r/learnprogramming • • Jul 12 '13

What are some bad coding habits you would recommend a beginner avoid getting into?

Whether they're stylistic habits or program design habits. I'm learning java and want to be sure to write my code as efficiently as possible to avoid lengthy code and poor design choices.

250 Upvotes

215 comments sorted by

View all comments

Show parent comment

10

u/YuleTideCamel Jul 12 '13

good naming convention is key, but be judicious with commenting. It is possible to over-comment and create extra noise that makes code harder for read. It's also possible to create useless comments that could have been replaced with a well named method.

This is an example of a useless comment //set counter to 0 int counter = 0

This is an example of good method naming replacing a comment //calculate average public double GetAV(int[] numbers) { // do stuff } the comment could be removed by naming the method: public CalculateAverage(int[] numbers){ //do stuff }

There's more of course, it's all illustrated in Clean Code

2

u/MonkeyNin Jul 12 '13

A phrase I've heard is: comment what, not how.