4 ms·
I write C++ for a living. I don't have time for Internet mentoring but I will suggest a few resources and general ways you can improve your code. Are you a C++
by fredophile 13y ago
I write C++ for a living. I don't have time for Internet mentoring but I will suggest a few resources and general ways you can improve your code.
Are you a C++ novice or a programming novice? If you're a programming novice you should take some time and learn some standard algorithms and data structures. Introduction to Algorihms is fairly standard for university algorithm course. Make sure you understand complexity and big O notation. Understand typical container classes and their trade offs (lists, queues, stacks, deques, various types of trees, etc).
The best way to improve your code is to write code. Reading good code also helps but when you start out you can't tell good from bad. Here are some questions to ask yourself as you write:
Is what I'm doing clear? Will I be able to understand what I did and why I did it if I read this a year from now?
What could go wrong? What inputs do I expect and what happens if I get something unexpected?
How hard will this be to update?
How hard will this be to debug if things go wrong?
For a novice I'd suggest reading Effective C++ and More Effective C++ by Scott Meyers. Read a point or two a week and really focus on using them in your coding that week. This will help you build up good habits. A lot of good coding is good habits accumulated over time. Herb Sutter is another author with excellent books for beginning to intermediate coders. He's also got a really good blog.
Once you've read and used techniques from Meyers and Sutter get a copy of Code Complete by Steve McConnel This book is a great resource. Once you've read it all the way through you can read Modern C++ Design by Alexandrescu. Anytime you find yourself thinking you should use a technique from Alexandrescu stop. You've probably gone too far and over thought something. Maybe ten percent of the time this happens you'll be right and template craziness is the right approach. You'll save yourself a lot of headaches the other ninety percent of the time by thinking more about what you're doing.
I know that some of these books are expensive but you really don't need to get them all at once. You can take a long time reading through each of them and learning to apply their content.
- sedeki 13y agoThank you for this answer. I will look into all these things but in particular the algorithms. Do you think it's worth learning esoteric algorithms or just the fundamental ones in order to get a job? Also, what do you think about design patterns? Do you use it in practice (often)?
- fredophile 13y agoTo start with it would probably be best to focus on fairly standard data structures and algorithms. Here are some you should learn about: stack, queue, dequeue, linked list, doubly linked list, binary tree, heap, B tree. You should be able to identify some times when you'd want to use one vs another from this list and what tradeoffs they have. Esoteric algorithms aren't necessary but can be nice to know. If there's an area you want to specialize in or learn about you should learn the basic algorithms for that area. There are lots of things I've learned that I don't use regularly. For these things it's enough to know about them and have a rough idea. That's what books and the internet are for. Design patterns can be useful if the people you work with know them. Their biggest benefit is giving you a common set of terminology that you can use to describe something. If I tell someone I'm using a factory they'll usually know what I'm talking about without needing more explanation. However, I wouldn't worry about them for now if I was you.