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

1

u/Professional-Sun-684 Apr 19 '22

Good readable code doesn't need any comments in their code base. Code doesn't lie whereas comments can/and often do especially when they are not maintained

1

u/BullCityPicker Apr 20 '22

Comments to establish what a function does, what the arguments are, and known failure cases?

I’m so happy for you your code is so perfect in needs no embellishments in pesky English. I’ve just spent the last two weeks rewriting a pile of shit from a guy who had the same attitude just to get it to run.

1

u/Professional-Sun-684 Apr 26 '22

Since a function should focus on 1 thing and is about +/- 5lines long, the function name should explain what the function is doing.

Arguments should have self-explanatory name. For example if your function is to set up a connection and you need an IP and port as argument then name those arguments IP and port instead of x and y.

Failure cases are handled by different exception handler depending on the failure. Custom logging messages can be added to explain what happened or what went wrong. But still custom logging messages are not comments.

I highly recommend the book "clean code by Robert Cecil".

Also: I never said my code is perfect. I said my code is very readable written and is self-explanatory. readability > performance. Don't compare the guy who left you a "pile of shit" with me as you do not know me and never saw a piece of code I wrote.

2

u/BullCityPicker Apr 26 '22

OK, I apologize. You really can't believe what "that guy" put me through, and I was pretty angry. Unlike you, there were lots of 'x', 'y', and other very, very short variable names, which were obviously reused for dissimilar purposes through the code base. I'm still trying to figure out what he did.

I never saw a formal rule of thumb for function length; 5 lines seems way to short. I try to keep mine under one screen on an IDE. I looked into some of the packages I'd written. My code averaged about 22 lines per function, and had eight lines of comments per function, if you can live with that.