Live data from Hacker News

The Art and Science of Great Code

queue.acm.org

21–30 of 35 posts

Re: The Art and Science of Great Code

#21

Forgive my bluntness, but why is ACM publishing a couple of academics' personal choice of lightweight coding standard, and why are so many Hackers upvoting it? Is there some hidden depth here that I'm missing, or some underlying research that shows these preferences are objectively better than some of the alternatives?

ACM Queue is not an academic journal. It's the ACM's venue for publishing opinion pieces by both scientists and people from industry.

Re: The Art and Science of Great Code

#23
post #4

A standard argument against aligning multiple similar lines of declarations as a table is that you constantly need to re-align when you add/remove declarations. One implication is that source diffs become larger than necessary as they will now include lines that haven't actually changed content-wise, only layout-wise.

Code is read many more times than it's written. Re-aligning isn't really time consuming.

Actually, many open source projects explicitly forbid vertical alignment as it becomes an obstacle for patch review.

I'm quite disappointed the article doesn't mention that.

Re: The Art and Science of Great Code

#24
post #4

A standard argument against aligning multiple similar lines of declarations as a table is that you constantly need to re-align when you add/remove declarations. One implication is that source diffs become larger than necessary as they will now include lines that haven't actually changed content-wise, only layout-wise.

Have you checked uncrustify? It doesn't do all the work necessary for the tabular alignment illustrated in the article but it does great part of it. I personally use it with a keyboard shortcut to fix the selection of the code I just wrote or edite. In this way I'm faster because I skip most of the white space characters.

http://uncrustify.sourceforge.net/

Re: The Art and Science of Great Code

#25
With regards to figure 1 I'd argue that avoiding duplication is far more important than alignment. When I first looked at figure 1 I paused to see if duplicating the case was what was meant or whether each line should match lower case and upper case. To me that signifies less readable code since I've had to re-read it to try to understand it.

Re: The Art and Science of Great Code

#26
post #4

A standard argument against aligning multiple similar lines of declarations as a table is that you constantly need to re-align when you add/remove declarations. One implication is that source diffs become larger than necessary as they will now include lines that haven't actually changed content-wise, only layout-wise.

In emacs, one can take out the drudgery of manually aligning and realigning your variables in tabular fashion using the align commands[1]. In certain revision control systems, one doesn't keep differences, but whole objects, so the point is moot there unless you have some serious bandwidth concerns. [1] http://www.emacswiki.org/emacs/AlignCommands

It's not only about bandwidth concerns, it's more about making commit diffs readable. If you have ten lines of tabular assignments and you changed the sixth, but that made you realign everything, then you'll see 10 green lines + 10 pink lines in your commit diff, even though you should only see two lines in total.

Re: The Art and Science of Great Code

#27
post #2

This reminds me of a blog post I read several years ago where the author connected the concision of code to the experience the author of the code had. More experienced coders needed less comments and could read higher-density code with less mental effort. Wish I could find that blog post again, I've thought of it from time to time over the years. edit: speeling. edit2: Yegge strikes again. Wow. Amazingly influential…

This is interesting, and not something I'd consciously thought about before, but quite often I will go back after I've finished something and add some white space and (sometimes quite thorough) comments to the code I've written. I especially do this with open source code that I plan to release. My reason for doing this is that I want to make it clear to whoever ends up maintaining the code after I've left the project…

I've spent quite a bit of time working on systems that became untenable and had to be partially re-written or completely re-written. The result is the original code was either a baseline or a reference. I will say, without a doubt, comments are a code smell. Any comments.

If you write a piece of code and think you need to comment it because it won't be clear for the next guy. It is good at best.

Furthermore, comments rarely help. They are written while you are in complete comprehension of the program or that part of it. The next person (assuming the comment is something they are using to figure it out) won't be.

That said, if you can do nothing to improve the quality because of time, lack of interest or necessary complexity. At least, make your best effort to comment what it does. Appreciating the fact that this is a minimal quality improvement action. Sometimes it is just a piece of code that has to be optimized, explain why so the next guy doesn't refactor/re-write it.

Re: The Art and Science of Great Code

#28

Earlier quoted context omitted.

In emacs, one can take out the drudgery of manually aligning and realigning your variables in tabular fashion using the align commands[1]. In certain revision control systems, one doesn't keep differences, but whole objects, so the point is moot there unless you have some serious bandwidth concerns. [1] http://www.emacswiki.org/emacs/AlignCommands

It's not only about bandwidth concerns, it's more about making commit diffs readable. If you have ten lines of tabular assignments and you changed the sixth, but that made you realign everything, then you'll see 10 green lines + 10 pink lines in your commit diff, even though you should only see two lines in total.

Unless you have the option to blend out whitespace-only changes, e.g. https://github.com/blog/967-github-secrets
Post reply on HN