DEV Community

Cover image for Code Pet Peeves: What's Yours?
dev.to staff for The DEV Team

Posted on

Code Pet Peeves: What's Yours?

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!

Top comments (36)

Collapse
Ā 
vapourisation profile image
Thomas Pegler •

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)

Collapse
Ā 
insidewhy profile image
insidewhy •

I have a slight preference to leave semicolons out whenever possible. Minimalist. It doesn't really bother me either way.

Collapse
Ā 
arndom profile image
Nabil Alamin •

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.

Collapse
Ā 
kachidk profile image
Nwanguma Victor •

For me its the opposite, putting new lines only when necessary helps to know if pieces of code are related.

Collapse
Ā 
arndom profile image
Nabil Alamin •

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:

non-space example

spaced example

I'd say the latter makes the block a bit clearer.

Thread Thread
Ā 
kachidk profile image
Nwanguma Victor • • Edited

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.

Thread Thread
Ā 
arndom profile image
Nabil Alamin •

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

Collapse
Ā 
jamesowens profile image
James Owens •

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.

Thread Thread
Ā 
arndom profile image
Nabil Alamin •

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

Collapse
Ā 
khairunnisaas profile image
Khairunnisaas •

i agree for that

Collapse
Ā 
ranggakd profile image
Retiago Drago •

Cannot be consistent with either this

def add(a, b, c):
    return a + b + c

add(a_very_long_variable_a,
    a_very_long_variable_b,
    a_very_long_variable_c)
Enter fullscreen mode Exit fullscreen mode

or this

def add(a, b, c):
    return a + b + c

add(
    a_very_long_variable_a,
    a_very_long_variable_b,
    a_very_long_variable_c
)
Enter fullscreen mode Exit fullscreen mode
Collapse
Ā 
khairunnisaas profile image
Khairunnisaas •

bottom one is much better for me

Collapse
Ā 
alteredoxide profile image
AlteredOxide •

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.

Collapse
Ā 
ranggakd profile image
Retiago Drago •

sometimes the former saves more space 😭

Collapse
Ā 
jonrandy profile image
Jon Randy šŸŽ–ļø •

Spaces being used for indentation instead of tabs.
Tabs, not spaces

Collapse
Ā 
michaeltaylor profile image
Michael R. Taylor •

Yes, this one! And to go along with it, at least for me: using tabs for alignment. 😠

Collapse
Ā 
ben profile image
Ben Halpern The DEV Team •

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.

Collapse
Ā 
xanozoid profile image
XANOZOID •

No comments

Collapse
Ā 
mikeatupside profile image
Mike Lowe • • Edited

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 😭

Collapse
Ā 
nicolus profile image
Nicolus •

Oooh, you would love working with me : I tend to rearrange variable declaration blocks to order them by line length so it looks nice.

Collapse
Ā 
ksolomon profile image
Keith Solomon •

It’s code-ish, but I ran into this doing a review with one of our juniors today. She was working on the mobile side of a site, and had the hamburger menu on the left…that’s not a problem. The problem is, the menu opened from the right. It’s so minor as to be pointless, but it drives me crazy to see that…

Collapse
Ā 
nicolus profile image
Nicolus •

Well to be fair if the spec she was given didn't specify what the hamburger button was supposed to do, she could have made it randomly open at the top/bottom/left/right and it would have been just as correct šŸ˜‰

Collapse
Ā 
ksolomon profile image
Keith Solomon •

She wasn’t give a spec for it, and I didn’t say anything about it…I suffered in silence… šŸ˜‚

Collapse
Ā 
wraith profile image
Jake Lundberg •

I have 3 that really get to me:

  1. inconsistent code formatting. i’m fine adopting different patterns or standards, but that pattern should be consistent throughout the codebase.

  2. when someone says ā€œwe’ll circle back and fix this laterā€ā€¦in my experience…no we won’t. unless this is a prototype and the team understands that this code will be thrown away, let’s do it correctly now.

  3. duplicate code. it may be easier for you in the moment to copy a chunk of code to get something working, but it causes so much more pain later. invest a little time now rather having to pay interest on that time later.

Collapse
Ā 
pxlmastrxd profile image
Caleb (pxlmastr) •
function curlybracesshouldbelikethis() {

}

function notthis()
{

}
Enter fullscreen mode Exit fullscreen mode