r/learnprogramming • • Mar 22 '22

Don't be that guy.

I just took over a project for a guy who left. Don't be this guy:

  • ZERO comments in your codebase.

  • One and two character variable names with no discernable pattern.

  • Comment characters used to comment out big chunks of code for no discernable reason.

  • No error checking.

  • Reliance on data files that you forgot to include or explain, going in to meaningless data frame names.

  • Making outrageous claims about how much your code improves things with zero baseline performance.

People like this think you're an idiot because you can't make their code work, and get to be all smug. We will track you down and find you. You will need references someday....oh my.

2.6k Upvotes

427 comments sorted by

View all comments

Show parent comments

2

u/vi_sucks Mar 23 '22

Oh, so when the system goes down because someone replaced the local global cache with a pseudo cache hosted on a cloud or something, you don't think it would be useful to know that the original intention was for the cache to be useful during a network interruption?

I just need to know what the code does.

Knowing what code does is less than a fraction of the difficulty of being a programming. Everyone can google some syntax to figure out what the code is doing. Understanding how it was built, why it was built that way, and how it came to be the way it is now is WAY more important. And that's substantially more difficult without comments. Even bad comments are better than no comments.

Hell I had a bug last week where there was a comment that just said "TODO ask senior engineer X". Shit comment, obviously. But since the bug had been in the system for 3 freaking years, it was way more helpful to be able to ask him directly "yo, is this supposed to do this?" And get an answer in minutes instead of starting a 3 day email volley with the users to figure out if the code that clearly did what the variable names said it did was actually supposed to be doing that when the users said it shouldn't.

2

u/illkeepcomingback9 Mar 23 '22

The naming should describe the intent. Look at the code to determine if it is fulfilling that intent. If your code is decomposed into functional units this is not a monumental task that takes 3 days of emailing back and forth. But honestly it makes sense now, if you're accustomed to an environment where something like that could even be merged in to main in the first place, I can see why you are so reliant on excessive comments. Comments are a workaround for a deficiency in your coding standards and processes. If something like that made it past PR in my environment we'd be having email chains of an entirely different nature.

1

u/vi_sucks Mar 23 '22 edited Mar 23 '22

You're missing the point.

The code was very clear and illustrated what the intent of the dev was. And it did exactly what the naming indicated. It's just that what the naming indicated was wrong from the standpoint of the users, and had been wrong for so many years that the users who would have helped develop that feature originally, as well as the dev who wrote the code were long gone.

You can't fix that with coding standards because it's not a code problem at all.

Nor is starting a blamestorming session about a bug introduced years ago by someone who no longer even works there helpful in the slightest. It's not going to fix anything.

To clarify the example a bit further, the code on question was a single line of code that took the value of a field and assigned it to another field. Very simple, very clear. The only question was "why is it doing that?" Was there a requirement to do so that the new users just didn't know about? Was it a typo? Something in the middle? Unless i could read the mind of the dev, who left years ago, i couldn't know. With a good comment i could know the why. With the bad comment, i could at least know who else to ask and follow up.