Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

That's just a matter of coding style. It's very easy to write code that reads equally well in a proportional or monospaced font. All you have to do is give up column alignment.

I haven't used column alignment in my code in over ten years, and it's been a real blessing. Column alignment leads to some absurd practices, like the examples below from this Servo source file:

https://github.com/servo/servo/blob/master/components/layout...

You may need to scroll horizontally to read these long lines:

  let construction_item = ConstructionItem::TableColumnFragment(Fragment::new(node,
                                                                              specific));

  self.set_flow_construction_result(&kid,
                                    ConstructionResult::Flow(kid_flow,
                                                             Descendants::new()))
Those statements would be more readable and much more maintainable with a simple change: Stop making a distinction between parentheses and curly braces. Instead of lining up columns where parens are used, indent expressions the same way we typically indent statements:

  let construction_item = ConstructionItem::TableColumnFragment(
      Fragment::new( node, specific )
  );

  self.set_flow_construction_result(
      &kid,
      ConstructionResult::Flow( kid_flow, Descendants::new() )
  )
Here's some of the trouble column alignment gets you into, again from the same source file:

  ConstructionResult::ConstructionItem(ConstructionItem::Whitespace(whitespace_node,
                                                                whitespace_style,
                                                                whitespace_damage)) => {
      ...
  }
It's easy to guess what may have happened here: at one time the code was aligned perfectly, but then four characters were added somewhere in one of those names, pushing whitespace_node farther to the right so it no longer aligned with the code below it.

With a non-column-aligned style, this would never happen:

  ConstructionResult::ConstructionItem(
      ConstructionItem::Whitespace(
          whitespace_node,
          whitespace_style,
          whitespace_damage
      )
  ) => {
      ...
  }
Now you can change any of those names and it won't affect the code formatting one bit. And look how much shorter your lines are when you use indentation instead of alignment!

Another benefit of giving up column alignment is that it eliminates any need for arguing about "tabs for indentation, spaces for alignment" and all that. And with no alignment, your code becomes resilient to re-indentation. Company founders get older and find it's become harder to read two-space-aligned code? You can re-indent the source mechanically to four spaces, or tabs, or whatever you like, and it won't break the formatting at all.

Of course if you have to work with column-aligned code like the Servo source, you'll probably need to use a monospaced font. But if you have any influence over the formatting of the code you work, try giving up column alignment. Even if you don't find it makes any difference in readability, the people who have to maintain your code later will appreciate not having to fiddle with the alignment any more.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: