5 ms·
Why he vertically aligns his code (And why you shouldn't)
- wmt 12y agoNext up, a blog post which shows even more readable using whitespace and syntax highlighting!
- tehwalrus 12y agoIt took me a while to realise why they pointed out the kerning around the equals sign. It appears to be because they have omitted the spaces either side of it -- a crime even worse than vertical alignment (in my brain's subjective opinion on code formatting).
- jwdunne 12y agoIt seems like the takeaway is that you should use a well-designed syntax highlighting scheme. You cannot expect everybody reading your code to be using a good syntax highlighting scheme. Either way, I think code should be readable independent of editor features. I have noticed that, if you make code readable without syntax highlighting, it's always readable with syntax highlighting. The reverse is not true. I would even argue that the code readable without highlighting is more readable with highlighting than the code written just for highlighting. I don't use vertical alignment. I do think that a long list of vars is harder to read and vertical alignment helps with that. Yet, the solution for me is to attack the core problem. I reduce the number of moving parts inside a procedure, which you can be sure variables are. Perhaps the author should improve the trivial examples by showing the code with syntax highlighting and vertical alignment.
- kazagistar 12y agoSyntax highlighting is a much more common feature then vertical alignment in editors. People should be able to read your code, but they should also be able to edit it without hassle, and mismatching indentation, or doing it manually, is quite horrible. If you want vertical alignment, it seems easier to just align it vertically for yourself. Customize your presentation, but leave it generic for everyone else.
- cromulent 12y agoThe coding atom example is vertically aligned.
- robotkilla 12y agoIt takes longer to read a line of text that has more whitespace than it does to read a line of text with less whitespace and proper syntax highlighting. In addition to this, modern typography has different rules for different mediums. Bringhurst's typographic styles weren't meant to be applied to C# code nor should they be. We don't read code the same way we read books or magazines, thus it doesn't need the same treatment. If we are going to start applying modern typographic elements to code that we write, then we need to start thinking about incorporating various font faces, weights, worry about the kerning and leading, add some headers and a host of other things.
- gus_massa 12y agoActually, the diff looks like: + int barney, But the patch looks like: extern int SomeDemoCode(int fred, + int barney, int wilma);
- brador 12y agoAnyone got links to good syntax highlighting schemes?
- Latty 12y agoVertical alignment of variables is one of those things that feels like it makes your code more readable when you look at your code in a page, as the original article did. The reality is, there is a big difference between pretty code and readable code - when actually reading code, we do it line-by-line to discern meaning. Vertical alignment means we see these numbers as a collection, making them easy to read as a group, but that's not useful. What we care about is how those numbers link to the variables on the left. Sure, the fact that syntax highlighting solves the same problem better is a good argument, but a better one is that vertically aligning assignments actually makes your code harder to read.
- 4ydx 12y agoThe loss of vertical alignment in go fmt is something that bothers me a bit. I am an aggressive vertical aligner and proud of it! It reduces the amount of noise in the code (as I perceive noise).