4 ms·
It's a little thing, and not uncontroversial, but I'm excited to see another language besides Python adopt whitespace. In general I wish more languages provided
by wiremine 11y ago
It's a little thing, and not uncontroversial, but I'm excited to see another language besides Python adopt whitespace. In general I wish more languages provided a way to enforce code layout.
After using Python professional (and managing a team of developers) for a few years, whitespace is a great way to keep things readable as more people touch code.
Whitespace isn't the only way to do it, of course. Go's "gofmt" is a good example of a different way to enforce code layout. [1]
[1] https://blog.golang.org/go-fmt-your-code https://blog.golang.org/go-fmt-your-code
- progman 11y agoI always was strictly against whitespace in Python because it can lead to all kinds of weird errors. But Nim (and also Haskell) has static types so most wrong indentations are caught by the compiler. That's really nice to have.
- nickbauman 11y agoI've been a Python dev since 2008 and I can count on one finger where this has actually been an issue. I'd love have you enumerate the "all kinds of weird errors" for me. Not saying you're wrong, mind you, just want to understand.
- muaddirac 11y agoI have to agree - the only whitespace-related errors I've ever come across are "IndentationErrors" - which are pretty easy to resolve.
- mercurial 11y agoI remember a bug caused by that, due to a merge, where an instruction went out of an if block.
- andybak 11y agoI wonder if it was an automatic merge or whether someone just didn't eyeball the code properly?
- iopq 11y agoThat's scary... this is why I'm unhappy with merge tools that don't understand the underlying language
- nickbauman 11y agoOk this sounds legit. Thank you. But if you think about this carefully it means that two people wrote the exact same expression in different scopes, which seems really, really odd, no? I'm trying to contrive this in my mind and I'm having difficulty (my fault, obvs). If this happens again it deserves its own blog post describing the situation carefully!
- mixmastamyk 11y agoSince 2000, there were a few times in that first afternoon while doing the tutorial... March 2000? I think, but then I configured my editor to use spaces and subtly show tabs. That was the last time, yeah. People that complain about whitespace haven't used Python much, it's a dead giveaway. And yet, the benefits are enormous, I've probably skipped typing a hundred thousand redundant braces since then, and ended up with more readable code.
- esrauch 11y agoTabs are considered the same as 8 spaces, so if you ever have a single moment of lax enforcement of "only tabs" or "only spaces" you can get bizarre results.
- Demiurge 11y agoJumping on this wagon. Have been using and teaching Python for more than 10 years and have never seen any weirdness. Python actually warns when there are mixed tabs in blocks.
- Nadya 11y agoI've always felt the argument against whitespace due to "indenting 2 spaces instead of 4 spaces" or something silly is like trying to argue "Braces are bad because you might forget to close a brace!" IDE's handle both scenarios. My IDE largely remembers how far in I should be indented and if I use a brace it closes it for me. If I program in a plain text-editor like Notepad - I still don't mess up my indenting any more than I forget to close a brace or parenthesis. It's a silly argument formed from speculation and "but its possible!" rather than reality.
- andrewstuart 11y ago>> it can lead to all kinds of weird errors Quite the opposite. Whitespace for me is a godsend - all code is formatted the same way and I rarely if ever have to deal with whitespace related errors. In fact I don't even know what whitespace related errors are - you'd have to explain what you mean. On the other hand, when programming in JavaScript I seem to spend all my time trying to work out issues related to brackets and code structure - very very annoying and silly - can't computers work brackets out, do we need to tell them what the code structure is?
- nickbauman 11y agoKen Arnold said it best in his "Style is Substance" http://www.artima.com/weblogs/viewpost.jsp?thread=74230 http://www.artima.com/weblogs/viewpost.jsp?thread=74230
- laumars 11y agoThe argument of white space or braces is largely a religious one. Any argument for one case is equally valid for the other as well and it usually just boils down to people trying to justify personal preference. eg: Python: white space is a great way to keep things readable as more people touch the code. Perl / PHP / etc: braced blocks is a great way to keep things readable if the formatting breaks. Python: People can get lost in braces. Perl et al: People can forget to tab. etc Personally I prefer braces, but I've worked with whitespaces and verbose ALGOL-style blocks too. At the end of the day, all these arguments are just theoretical because most people manage just fine 99% of the time.
- wiremine 11y ago> The argument of white space or braces is largely a religious one. True. That said, my main point is that standardizing on how to layout code is very helpful, either through the compile or using a preprocessor (like gofmt) is helpful, and more languages should encourage it out of the box.
- laumars 11y agoQuite a few languages do standardise style though (eg C# https://msdn.microsoft.com/en-us/library/ff926074.aspx https://msdn.microsoft.com/en-us/library/ff926074.aspx). Just as quite a few (possibly most?) companies will have their own coding policies as well. The problem is when individuals decide to go off piste and do their own thing. But then those same individuals could equally be likely to bypass gofmt when writing code (which is very easily done), or to ignore company policy about tab spaces et al when writing Python code. That said, I've learned to love gofmt for the laziness it brings. Text editors that auto-close brackets and such like can often be more of an intrusion than an asset. Where as gofmt only jumps in after the document is saved and the syntax is parsed for errors. So sometimes I find myself just throwing code down knowing that gofmt will tidy it up for me as I go. Which I'd be the first to admit is a pretty bad habit to get into hehehe
- seanmcdirmid 11y ago
- deleted 11y ago[deleted]