I am currently trying to break through the intermediate coder stage to advanced and needless to say it’s been tough.
I have been working through several books with example code. I have felt lately that taking the example code, changing it to fit my own similar project, breaking it, and fixing it, is more effective for learning than simply re-coding line after line of example work.
Does anyone else similar or contrasting opinions? Will this method pay off in the long term?
Thoughts on this method of learning?
Thanks!
2
I think you need a proper project: Find a problem to be solved, and solve it.
Doing something real (rather than hacking examples) will drill into your head all kinds of lessons: things that you have been taught that are good, things that don’t work so well.
The biggest difficulty in a real project is not so much writing code, its knowing what code to write. That is, how to break up and structure the problem space. Get that wrong and the nicest code in the world is still a lousy solution.
1
Reading other peoples code all the time is a sure shot way of improving your skills on the project. No doubt about it.
It also helps to be the dumbest guy in the team – by that I mean to say that if all the other programmers in the team are way above you in terms of programming skills it will automatically lift your level too – as long as you have the maturity to accept your limitations and ask for help. So leveraging skills of other team-mates is also important.
Reading code – apart from reading other people’s code and asking them to explain their approach, pair programming is another good tool. Just sitting with a peer and observing their way of tackling a problem can set off light bulbs in you. Also make it a habit to always review your own code – old code from time to time. I recall many times when I have visited a 100+ lines of code I wrote myself 2 months back and thought it was shit and refactored it much better.
1
I think the most important aspect of learning is failure. When you attempt to adapt example code or implement something new and it doesn’t work, you have to figure out why it doesn’t work.
This is when your brain will be put to work attempting to solve the problem you have come across. And when you finally have that ‘aha!’ moment, what you have learned from the initial failure will stick in your mind.
It’s this process that is vital to becoming a better programmer. Good programmers are good at figuring out how systems work, why they don’t do what they should and how to fix them. And the only way to get good at this is to practice solving problems when something fails to work.
If you do nothing but copy code from a book and run it it will always work (assuming no typos by yourself or the book) and you miss out on the vital experience of figuring stuff out for yourself.
1
I guess both are useful, but your coding on your own will be better.. Other’s code will help, you will get to learn some things you couldn’t have thought of but at that transition, it’s how you think that matters.
It would be better if you take a few problems and solve them. Use other People’s help when there are any problems that you can’t get around. That way you will learn a lot more than by fiddling around with other’s code.
When doing it all from scratch, you can understand every little thing of the code. Also, you will also learn from your mistakes(everyone makes them, and so will you).
When you type code, it’s usually not what you type, but how you think of what to type, the logical analysis of the problem (and the inference/derivation of the solution) is what matters.
Absolute majority of programming work is done in a team and involves code base that already exists for some time and needs to be continuously adjusted for new requirements and features. You won’t ever learn that from text book, you have to try it.
Working with other people’s code is also great way to get experience how various idioms work in practice. You won’t normally try to solve problem in all possible ways to see which one works better and you won’t come up with that many ways yourself anyway. By reading existing code you will see various approaches to solving problems and learn what advantages which has in practice, so you can easily pick one when you need to design something yourself.
Lately there are many open source projects out there, so it should be easy to pick one that is interesting for you and contribute to it. You can start by fixing bugs or doing some small feature you think of. That’s currently easiest way to get experience with some real programming work. You can even get grant for it from Google.