How to become a programmer
Hello,
I have been doing some web programming during the last few months and I'd like to become much better at it. I am trying to learn by reading programming (php) books and doing the practice exercises. I have also tried to write my own code for fun. The problem is that the stuff I do from books are really, really boring! The stuff I do on my own is more fun, but I get stuck quite a bit. Last week I spent an entire day trying to debug why php was not connecting to the mysql db. Once I figured it out, it was great, but I was beat. Is there a better way to learn programming?
36 comments
[ 0.20 ms ] story [ 82.1 ms ] threadOne thing I realized was the importance of rhythm. If I code for a day and then come back to it after a week, it was almost like I was starting from zero.
Coding for sometime continuously is a good way to pickup a new language.
Most into tutorials start "this is an int, this is a char, this is a variable, etc." Before you even get to anything interesting you are already dozing off.
With PHP, however, you can hack together your own blog/website show it to your friends and say "I made this." The ability to say "I made this" is the best feature of any language, but usually it is a pretty inaccessible feature for the beginner.
PHP is definitely not a good language to start programming at first (for that I'd recommend Scheme, ala SICP) but it's definitely a great one for a My First Website project.
Also, I think it's important not to rely too much on others for acquiring knowledge.
http://hacketyhack.net/
It's a pretty decent introduction to Ruby.
And I tend to agree you should probably not start with PHP as your first language. I did, and now all I do is Python and Ruby which are significantly better, imho.
I think the main thing to accept is that if you're going to be coding then you're going to be thinking a lot. If you're not thinking and going on auto pilot then you don't know enough...
Now on to becoming a better programmer:
Find a good project and read some theory books on debugging and how to write code in general (check amazon.com and read the reviews). Books like Code Complete 2nd edition and Beautiful Code. If you want to be more serious about it, the Computer Science series by Knuth will give you all you need to know to get a CS degree, but they are boring so you have to be willing to stick with them. Those books, 3 volumes, are the bibles of Computer Science ( yes, someone will disagree) and as such they are theory. However, you need to know a good deal of that theory to write good software. Specifically, you can concentrate on searching/sorting algorithms, algorithm analyses and machine architecture.
In general, you will find that there is a HUGE learning curve to understand what the computer is doing with your program and how to write code that makes sense, which makes you a good developer. However, the time you invest in learning what happens behind the scenes is worth it's weight in gold, independent of the language you use.
Always try to figure out what the tool/language you are using is trying to do and don't blindly trust it.
Never, ever skimp on comments. You don't have to write a novel and explain that you are adding 2 to variable i, but do explain what the function is doing or what a complex bit of code is doing, this will save you hours when trying to find that bug.
Use a version control tool. The simplest one to use would be Subversion and the book for it is free online. There are also free Subversion hosting services such as http://beanstalkapp.com/.
Depending on how serious you are, you might want to look at the coursework from colleges like Stanford. Many top schools post their coursework with lectures online.
Google is your best friend. Just paste the compiler error and remove any variable names and you will often find people who had the same exact problem with possible solutions. You might have to play with the search string, but you will often arrive at an answer quite fast in this manner.
Try to find mentors on forums and newsgroups. This will take time as you develop relationships with people, but it's the best way to learn as the software development industry is still, very much, based on the notion of apprenticeship.
Try to study some open source projects. Little ones are best, as they are least complicated usually. Trying to figure out what someone else wrote will make you a better programmer in a hurry, because you will notice mistakes people make and how you would like to do things differently.
Lastly, think about which tool/program/etc. that you would love to have or rewrite an existing project in your own style and do it. The first one will be horrible, full of bugs and many many problems, but it will teach you more than most classes you take in school.
Better yet, don't name your variable "i". Name it something like "PartCounter" or "CustCtr". Then you won't have to write many comments. Your code can be largely self-commenting.
As a general rule of thumb (IMO), never name any variable with less than 3 characters and never allow one variable name to be completely contained within another (Ctr & CustCtr). Being able to find every instance of a variable (and nothing else) with a simple editor global search will save you much time and headaches over the next n years. (Oops, I just violated my own rule.)
( i for one will continue to name my counters i :-) )
Although I often try to avoid using counters at all via foreach or recursion.
No. You found it.
When I first started studying CS at school, I thought that there was some secret knowledge that the true hackers had that allowed them to program without thinking about it. And alas, I must not have had the hacker gene because I worked at it and worked at it and worked at it until I solved a problem, only to move on to the next problem.
Then, it hit me: That's the secret knowledge. You just have to keep chipping away at it. Eventually you'll become good at it. There's no free ride; it's a lot of hard work.
Unfortunately, days when you try and solve one problem for a long time can be common. When you think you are getting into something like that you need to take a 5 minute quite break. Something that gives your concious brain quite time, I find ideas and answers flood in then.
So in your case its fine to learn PHP but I would encourage you to look at many different things that are unlike or even the antithesis of PHP. It will help you understand where general computing nomenclature comes from, what the limits of your chosen technology are, how best to implement it in a given environment and ultimately it will give you a much better understanding of the technology itself.
Begin at the beginning and go on till you come to the end: then stop.
Ideally, you'd work in the same room as your mentor, but it should be enough if you can meet once a day or so. A longer feedback cycle, or mentoring remotely through the net, is less than ideal, but anything you can get is better than being on your own.
Ask them what language they'd be more comfortable helping you out with. Start playing with that language. For that, follow other advice in this thread. Don't expect to be spoonfed.
If you get stuck in something after giving it a honest try, ask. Every now and then, show them what you are doing, even if you have no immediate problems. Chances are that they can steer you into better ways to think about problems, simplify your code, etc. These are insights that only come through experience. They are often hard to explain out of the blue, and hard to internalize so that you can put them to use later, when explained in abstract terms. They are best communicated in little doses, while commenting on actual code that addresses actual problems. Ideally, your code and your problems.
I'm now spending my time on RoR, and I don't think it's a very good language for starters. It's just too much to learn at once.
For a first project, I'd say, just don't give up, think of something you want to make and dont stop until it's done.
2. Do the exercises
3. In parallel, choose an open source project and join on that
4. Share with us your experience
http://xkcd.com/353/