Welcome to Code Chatter, your go-to series for conversational coding insights. What makes this series of questions different from all the others? Well, truth be told, not much, but they're still thought-provoking and fun. Join us as we explore the coding world, one witty question at a time.
What's your secret 'code pet peeve' that, while not critical, drives you crazy?
Follow the DEVteam for more discussions and online camaraderie!
Oldest comments (36)
Spaces being used for indentation instead of tabs.
Yes, this one! And to go along with it, at least for me: using tabs for alignment. ๐
No comments
This is so silly but I really don't like the Javascript pattern of not using semi-colons and trying to remove as much punctuation/structure as possible. I get the desire for conciseness but not having reliable beginning and end-points in code bothers me. I'm saying that as a Python developer (sometimes I wish Python had more punctuation but at least whitespace is the delimiter)
I have a slight preference to leave semicolons out whenever possible. Minimalist. It doesn't really bother me either way.
I have come to really like statically typed languages. Dynamically typed languages are fine, but I can't deny that they get on my nerves a little bit.
I don't know if it's a pet peeve, but premature abstraction/DSL-ification grinds my gears, i.e. violating the "rule of three"
Rule of three is a code refactoring rule of thumb to decide when similar pieces of code should be refactored to avoid duplication. It states that two instances of similar code do not require refactoring, but when similar code is used three times, it should be extracted into a new procedure. The rule was popularised by Martin Fowler in Refactoring and attributed to Don Roberts.
My biggest would have to be spacing of code blocks, seeing large lines of code all together with no breathing room is just awful and slows down the readability.
For me its the opposite, putting new lines only when necessary helps to know if pieces of code are related.
Yh, I agree, but, there are cases where a new line really makes it easier to read, even when they are related. Take this for instance:
I'd say the latter makes the block a bit clearer.
Cleaner does not necessary mean readable. i.e there are one-liners that are cleaner but not readable.
In your example, It would be annoying If I was scrolling through the code and, at every new-line stop to try and contemplate if the code above and below is related or not.
Yh, one liners can be tedious.
The example I gave is about readability, the nesting also helps you to understand that's it's part of the same context, collapsing that block could also help you along.
At the end of the day I think it's just up to what your team agree is the pattern to follow
If you're separating blocks of code that are related with new lines it could be an indication that your blocks could be extracting into separate methods.
Definitely agree, this example is not the end and be all. In that case I was going by the rule of only abstracting when there is a repetition of more than 3. It's all opinionated though
i agree for that
Cannot be consistent with either this
or this
bottom one is much better for me
sometimes the former saves more space ๐ญ
Yes. The first one irks me, especially because that first argument is rarely perfectly aligned with your chosen indentation (2, 3 or 4 spaces), which leads to needlessly tedious manual spaces or deletions before following argumentsโdepending, ofc, on your linter.
Not strictly code but I tend to alphabetise things like environment variables in config files, YAML, JSON param files for CloudFormation, that sort of thing. It pains my heart when someone comes along and just throws new variables/params in in any old order ๐ญ
Oooh, you would love working with me : I tend to rearrange variable declaration blocks to order them by line length so it looks nice.
Using long array in PHP. The sea of parenthesis () is so hard to read.
Well, I guess mine it's why some languages start counting with 1, when the rest starts with 0 ( elements of lists for exemple) , why do they want to be different of the rest and don't start with the 0 ๐
For me, it's over optimizing code to the point that whilst short and elegant, it is not readable at a glance for those that might not live in the code base every day.
Upper-case SQL keywords. It looks like someone's crazy uncle sent out another email forward and the illegibility gives me a headache.
Line length limit standards predicated on screens narrower than the narrowest screens we have today (not moved with the times). Aka PEP8.
Long, long functions. More than 2 levels of loop nesting. More than 2 levels of conditionals nesting.
Not splitting long functions is like writing an email without paragraphs.
๐ช
My pet peeve is folks having too strong of an opinion about syntax.
Iโm also rather annoyed by the over-emphasis on OOP as though it is the only correct paradigm.
Finally, I donโt like folks who behave like one language is better than another. Theyโre tools, not political positions.