3 ms·
I wish we could talk about style in objective terms, not just opinion. Opinions are kinda stupid. Here's my opinion: https://news.ycombinator.com/item?id=2679
by thrwaeasddsaf 5y ago
I wish we could talk about style in objective terms, not just opinion. Opinions are kinda stupid. Here's my opinion: https://news.ycombinator.com/item?id=26790701 https://news.ycombinator.com/item?id=26790701 (actually that's just a faux opinion to make a point, but you get the point)
And if there are no objective facts, then maybe we could just stop calling other peoples' preferred style nasty and "bad habits" as if it were objective.
- okl 5y agoYour "opinion" is particular "stupid" (your words) since you introduce a false analogy between program code structure and natural language sentences. Let's see what CMU's SEI has to say: https://wiki.sei.cmu.edu/confluence/display/c/DCL04-C.+Do+not+declare+more+than+one+variable+per+declaration https://wiki.sei.cmu.edu/confluence/display/c/DCL04-C.+Do+no...
- thrwaeasddsaf 5y agoI know SEI well. I have worked on projects where linters enforce that style, and I hate it. You can read their justification: a programmer or code reviewer might mistakenly believe that the two variables src and c are declared as char *. "A programmer might not know the syntax" is as stupid a justification for enforcing these rules as "a reader might not be able to read long sentences correctly" is for enforcing a stupid rule over text written in a natural language. I'm sorry that you failed to see the analogy. They also just drop a statement like "declaring no more than one variable per declaration can make code easier to read and eliminate confusion." I can drop my opinion too: "declaring more than one variable per declaration can make code easier to read and eliminate confusion." It can also make the code shorter and easier to scan & edit. And I think analogies involving natural language are more relevant than you think. I would rather read "U, V, and W are phases" than "U is a phase. V is a phase. W is a phase." It's the same goddamn thing, we're declaring things (and optionally initializing them).
- monsieurbanana 5y agoMore difficult to read, more difficult to edit, but the worst thing is how difficult it makes diffing code. You should try using some kind of code versioning, git is a popular choice.
- thrwaeasddsaf 5y ago> More difficult to read Subjective, and I do not find it more difficult to read. On the contrary, I often find shorter and denser expressions (especially around obligatory fluff that doesn't actually do much) to improve readability and make it easier to focus on the interesting part. > more difficult to edit Subjective, and I do not find it more difficult to edit. In general, as long as you're not using a magnetized needle as your editor, creating new declarations or moving declarators around shouldn't be a challenge. It is trivial. Nevertheless, if we want to consider the relative difficulty of various trivial edits, it can go both ways as far as multiple declarators per line are concerned. It can be easier to edit when you have a set of related variables and you need to change the type once. If you split them on a bunch of lines, you need to remember to change every line, which is more work and larger diffs. Oh the horror... > but the worst thing is how difficult it makes diffing code. I agree that it can make diffs a little harder to read but I have not found that to be a big issue in practice (having worked on both styles of code professionally and as a hobby for more than two decades). If diffs were such a major concern, then we probably should adopt an assembly-style syntax with one instruction per line and no nested indentation. That would keep lines inherently short, so you don't have to locate and read the small change on a longer line. And you'd never have to pick small changes from a large hunk that is large mainly due to changed indentation. (At this point, I'd like to make a point about how splitting everything to more and more lines isn't always good for readability but I think I made that point already.) By the way, you might wanna try out one of these modern diff tools that can hilight the actual change on a diff line. > You should try using some kind of code versioning, git is a popular choice. I can assure you that "multiple variables per declaration" have never been a problem for me with git. Coincidentally, the source code of git itself does have multiple declarations per line so looks like it wasn't a big problem for the authors of git either. (Obligatory example: https://github.com/git/git/blob/89b43f80a514aee58b662ad606e6352e03eaeee4/tree.c#L97 https://github.com/git/git/blob/89b43f80a514aee58b662ad606e6...)