Developing good programming style

I have taught myself c++ mainly from books and reading tutorials on line. While I would by no means call myself an expert, I still have learned a lot about the language and have become competent at using it. This said I fear I have picked up a few bad habits during my self education, so my question is how would you recommend someone develop good programming style, and what are some examples of bad style that you find common from new programmers.
I used to suck so much but then i learnt to pretty much use functions alot, so its easy to bug fix. for example "printHighscore();" before i would of just just printed it in int main() appart from that I probably still have a lot to learn as well!
@Belldore

Just a quick message - don't make a reply unless you are sure that it is going to be helpful in some way. I am sure the OP is well versed in using functions.

closed account (i23CM4Gy)
Always use braces. If you decide to add a second line after a simple one-line if or while statement, and forget to add braces, you've just created an error that can be very hard to find and won't show up in the compiler log.
I'm not the one to talk to, but there are "best practices" books out there. Effective C++ is one recommended by many people, including professionals. If you haven't read that yet, you might give it a try. I have it in my shelf, but it's still too early for me to touch that one :(
I would suggest getting some coding standards and following them as they are all about coding style, although they wont iron out bad practice they will help keep your code readable and maintainable.

There are plenty of free ones out there, personally i like the idea of letting some mega corp like google or MS do the research for me and then just use their standards which are usually published and free.

To educate yourself on good practice i would recommend reading books. Which books is the question. Are you looking for good practice for c++ generally? or for windows programming? or data management? the list is endless and obviously prompts other questions.

In short, to answer the original question, Use a recognised coding standard and your style wont go far wrong.
Thank you for the suggestions. I will definitely be getting more books on c++ and taking a more in depth look at established coding styles. Also I plan to take my first formal class in c++ programming next year so that should help as well.

The main thing I am worried about is that I spent a lot of time learning different concepts, like what a singleton is and how create one, and not as much time focusing on when it's appropriate to use these tools.

As for what area of programming I am focused on, I started learning c++ for video game development, and while I still do enjoy this, I began spreading out into other areas, perhaps a little too much.
Recommended: 'C++ Coding Standards: 101 Rules, Guidelines, and Best Practices' by Sutter and Alexandrescu.
http://www.amazon.com/exec/obidos/ASIN/0321113586/
@JLBorges +1

and not as much time focusing on when it's appropriate to use these


yes, thats the problem for everyone. You cant learn that beforehand, it is a refining process that comes with time. As you write code and encounter problems, stuff you know will pop into your head, it may or may not be appropriate for the job in hand but as a beginner you wont know that until you've tried coding it.

Software engineering is a skillz job and you cant get skillz from a book. Just do it, if its wrong do it again. In 10 years you could be an expert, but only if you learn from your own mistakes, books are good for reflecting on your own learning, helping you to understand why something was inappropriate, and perhaps gleaning a more appropriate solution for future use.
@TheIdeasMan
sorry, but my reply definetly will help, but Im just making sure that he dosnt expect me to be some c++ mastermind when I'm not, just trying to help
Last edited on
Topic archived. No new replies allowed.