Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

How do you go from being an okay programmer to being able to write maintainable clean code? For example David Hansson was writing Basecamp when in the process he created Rails as part of writing Basecamp in a clean/maintainable way. But how do you know when there is value in a side project like that?

I have a bachelors in computer science, and I am about to get a masters and I will say that colleges teach you to write code to solve problems, not neatly or anything. Basically you think of a problem, come up with a solution, and write it down...not necessarily the most maintainable way in the world. Also my first job was in a startup, and now my third is in a small team in a large company where the attitude was/is get it done yesterday (also most of my jobs are mainly database development with SQL with a few ASP.NET web pages/.NET apps on the side). So of course cut/paste is more favored than making things more cleanly. And they would rather have something yesterday even if you have to rewrite it next month rather than to have something in a week that lasts for a year. Also spaghetti code turns up all over the place, and it takes very smart people to write/understand/maintain spaghetti code...However it would be better to do things so simple/clean that even a caveman/woman could do maintenance. Also I get very bored/unmotivated having to go modify the same things cut/pasted in a few locations.

Is this the type of skill that you need to learn by working with a serious software organization that has an emphasis on maintenance and maybe even an architect who designs a system architecture and reviews code? Could you really learn it by volunteering on an open source project (it seems to me that a full time programmer job is way more practice than a few hours a week on an open source project)? Is there some course where you can learn this? I can attest that graduate school and undergraduate school do not really emphasize clean software at all. They just teach the structures/algorithms and then send you off into the world to solve problems.

Overall I think the first thing is learning to write clean/maintainable code within the bounds of the project in order to become a good programmer. Then the next thing is learning when you need to do a side project (like a framework) to make things more maintainable/clean even while you still deliver things for the deadline in order to become a great programmer.

For example, you are making an SQL report and someone gives you 100 calculations for individual columns. At what point does it make sense to construct a domain specific language to encode the rules in simply and then generate all the SQL as opposed to cut/pasting the query from the table a bunch of times and then adjusting each query to do the appropriate calculations. This is the type of thing I would say a great programmer would know. He/she would maybe even know ways to avoid the domain specific language and to still do all the calculations without creating an unmaintainable mess or a ton of repetitive code to cut/paste everywhere.

share|improve this question
5  
I would +1 this, since it's an important question, but this goes on rambling way too long. Might be a good answer to a "tell your experiences with.." type question, though. –  DarenW Oct 8 '10 at 22:39
show 1 more comment

closed as not constructive by Mark Trapp Oct 13 '11 at 20:03

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

24 Answers

up vote 46 down vote accepted

Aside from agreeing with Josh k's answer...

  • Read code and lots of it.
  • Write code.
  • Read books and lots of them. Work along with the examples.
  • Write some more code.
  • Speak with other programmers. This is often overlooked. There are lessons to be learned from everybody.
  • Keep on writing code.
  • Think of ideas when away from your machine.
  • Still coding? I hope so.
  • Remember to go over your code after taking a few hours or days away (if you have that kind of time.) It gives you a new perspective.

Good luck!

share|improve this answer
2  
What are you saying... that by coding an interacting with other coders you'll improve? Hogwash! –  ChaosPandion Oct 3 '10 at 5:50
1  
This points out something that most career counselors, books, job hunt sites, etc. miss: it's important to know what the grungy day-by-day work one must do to be competetent or brilliant in some field. –  DarenW Oct 8 '10 at 22:29
1  
Should be "Write code, lots of it" and "Write lots of more code"... –  user1249 Feb 13 '11 at 16:56
show 5 more comments

Researchers have shown it takes about ten years to develop expertise in any of a wide variety of areas... The key is deliberative practice: not just doing it again and again, but challenging yourself...
  — Peter Norvig [emphasis mine]

Experts are made, not born.
  — (unknown)

share|improve this answer
show 1 more comment

Some really good ideas mentioned already, I will mention one more.

Surround yourself with great programmers.

The best way to learn is to learn from the best. Make sure you're not the best developer amongst your colleagues - if you are, it might be time to move on.

share|improve this answer
8  
The question is how do you find a company with the best programmers so that you can work under them. –  Cervo Sep 29 '10 at 0:32
show 3 more comments

I really think that the greatest programmers are those who understand business. And more specifically the impact of their output on the business.

A great programmer is the one that will maximum the ROI (Return On Investment).

To be able to do that, you have to be really interested in BOTH, programming and business.

It is very rare, and when a company get one, they usually try to keep it forever.

If you are just a good technician, you can be replaced easily.

Seth Godin's coined a name for that kind of person.

Linchpin - Are You Indispensable ?

http://www.amazon.com/Linchpin-Are-Indispensable-Seth-Godin/dp/1591843162

alt text

share|improve this answer
2  
Although I agree with you, I don't with the financial notion. Understanding the business is completely false. Entire corporations thrive over improvised ideas...take facebook as an example (I'm no fan of facebook btw). Understanding the trends and needs/demand would have been more appropriate IMHO. –  Christian Oct 3 '10 at 12:39
1  
Don't you think that Facebook like successes are based on luck rather than understanding market trends & needs/demand? I'm reading an interesting book on the subject called Dance with chance. Great piece of writing. –  user2567 Oct 3 '10 at 12:45
add comment

IMHO the biggest thing that separates so-so programmers from great programmers is the a firm grasp of multiple levels of abstraction and the ability to think about the same problem at all of these levels. Often one level provides insights that are almost impossible to grasp at another level. To be a truly great programmer, you need to be comfortable at all of the following levels of abstraction (from lowest to highest):

  1. Assembly language. (At least reading it and being familiar with the basic concepts, such as what a calling convention is, what the stack and static data segment are, and what various compiler optimizations look like at the ASM level.)
  2. The C-style memory model. You need to have a firm grasp of pointers, manual memory management, how object-oriented programming can be done in languages like C, how garbage collection can be implemented, etc.
  3. Programming of single-use components in a garbage-collected, far from the metal language. In other words, basic code monkey style programming.
  4. Design patterns and how to separate the parts of a problem that vary from the parts that are reusable.
  5. Metaprogramming/reflection. Exactly what kind isn't as important as the thinking style. It can be Lisp macros, C++ or D template metaprogramming, Python reflection, etc. The important thing is that you are comfortable with the idea of programs operating on themselves in non-trivial ways and can use this to make interesting, useful things work.
  6. Theoretical computer science. Things like big-O notation, NP-completeness, graph theory, number theory, type systems, etc.
share|improve this answer
add comment

Just like anything else, the best way to get better is to practice, practice and practice some more. Read other peoples code, read books, and code some more. It is also good to have someone else that will look at your code with fresh eyes and can/will give you constructive criticism.

share|improve this answer
2  
any practice: personal projects, open source, etc. Open source is good, bc you are working (usually) with others who can critique your code. Tiger Woods didn't become Tiger Woods by sitting around reading about golf. –  Muad'Dib Sep 28 '10 at 3:03
show 3 more comments

Eat lots of spinach.

There aren't any tricks or tips that will turn you magically into a "great" programmer. Programming is something I love, and that is what (at least in my eyes) makes someone great at what they do.

If you don't absolutely enjoy it you will be hard pressed to do the things that lead to this "greatness." Experimentation, play, practice, hard work, endurance, etc. This doesn't just apply to programming.

share|improve this answer
2  
-1; Cervo wasn't asking for magic tricks, and even if you love it some paths are going to be more productive than others for honing that love into excellence. –  BlairHippo Sep 28 '10 at 15:59
3  
Note that keeping healthy and reasonably physical fit also can make a difference in your energy levels and your ability to perform mentally at your job. You don't need to go overboard, but eating your spinach quota and getting some exercise can only do you good. –  fennec Oct 3 '10 at 19:48
show 6 more comments

Pair programming, when it is practiced, is one technique which can help expose you to new concepts and techniques, feedback from your peers, and insight into the way they work. Even pairing with junior developers demands introspection and synthesis of ideas and insights that you have experienced, and helps you understand and internalize them.

(My team does pair programming and it really helped me get up to speed when I first started work there after college, and it continues to do so today.)

share|improve this answer
show 5 more comments

IMHO
1) Write a bucket load of code on a regular basis - doesn't have to be good code, just as long as you're writing and thinking
2) Read a lot of other people's code - understand what's good, bad and why they made the decisions they did.
3) Learn your algorithms and data structures to a pathological degree
4) Learn a variety of languages i.e imperative, OO, functional - this will broaden your outlook on the world so don't be a 'one trick pony' i.e c++ or java but look at how problems get solved in the python or ruby community then look at it again in the Haskell or Erlang communities
5) Understand hardware and the thinking behind it - caches, instruction scheduling, memory fences etc are there for a reason. It's good to know why.

HTH

share|improve this answer
add comment

These points seemed to have been missed or hidden within other points:

  • Read other programmers' discussions on HOW TO program better. Don't just look at the code. (The most common source of this is blogs.)
  • Think about the code you're going to write. Make it the best that you can at that time, organizing it with the principles you've learned from the blogs and books about programming well. Again, simply examining existing code won't help.
share|improve this answer
add comment
  1. Keep learning (from programming resources and other domain : be curious!)
  2. Persevere
  3. Experience Programming : Write Code - Have spare time projects
share|improve this answer
add comment

There are a few different ideas I'd suggest:

  1. Get involved in your local community organizations that may help with some skills. For example, in my case a local .Net User Group can be useful for building contacts, seeing code, asking questions about code, etc. This could also give you an idea where some great programmers are as some may share an employer that seems like a great place. Alt.Net would be another example of something that may be useful in some cases.

  2. Ask and answer questions here and on StackOverflow can also increase your knowledge as well as test what you know.

  3. Understand the scale of various solutions. For example, some IT projects may require years of work to get done because so much has to be done spread over so few people in replacing a big system like an ERP, CRM or CMS. Similarly, a bug fix may have various approaches to fix it depending on how long someone has to work on it: It may be fixed in 2 days, 2 months or 2 years. In some cases, each can make sense depending on how bad the bug really is. When are you just doing a little proof of concept project and when are you building an enterprise application that has to survive in production for years.

  4. Consider various personal development ideas. Sources of Insight would be a blog example that has various ideas that may or may not be something for you. There are tons of self-help books and chances are there are probably a few that may help you but figuring out which ones those are may be a bit of a challenge. How to Win Friends and Influence People would be a book suggestion about how to deal with people. Other book ideas here would include The Mythical Man Month, Peopleware, and Joel on Software.

Likely some combination of these and others are what some do to be the great programmers is my guess at an answer.

share|improve this answer
add comment

Two things I didn't see mentioned:

  • Documentation, a lot of it. Many programmers overlook this, but in truth, documentation and references enhances your future work, especially if you're a forgetful guy like me.

  • Keep away from good programmers. This is mostly to break the trend in answers, but give me a chance to explain myself. Although I've learned a lot from good programmers, they're like a drug. Too much of them and you're one of them. The thing is, being a good programmer isn't constant. While someone is good at a certain kind of programming, he slowly dies out, just as that particular technology dies out (obsoletion etc). So why should one keep on his own? It instills a sense of creativity in you. For instance, I used to write a lot of eval() in GML, and slowly found out how it was bad for performance. By the time I started writing JS, I knew how to avoid eval() at all costs. Not only that, but today, I even know where to use eval(). If I had to go "the great programmer way", I wouldn't be using eval() at all (Crockford et al) which is bad considering there are places (such as dynamic code) where one really needs to use this feature.


(did I just wrte eval() 5 times? ;-) )

share|improve this answer
add comment

I joined 2 open source projects and I learned a lot from the other team members while doing. Not only improving technical skills but also follow the style guidelines and work together in a team. Watch old code from team members and fix bugs which makes you understand the pitfalls.

share|improve this answer
add comment

In systems programming, One thing I consider vital to the great programmers is Domain Knowledge. It's not just being able to write good code, it the the ability to understand the basic facts and challenges of the real-world problem that your program is solving. You don't need to be an expert, but you need to be able to hold intelligent conversations with the experts.

share|improve this answer
add comment

There are kinds of software jobs which do not emphasize on software. Usually the users need some data, and some "software responders" fetch the data by typing in some queries. Once the users get the data, the queries aren't needed anymore. It is throwaway by definition and it's impossible to learn software engineering working on this kind of assignments.

share|improve this answer
show 1 more comment

Although the quote below is about mathematics, I believe it can be adapted easily enough to programming:

Don’t just read it; fight it! Ask your own questions,
look for your own examples, discover your own proofs.
Is the hypothesis necessary? Is the converse true?
What happens in the classical special case? What
about the degenerate cases? Where does the proof
use the hypothesis?

— Paul R. Halmos
share|improve this answer
add comment

There is just one way: Spend every waking hour in front of the computer. Look at everything that you can get your hands on, play a few days with everything (computer graphics, 3D, games, graph theory, number theory, tools, IDEs, visualization, using various applications, writing your own text editor, databases, HTML, create your own website, to name just a few). Don't only use applications but join the development teams, submit a couple of features or write your own version.

Do that for 20 years and you will be a great programmer.

share|improve this answer
4  
Do that for 20 years, and you still won't have a [w/l]ife. :) –  Jonathan Sterling Oct 4 '10 at 6:23
show 2 more comments
  • Write a lot of code.
  • If you are the best programmer in your project, find a new team to work with.
  • Repeat.
share|improve this answer
add comment

I think it is important to remember most programmers, probably even 95%, will never be great. The majority are somewhere in the good to very good areas. Even quite a few well know internet 'gurus' often are not that great, just loud.

share|improve this answer
show 1 more comment

Practice, think, "What can I do better?", practice, and ask someone else, "Is there a better way?"

I do some flute in my spare time, and the statement that is most often found to be true in the best musicians is, "Perfect practice makes perfect." The question then becomes, what is perfect practice? I believe that the answer is whatever works to get you better the quickest. For example, I learn best by hacking together code first, then going through a structured turtorial. If I've cut my teeth on the problem myself, I have found that it's much easier to learn it right. The key for me is to know when to stop trying to do it on my own and get help. I know other people who learn best from a structured class/tutorial, and wean themselves out into the technology.

Remember: "Whatever works for you" can only be discovered by doing it over and over again in different ways until you discover how you learn best.

share|improve this answer
add comment

A few things I would recommend:

Read a lot

Keep learning, and look at different types of programming (OO, Functional, Logic etc).

Do Code reviews.

Teach!

Write articles or better yet a book, you will learn a lot by presenting information to others

share|improve this answer
add comment

I think learning is an iterative process.

  • Make sure you go to the basics often, meaning doing SICP and working out problems, reflecting on them. The abstraction process is very important for developing intuition, which I think is very important.
  • Read code and understand it as solution to a problem, reason why it has evolved the way it is(VCS are your friend) and think of an alternative solution. If it is an open source project, fork it and implement using your own ideas. Even if your project is not useful to anyone, you have learnt a lot by diving in.
  • Lastly, repeating everyone here, write lots of code.
share|improve this answer
add comment

Something that has been missed is refactoring. I think going through the process leads to better code in small steps and overall you end up with much better code. One book I found which is really good is Refactoring: Improving the Design of Existing Code. The more I go through the process the more I become familiar with more factored code so each subsequent time the code needs less factoring. It does a lot to reduce duplication and make the code easier to maintain. The best thing is that refactoring lets you start small so it is easy to get started.

In any case, I think refactoring is a great way to become familiar with better code and even to see a way to turn so so code into better code. It also seems to undo some design oopses...

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.