4 ms·
The 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 dow
by laumars 12y ago
The 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 12y 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 12y 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 12y agoIDEs typically close braces not to help you type or to enforce format rules, but to provide better feedback during a language aware editing session. Compilers can do amazing things with error recovery for code being edited, but still have problems inferring missing braces.
- laumars 12y agoYou misunderstand me; I wasn't suggesting auto-closing of brackets was a method of enforcing format rules (that would be a dumb statement to make for the very reasons you highlighted). I was just commenting on how non-intrusive gofmt is when compared to the other tools that alter code while your programming.
- seanmcdirmid 12y agoYes, but they are solving different problems so aren't very comparable, even if they both work by modifying code. I just want to clear the air about why we IDE developers go this route.
- laumars 12y agoThe fact that they are both modifying code makes them comparable from an end user experience perspective, which was the comparison I clearly made. I appreciate you wanting to be specific about their intended purpose but, frankly, you're stating the obvious. Anyone who's spent more than 5 minutes inside an IDE (or even basic programming-geared text editor) will already be well versed on the subject. You don't need to be an IDE developer to understand this (and to be honest, what developer hasn't written their own programming environment at some point in their lives anyway? :p ) In any case, I was just making a light-hearted passing comment; hence the "hehehe" at the end of it. It didn't really add anything to my original post and certainly wasn't meant to picked apart in this level of detail.
- seanmcdirmid 12y ago
- lobster_johnson 12y agoThe only case where I have found a brace-type syntax to be superior is when you do quick REPL stuff. With Ruby I frequently do things long, compact reams of statements combining blocks via map, inject, each, etc. that are all written on a single line, and plays nice with Readline history.
- laumars 12y agoMy point is that there isn't a "superior" syntax. It's just personal preference.
- lobster_johnson 12y agoAnd my point is that there are pros and cons.
- laumars 12y agoOf course there. I even said this in my first post. But at the end of the day you can draw up a list of a pros and cons about anything that essentially just boils down to personal preference. What I take issue with is when people start using those pros and cons as an argument for superiority when what they really mean is "I personally prefer..."
- seanmcdirmid 12y agoI prefer white space, though I've learned to live with both by minifying brace only lines to 3 point fonts in my IDE, which might be a nice compromise. The only problem with white space languages are multi line lambdas.