#134262 - ShannonB - Thu Jul 12, 2007 3:14 am
Right, so I came across this thread: http://forum.gbadev.org/viewtopic.php?t=3143
After reading it, I have the absolute fear of god about developing bad coding habits and never being able to break them.
So, where DO you learn good coding habits? It seems every guy and his dog has a different idea on what is good and what is bad.
Is there a list somewhere of stuff that everyone, or most everyone, has agreed is a list of Good Coding Habits (tm)?
_________________
"Do you know what the chain of command is? It's the chain I get and beat you with until you understand who's in rutting command here!" -Jayne Cobb
#134289 - keldon - Thu Jul 12, 2007 9:09 am
Oh no there are not different ideas of good and bad coding habits. If you google for good c programming practices you get a multitude of useful links. The first result has a good list.
#134294 - ShannonB - Thu Jul 12, 2007 9:48 am
keldon wrote: |
Oh no there are not different ideas of good and bad coding habits. |
Buddy I've just gone through the top five links that come up on google and NOT ONE of them has a single item in common. Sure, they may not be directly contradicting each other, but for all intents and purposes, it's like asking a bunch of philosophers "why are we here?".
_________________
"Do you know what the chain of command is? It's the chain I get and beat you with until you understand who's in rutting command here!" -Jayne Cobb
#134295 - keldon - Thu Jul 12, 2007 9:51 am
The reason why is because all good coding practices would span an entire book. Now what you may need instead is just a good book on C++, which will teach you good programming practices as you learn them.
#134302 - Lick - Thu Jul 12, 2007 10:37 am
One thing I found out is that whatever pattern, coding style or commenting style you're using, Google will return a rant against that. So instead of looking for the perfect practice, just watch out for truly bad practices.
_________________
http://licklick.wordpress.com
#134316 - gmiller - Thu Jul 12, 2007 1:16 pm
well, if you never start then you do not need to worry about bad practices.
Sorry I had to say that ...
Programming by definition has many solutions to each problem and there are good and bad points to each solution.
The following is my opinion and is worth absolutely nothing so take it for what it is worth.
Each set of practices is targeted at a particular problem set and so when the problem set does not match the practices do not fully apply. Depending on your programming environment the way a problem has to be solved is not always the way you would have solved it. Do not decide that a practice is a solution to every problem keep re-evaluating what you are doing and see if there are better ways.
"if you only use nails all solutions will start to look like hammers", not my words but something I have embraced. I have been writing code for quite a while and have seen many different approaches come and go as the "hot" ways to do things.
#134346 - ScottLininger - Thu Jul 12, 2007 5:09 pm
Rapid development + multiple iterations = good coding (eventually).
There are many coding practices that are essentially religious beliefs: two very experienced programmers will give you two very different (and passionate) arguments for why it sucks or doesn't.
By most standards, my GBA coding practices suck, but I've finished more projects by diving in than by worrying about how the other guys on the forums like my stuff. I love gmiller's quote...
Quote: |
well, if you never start then you do not need to worry about bad practices. |
My $.02: finish a project, post it to the forum, and ask for people's suggestions to help improve your practices. :)
-Scott
#134351 - gauauu - Thu Jul 12, 2007 5:25 pm
Agreeing with everyone else that you should just read a few, get some ideas, and then just jump in and do it, there are a few things that I don't think are ever debated for good code:
1. Readability...pick a readable, and CONSISTENT format for your code. Pick a style for variable names, indentation, braces, etc, and use it.
2. Think ahead, and do your best to write your code in a way that promotes re-use.
3. A combination of #1 and #2...use function/variable/method names that are meaningful. How meaningful is up to you, but you should be able to come back at look at your code later and understand it.
Doing those things, I wouldn't worry too much about all the rest. Sure, you'll do dumb things, but you'll learn as you go.
To agree with ScottLininger...."good code" depends on what the project is for. If you're doing something for fun, it only has to be good enough for you.
#134356 - kusma - Thu Jul 12, 2007 5:44 pm
Never commit to something just because you've heard it's the best way. Understand why it is, and always suspect your decision to be flawed. There is no simple answer to what route to take when solving a problem.
#134360 - gauauu - Thu Jul 12, 2007 7:37 pm
To heap on more advice:
Keep reading what smart and experienced people have to say. But then don't just accept it. Think about it, and see if it makes sense. Use it if it does, but not blindly.
#134368 - keldon - Thu Jul 12, 2007 8:13 pm
gauauu wrote: |
To heap on more advice:
Keep reading what smart and experienced people have to say. But then don't just accept it. Think about it, and see if it makes sense. Use it if it does, but not blindly. |
Good point. I had to say something of a similar line in the Java forum when advice was being given out. Little discussion on immutable/mutable data storage, and bottom line is that even if you found that every class from now till the day you die would be better immutable just know why it should.
#134395 - sgeos - Thu Jul 12, 2007 11:10 pm
I liked the book Code Complete (search for it). It points out a bunch of basic things people ought to pay attention to.
-Brendan