12 ms·
I'll be absolutely subjective here. Python seems fine, except that I can't get comfortable in a language that uses whitespace as part of its syntax. I know th
by dvdhnt 5y ago
I'll be absolutely subjective here.
Python seems fine, except that I can't get comfortable in a language that uses whitespace as part of its syntax.
I know the typical arguments of "linter, etc" but I believe my ruby and JS code, which includes using a linter and formatter, is easy to reason because brackets allow for better mental encapsulation.
All personal experience, I can't speak to the technical differences.
- drcongo 5y agoI think once you get more used to it you'll find the complete opposite. All those brackets are extra things your brain needs to process when reading the code, strip them away and it becomes just like reading written language. Ruby to my eyes, even when well formatted, looks as ugly as PHP - a mess of unnecessary indications that destroy the readability of the code (for me).
- dragonwriter 5y ago> All those brackets are extra things your brain needs to process when reading the code, strip them away and it becomes just like reading written language No, it doesn't, because written language explicitly marks ends, and sometimes also begginings, of structural units (programming gets brackets from natural language), it doesn't just use white space (until you get to units bigger than sentences.)
- Thrymr 5y ago> No, it doesn't, because written language explicitly marks ends, and sometimes also begginings, of structural units (programming gets brackets from natural language), it doesn't just use white space (until you get to units bigger than sentences.) Written language does of course use white space to separate words (this was not always the case, see for example classical Latin). And I think it's fair to say that a line of Python is roughly equivalent to a sentence, and whitespace indentation is only used for syntax at that level. The analogy breaks down a bit at higher levels, as Python blocks can recurse, but in writing we have structures like chapters, books, etc.
- necovek 5y agoAs pointed out, in written language, structural units (like chapters, paragraphs, bullet-point lists...) are usually finished with... distinctive whitespace (indentation or vertical space). Beginnings are usually more prominent (more whitespace, bigger fonts and different alignment, or introductory sentences with colons for lists), just like in Python. I am only saying that there's no need to make up arguments against significant-indentation. You can like how it looks or not: that's pretty subjective, though. The only two objective arguments for either side I can see are: * Terminating "end" or "}" are superfluous if you are already indenting code. * Re-indenting a block with no termination indicator can lead to subtle bugs (at least more of them compared to when an indicator for block end is present).
- chillfox 5y agoWritten language usually don't have paragraphs inside paragraphs. In programming things are frequently nested several levels deep. This is the key difference that makes a termination character/word important I think.
- necovek 5y agoThey do have it. Quotes (esp multi-paragraph ones) are usually indented another level in. So are nested lists (imagine if lists on different levels of nesting only used different bullet characters). So are mathematical formulae. Or table of contents. Or bibliographic references. Tables in general are a special case of horizontal spacing that matters. Figures and images in text. It's not as common because writing is not all hierarchical all the time (or at least, lots of space would be wasted if entire chapters/sections were indented one level extra), whereas programming is heavily hierarchical with shorter "blocks". Horizontal indentation is the most common way to express that hierarchy, including in programming languages that use block termination indicators — indentation is used to help humans parse the code, termination indicators are there to help computers parse it. You are making it sound as if you are not making use of indentation when programming: I thought the only complaint was about it being significant.
- arcticfox 5y agoAs a Python->Ruby convert like the parent here, I'm curious, which indications do you find unnecessary? The only one I can really think of is `end`, which, sure. But the implicit return is also much cleaner after I got used to it, so I think that's a wash.
- drcongo 5y agoI've barely written any Ruby in my life, so I may well change my mind like you if I did more. I do find it interesting how some languages just look uglier than others, and how subjective that is. I really struggle to learn languages where my initial reaction to how it looks is bad.
- chillfox 5y agoI agree that languages that look bad are hard to read. For me curly brackets or significant white space for blocks/scope is a big problem, it just all turns to soup. So Ruby using end instead of brackets or white space is one of my favorite features of the language.
- vidarh 5y agoPython looks horrendous to me, and it's absolutely one of the things that stops me from using it. It feels like walking with gravel in my shoes to have to look at it.
- kevinmgranger 5y agoI really wish there were languages with tooling to expose the source as either whitespace-using or bracket-using. It would solve so many conflicts. Let's have it handle tabs or spaces while we're at it. The answer could always be "whatever you prefer". My kingdom for better tooling!
- dagw 5y agoLet's have it handle tabs or spaces while we're at it. The answer could always be "whatever you prefer". As long as you don't mix tabs and spaces in the same file python is fine with either.
- kevinmgranger 5y agoIt's not about what the language is fine with. It's about what the developers are fine with. And they'll never agree, so why not give them a choice with tooling?
- necovek 5y agoThat's what tab-loving developers are saying the whole time: tab character is that special tooling that can be set by every developer for their own environment. :) Even though I fully buy that argument, I still prefer spaces, perhaps for the same reasons I like to format my code myself (vs. auto-formatters). Even software engineers can't be all reasonable all the time :)
- chaxor 5y agoI also love the cleanliness of Python compared to bracketed languages. When I was younger and learning the language it seemed to be beneficial in forcing more structure and readability in the code (no ridiculous obfuscation by single line programs). There was an article the other day showing how to take latex math notes in neovim the other day. They showed a plugin that displays a render of text on lines that the cursor is not on. Perhaps there is a way to set that up for languages with brackets? Just show the brackets relevant to that line (and the closing ones perhaps)
- 5y ago
- stavros 5y agoI'm subjective the other way, why do I need to type brackets when my indentation already carries my intention?
- addicted 5y agoA language that uses parentheses does not preclude one from also using indentation to convey code structure. In fact, this is usually standard practice. Python, however, does indeed preclude one from using additional signifiers of code structure beyond indentation. And in practice you don’t type out parentheses. You put in a single opening parentheses and your editor will add the closing parentheses and add the appropriate indentation (and if desired, newlines) for you. In practice the only difference in typing is typing a single ( character vs a single <tab> character. All that being said, this is the very definition of bike shedding, so it’s really not a factor when picking one language over another.
- stavros 5y agoI don't understand what you mean. How are parentheses relevant? Also, personally I hate the parenthesis completion, it gets in the way more than it helps. By "parentheses" do you mean "brackets"? If so, sure, you can use indentation along with brackets, but why am I now using two things? With Python, all I need to do is backspace every once in a while, to signify the end of indentation, which is very easy to do.
- wizzwizz4 5y ago> By "parentheses" do you mean "brackets"? I choose to believe that this means S-expressions.
- horsawlarway 5y agoAs a real reply - I can copy code marked up with parens and brackets from basically any source (no matter how it's indented or how whitespace is handled) and my linter will automatically understand and format it nicely. In an indentation language - If I copy a chunk of code that's nested more or less deeply than the section I'm currently working on, I have to manually replace whitespace everywhere. Sometimes the linter is smart enough, sometimes it's not.
- tonmoy 5y agoHaving used both professionally I love Ruby and I think python is an ok language. However, if there is one thing I do like about Python it is the white space syntax. It forces all coders including the not-so-technical people to write scripts using proper indentation and it makes inheriting Python scripts a little bit easier
- derac 5y agoYou can have your IDE indent code in the style you prefer automatically.
- tonmoy 5y agoI’m looking at diff between two commits right now where someone decided to fix the indentation in a non-Python language. While the new code is very easy to read, the diff is very difficult to analyze.
- vidarh 5y agoDiff can ignore whitespace changes just fine. But also, mixing whitespace fixes with other changes in a commit is a deadly sin.
- indymike 5y ago> You can have your IDE indent code in the style you prefer automatically. If you look at significant whitespace through the lens of developer preference, then sure, it sucks. Where it shines is ensuring code is readable by people other than the guy who likes 320 character long lines, and likes aligning everything to the = sign. The only language I know that is as easy to read as Python is Go, and it does so by forcing developers to use go fmt.
- mixmastamyk 5y agoIndentation instead of brackets in Python was a masterstroke in my opinion. Despite complaints from folks that don't use it much, and therefore run into an issue here and there due to lack of familiarity. As a regular user the tradeoff pays great dividends every single day in readability for years on end. I would remove more punctuation if I could… every single new feature to Python seems to include colons lately. :-/ No, I don't miss brackets everywhere one bit.
- cardanome 5y agoDo you have "show whitespace" enabled on your IDE? I think it really helps being able to see the characters properly. (Also helps avoiding mixing tabs and spaces like some bloody animal.) While there is some value in whitespace-insensitive syntax, I think using whitespace is a neat and human friendly way to keep things separated and to show structure. We are good at spatial thinking For example this text is using whitespace between words to tell you where which words starts and ends. It uses paragraphs to further split up certain ideas. (Same with math notation which also uses whitespace) {[Do; you; think; that; this; is; easier; to; read; ?][Does; it; feel; more; comfortable;?]} Getting used to new syntax is not as hard as people pretend it is. Never understood the aversion of some people. For Python being whitespace sensitive is a great choice as it helps the pseudocode look of it and is often used as a beginner language. You want beginners to learn how to properly indent code and to suffer if they mix tabs and spaces. (Though maybe now that we have automatic code formatting in many languages, maybe less so.)
- UncleOxidant 5y agoI was a Ruby early adopter - early 2001 - because I needed to move from Perl to a new scripting language (OO Perl just seemed like such a hack and there really was something to the Write Once aspect of Perl - I'd come back to a Perl program 6 months after I wrote it and wonder what the heck was going on). I took one day to play with Python. I got burned by the significant whitespace thing right away. Next day I looked at Ruby and it seemed like the perfect fit for what we were doing. Over the next dozen years or so I was a huge Ruby fan. But then around 2014 I got a different job in a Python shop. I thought I was going to have a rough time with the significant whitespace, but I ended up liking it a lot. That's not to say that I don't miss features from Ruby, but I found that I could get along fine with Python's significant whitespace.