News for hackers. Stuff that matters.
Re:Ifs and &&s and Plan 9's Source Code by jamesaguilar on Friday May 24, 2013 @03:14PM (#5764740)
Good luck using an auto formatter on a code base that uses this technique.
Re:Ifs and &&s and Plan 9's Source Code by supersillyus on Friday May 24, 2013 @05:54PM (#5765379)
If I'm not mistaken, Plan9 comes with a code formatter, and this idiom is common in Plan9, so it seems likely that it is supported. http://plan9.bell-labs.com/sources/plan9/sys/src/cmd/cb/
Re:Ifs and &&s and Plan 9's Source Code by adrianmsmith on Friday May 24, 2013 @03:48PM (#5764869)
I believe that the layout of code is done by humans for humans. An auto code formatter destroys all of that meaning.

I blogged about this more here: http://www.databasesandlife.com/do-not-use-automatic-code-re...

Re:Ifs and &&s and Plan 9's Source Code by jamesaguilar on Friday May 24, 2013 @05:14PM (#5765215)
Yeah, I saw that. I think it's misguided. The amount of time spent on arguing about style far exceeds the time savings of the changes you propose. People can get used to different formats quite easily, but time spent arguing about and maintaining formats can never be recovered.

Also, your formatter looks pretty brain-dead. clang-format formats all of those cases (in C++) as in your green examples with Google style turned on. Even the Eclipse formatter should do a better job than what you've posted with the appropriate settings. When I advocate an auto-formatter, it doesn't make sense for you to respond with a blog post talking about a formatter seemingly designed to make everything worse.

Re:Ifs and &&s and Plan 9's Source Code by LeonidasXIV on Friday May 24, 2013 @06:56PM (#5765673)
I agree and for this reason, gofmt, an automatic formatter for Go code is possibly my favorite part of the toolchain. It is kinda like PEP8 for Python but formalized into a program (there is a third party pep8 program) or Emacs for Common Lisp. The advantage is that it is a standard tool.

So I can just run it over my code, no matter what editor I used and the code is fine. No arguing what is right, no thinking about where to put some stupid spaces or how to break a fucking line, just run gofmt, done.

Re:Ifs and &&s and Plan 9's Source Code by adrianmsmith on Saturday May 25, 2013 @06:41AM (#5766890)
"People can get used to different formats quite easily, but time spent arguing about and maintaining formats can never be recovered" This is nevertheless what this whole discussion is about :-) e.g. should one list those ifs straight like that, or use &&, etc.

"Also, your formatter looks pretty brain-dead", it is, alas, what Eclipse does, and that's pretty standard in the Java world, and it's also pretty standard to use its code formatter alas.

Re:Ifs and &&s and Plan 9's Source Code by webreac on Saturday May 25, 2013 @09:15AM (#5767181)
When working in a team, human code formatting can cost a lot of time. The rule is generally to have an auto code formatter that runs when we do a commit. The choice of formatting rules is made collectively and can be discussed. The usage of an auto formatting is generally mandated by society policies. I think it is a huge time saver (not using an auto formating tool is way to lose a lot of time).
Re:Ifs and &&s and Plan 9's Source Code by andkerosine on Friday May 24, 2013 @03:51PM (#5764877)
For what it's worth, Vim handles it just fine.
Re:Ifs and &&s and Plan 9's Source Code by calebegg on Friday May 24, 2013 @04:36PM (#5765069)
What? Not for me, not with cindent on. It indents each if statement by one level, just like it "should". How would it somehow know to not indent them?
Re:Ifs and &&s and Plan 9's Source Code by Someone on Friday May 24, 2013 @05:07PM (#5765179)
An auto-indenter could easily detect the idiom if hit backspace after the auto-indent it produced after the first 'if'.

Once you have your two ifs at the same indent, the indenter can use that info to keep them at the same indentation level. It could even assume you mean (a&&b) vs (!a&&!b) and not the three-way (a&&b), (a&&!b), (!a) when you follow it with an else block (I think that would be the best heuristic)

Implementing this will get a bit hairy, but if you are writing an auto-indenter for C, you should be used to that.

So, all you would have to do is hit one extra backspace to signal your intent.

Alternatively, one could type

  if(a) if(b) {
To signal that one wants

  if(a)
  if(b) {
Same number of keystrokes, and, IMO, that space is slightly easier to type than the return it replaces.
Re:Ifs and &&s and Plan 9's Source Code by jamesaguilar on Friday May 24, 2013 @05:16PM (#5765223)
None of the existing auto formatters that I'm aware of do this.
Re:Ifs and &&s and Plan 9's Source Code by calebegg on Friday May 24, 2013 @06:13PM (#5765464)
That's all good and well, but vim does not do this and, more generally, does not support this style, which is what I was saying.