views:

768

answers:

17

Before I took programming courses in high school and college (which did not teach me much besides new syntax for new languages), I started out with a Python tutorial that served as a general introduction to programming. It included variables, if statements, loops, etc. At that point I was so excited about programming that I picked up Learning PHP and I put my first web application together.

The problem I think I have is that I started out too quickly and consequently the quality of my code suffered. In fact, I would rather not look at the code I wrote 2 years ago ever again.

In summer I read Code Complete and The Pragmatic Programmer. Although I found them somewhat useful, these books seem to be targeted at developers with much more experience than I have. I did start using source control and try to adhere to the DRY principle, but basically what I am looking for are some resources (books, preferably) that would help me quit being a hacker and become a developer who is proud of the code he writes.

+1  A: 

I found Writing Solid Code to have many good general points about programming well, and while it's written for C, it can be applied to any language.

Elie
+1  A: 

Your story of how you started development sounds incredibly like many of ours. Some of us went to school for it, some of us went to school for auto mechanics! It doesn't really change much if you've got the right mindset for it. Not everyone here has a CS degree that's for sure.

At any rate, you started out right reading Code Complete and The Pragmatic Programmer. You didn't go wrong there.

You're likely more "advanced" than you give yourself credit for.

Books like The Art of Computer Programming Series won't lead you astray. I'm sure others will chime in with some great books as well. Based on the commentary I've recieved for this suggestion I'd like to clarify that I suggest this book series only as a complement to what you're already doing. This series will help you explore how to develop more elegant solutions and likely some of the mechanics at work behind the solutions you've already been building.

Someone else has mentioned refactoring books. A great idea!

Mat Nadrofsky
While that series is great, it's not written for learning to program, IMO. It's advanced mathematical theory applied to programming. Great if you want to learn about optimal algorithms and such, but it won't teach you to write good code.
Elie
Please stop offering TAOCP as a panacea for all ills. It has exactly zero to do with coding. Please read anything you recommend!
Ying Xiao
TAOCP is a good reference if you want to delve deeper into the mechanics behind programming and ultimately, end up writing better solutions. I agree, it's not a "this is how to program" series and it's not a "beginners" series either though.
Mat Nadrofsky
Agreed, TAOCP is useful if you really need to understand the thoery of why certain algorithms for searching, sorting, etc. are more efficient and/or suitable for specific problemss. However, it's not going to teach you how to program.
Matty
A: 

Sounds like you are doing the right stuff. Keep reading and learning. It never stops as @Elie says.

kenny
+3  A: 

I would suggest to read a book about Refactoring - if you think your code is somewhat ugly and messy - its exact where refactoring books starts and they end with what it should look like! I recommend Marting Fowler - Refactoring

Calamitous
+11  A: 

Keep writing code. Read other people codes. compare how they did things to how you did them. Which seems better. I am not saying to stop reading book or doing tutorials, but the only way to become a better coder is write code. you've already seen improvement in your code in the last two years.

As Mat said not all of us have CS degrees. Keep working at it.

Jim C
Just wanted to reinforce "read other people's code" -- you can learn a ton from good and bad. If you find it easy to follow, chances are it's good programming (barring security concerns, etc).
Hans
A: 

I'll echo Jim on one of his points, read other people's code. Open source can be a great place for this. You can find some excellent (and some awful) programming examples.

And to the point of refactoring, I would argue that you have to go back to your code from 2 years ago, pull it apart, and re-write it. I've had PL/SQL packages that I've gone back to 6 months later and took 2000+ lines of code down to several hundred.

Learning more about the programming language(s) you're using and seeing how others do things is key, and you can apply those new ideas to your existing code base to see how the new concepts work.

Milner
A: 

A great book is "Programming Pearls" by Jon Bentley.

+2  A: 

Keep programming, read other programs and keep learning. While you're programming, be sure to practice critical thinking (e.g. are you solving the right problem, are your assumptions correct). Learning about data structures and algorithms helped me considerably.

Peter Norvig, Director of Research at Google, has an excellent article on this.

Ryan Ische
+5  A: 

By way of reassurance, being disgusted at the code you wrote in the past is normal, and in fact generally a good thing. If you stop being dissatisfied with past work, you are, practically by definition, no longer improving. It's a bit uncomfortable realizing you will always be critical of yourself, but it's also enlightening and relieving at the same time.

Karl Seguin's Foundations of Programming is a little .Net-centric, but it's a short series and, I think, is somewhat applicable from a language-agnostic perspective. It helped me a lot to sort out how I should be thinking about the object oriented structure of an application.

Also, Jeremy Miller's Patterns in Practice series is quite good. Again, apologies for the .Net slant, but it's still reasonably applicable to OOP in general.

I Have the Hat
A: 

I find having a project to work on is best, otherwise you can lose focus. Try and solve a problem, then go over your code and look for bits that smell and can be improved. Have a google or rummage on here, see how to do it better and then refactor!

Andrew Bullock
A: 

To me you become a better programmer when you can identify most uses of your code beforehand. This only comes through experience and cannot be learned by reading any book or article. When you make a mistake once, next time you know that what you did was bad and you know why.

Reading general software development practices would be the easiest way for you, even if they don't involve coding. I suggest you read a lot about design patters (http://en.wikipedia.org/wiki/Design_pattern_(computer_science)) and best practices.

But as much as you can - try to program and build good applications, and think about how your code will be used, not only your application. One of the greatest periods I've had is when I started writing code used by other developers through an API. This opens your eyes and teaches you a lot about what you can expect. So try and also use other applications so that you can see the problems other people have.

Slavo
A: 

Code is a good read if you're interested in a primer on what's really going on at the layer of zero abstraction. I believe the more you understand about what's really happening the better your code and approach generally become.

Matty
A: 

Code Complete, Programming Pearls, and Code are excellent at telling you the "how" of programming.

If you're more interested in the "why" behind the "how", you will probably get more out of something deeper, like Structure and Interpretation of Computer Programs (available via HTML or as video lectures).

It's a text originally used for freshman Comp Sci majors at MIT, so it starts from zero, but it gets deeper into the real art and science of programming than anything else I've seen.

There are a number of pennies that really dropped for me when I went back and studied SICP, even after ten years of programming experience. Now at fifteen years, I can say that I still see solutions that I wouldn't have seen before really understanding it.

Tim Lesher
A: 

One of the keys to creating good code is good planning.

If you want to have code that you can be proud of, try spending some time before you actually code to plan what you want to do. Draw high-level diagrams, program flow charts, possible input combinations, possible errors (and how to fix them!).

If you try to plan as you go, you may or may not be able to write code that works, but it most likely won't be pretty.

Good code is like a good book, it's clean, readable, and well-thought out beforehand.

samoz
A: 

10% of programming is writing the actual code, you need to plan a head. Every line I write is thoughtfully planned. I may seem that planning tiny programs or project is unnecessary,don't be fooled. And you learn by programming, you can read a lot but it will only get you as far. If you're interested I would like to recommend a book about low-level programming. And a book about UML, reading about how to program is just as interesting and useful.

gonegonegone
A: 

Maybe I'm missing something here, but in all their glory, books cannot teach you everything you need to know about programming. They prove to be very useful at first. Then, they gradually leave you wondering, and at last, they make you confused. Later, you only use them to look something up, prove something, or refer to something.

Solving and reviewing problems pose as one very important part of a programmers life and learning in general. That is the one thing they don't teach us in college (school). Programming is very different form other subjects. You can learn the theory, but then you won't know anything important. You can learn the syntax, but then you wont know how, when and where to use it. That is where the problems come in, they basically teach us what to do, how to do it, where to do it and when to do it.

It doesn't become clear unless we learn to push our mind to it's limits, thinking inside the frame of a programming language syntax, using our previous knowledge (non intentionally) just to solve a problem or two. That is when the previously unused, but known syntax, comes out in portions spiced with logic and determination, creating a solution.

Another aspect of programming that also proved important is experience. Given that you can't learn experience but only acquire it. You can learn from the experience of other programmers by reading their code and understanding or acquiring other ways of thinking and solving problems. Next step after this one, is improving or changing their code, to better it, and acquire more knowledge.

Everything that you have written in your question, someone has already been through. Learn from the past experiences of other programmers, avoiding their mistakes will make your learning experiences in problem solving easier and knowledge acquiring much faster.

I will leave you with this, http://xkcd.com/292/

Secko
A: 

I got a lot of out of The Software Project Survival Guide. It's got great info about software development process (specifically an iterative development approach), which is just as important as writing the code itself. Pay particular attention to the sections discussing risk management!

I currently work on medical devices, and my company's quality system is similar to the iterative process described in this book. I can't emphasize how important it is to become familiar with software development processes. Adopting and adhering to a good software process will dramatically improve the quality of your software.

There are a lot about software processes to explore out there. Take a look at some of the flavors of Agile development as well, like Scrum and Extreme Programming.

Maha