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.

249 Upvotes

215 comments sorted by

View all comments

Show parent comment

24

u/commodore-69 Jul 12 '13

I got into the horrible habit of naming variables 'test3' and looking at them later and not knowing what the hell they're supposed to do

28

u/happy2pester Jul 12 '13

I'm just peering over one of my old programs now, here's a list of some of my variables.

n,l,a,lset,etype,deus,Ruby,ruby,hper,wper,mper,fper,pper

It goes on and on and on. And it gets better. All of those are global variables, because I didn't know how to do it otherwise.

Also: Only 1 in three functions have any comments, and several resources that the program relied on have the location hardcoded in.

30

u/commodore-69 Jul 12 '13

I opted for the super descriptive variable and I'm still not sure what it does

varTakenFromTurningBecauseItsWithThisScriptFromTheBeginning

16

u/happy2pester Jul 12 '13

The previous version of that program had variables like "Bananas" and functions called "Screenish"

Still. I think I had some fairly elegant solutions in there.

8

u/[deleted] Jul 12 '13

I vomited. Then again we all have written some bad code at one time or another.

3

u/[deleted] Jul 12 '13

Thanks. I needed the self-esteem boost.

1

u/ToadingAround Jul 12 '13

Sounds like manually minified javascript

1

u/happy2pester Jul 12 '13

Python actually. A random map generator

1

u/ToadingAround Jul 12 '13

But do you need to minify python code for production? I thought python was usually just an app download

1

u/happy2pester Jul 12 '13

Minify? Also, i've never put any of my code into production, I just play with it.

2

u/ToadingAround Jul 12 '13

Ah, gotcha. Minifying code is basically compressing your code by reducing the amount of characters you have within the code. It's only really used for client-side scripts that get loaded alongside web pages (hence javascript), to reduce the data the user needs to download when loading a page.

See Google's mini-tutorial on their minifier (Closure) for some good examples of what it does

1

u/happy2pester Jul 12 '13

Ah yes. I can see how.why that would be useful. But my code is mostly poorly written python. I had what I feel are some elegant solutions, but apart from that, kinda awful