4 ms·
I'm subjective the other way, why do I need to type brackets when my indentation already carries my intention?
by stavros 5y ago
I'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.
- wizzwizz4 5y agoIf your editor keeps the selection once you paste, you can just hit tab / shift + tab until the indentation's correct. And there's no counting “did I copy the correct number of close brackets”. I actually find Python easier in this regard, even in editors where I have to re-select everything I just pasted.
- jimbokun 5y agoBecause there are places where indentation signifying intention breaks down. The classic example being the arbitrary restrictions on the Python lambda syntax. Ruby is more orthogonal and systematic. Everything is an object, and you call methods on those objects. And sending a block as a method parameter gives you something that very much resembles functional programming (minus the immutability). There are a few other constructs (it's not quite so dogmatic about object orientation as Smalltalk), but Ruby is very regular and so you can understand how everything works with a small number of syntactic constructs.
- wizzwizz4 5y ago> The classic example being the arbitrary restrictions on the Python lambda syntax. That's actually because Guido thinks multi-line expressions are messy to parse, rather than because they can't be done. Consider: f = lambda x: return x + 5 Or, perhaps: print(sum(map(lambda n, b: while n: b.append(n) n -= 1 return b , range(3), [[], [], []]), [])) You can see why this was never added to the language, though.
- larkost 5y agoThe lambda thing is not about whitespace indentation. It is a purposeful decision that if you need more than one line to do it, it should have a name. At first I disliked this, but it does nudge you towards readability, which winds up to be a good thing. And if you look at it, there is very little space difference between an unnamed lambda and an embedded function: def lambda_version(): a = lambda x: line one line two # note: this sort-of requires the idea of implicit return, which Python does not have outside of lambda a() def named_version(): def lambda_replacement(): line one return line two lambda_replacement()
- setpatchaddress 5y agoYou need to spend a couple of days debugging scripts where someone has fucked up the indentation by copying and pasting with a program messes with leading whitespace. Or where someone has inserted an extra whitespace character in a random line in a long script.
- stavros 5y agoI've been a Python developer for twenty years, I'm sure those things are bound to happen at some point but haven't yet.
- horsawlarway 5y agoI was a TA for a physics lab that used python (3 months) This came up nearly 100+ times in those 3 months, just in the classes I TA'd for. Making invisible characters carry significant meaning really throws non-programmers for a loop at times: It's so easy, right until they break it and don't understand how.
- stavros 5y agoIsn't it the same when their code won't compile because of an extra bracket?
- horsawlarway 5y agoNot really - A missing bracket is immediately a parsing error. Mis-indented whitespace is not. if(err) { console.log('something bad happened') recover() continue() Immediately throws an unmatched brackets error. No such luck for if err print("something bad happened") recover() continue() now you can spend minutes trying to figure out why continue isn't being called as you expect it to in the success case. It's obvious enough once you open that specific file and see the indentation, but the tooling is no help at all.
- scarygliders 5y ago