Wednesday, May 27, 2015

Driving

Driving a car isn't hard.  Most 8 year old kids can do it.  Start it, put it in gear, press the accelerator, and steer.  But driving well takes lots of practice.  We typically start with supervised learning at about age 15 and after a year or so get a driver's license.  Even then most people are marginal drivers, but continue to learn and improve for most of their lives.  Some learn quickly, others just never seem to get very good at it.  A lot depends on how much they try.

Programming is a lot like driving.  Someone interested in learning can get on the web and find any number of tutorials.  Within a couple of days they can be writing simple programs of their own.  That's a great confidence booster, and gives one a sense of power much like the first time they drive on an open road.  But just like driving, that is simply the start of the journey.  Learning to program well is a lifetime journey.  And again like driving, how good that person gets at programming depends a lot on how much effort is put into it.  What does it take to become a good programmer?

Many new programmers think that knowing a programming language makes them a programmer.  And that knowing several languages makes them a good programmer.  Nothing could be further from the truth.  Does knowing English make one a writer?  Does knowing English, French, and Russian make one a good writer?  Does owning a Ferrari make one a good driver?  Does owning a Ferrari and a Maserati make one a race driver?  Programming is about solving problems.  It matters little what language is used to express the solution.  Some types of cars are better suited to certain tasks, and certain languages are better suited to certain types of programming.  Part of being a good programmer is knowing how to choose and use the right tool for the task at hand.  For a small line following robot, perhaps C is the right language.  For a large artificial intelligence database, perhaps Lisp is better suited.  Learn the strengths and weaknesses of different approaches and languages, then choose the one that is right.  It is much easier to learn a new language when you have a problem to solve that suits that language.

If a person learns to drive in a small economy car, then suddenly finds themselves behind the wheel of a large transport truck, things aren't likely to go well.  The knowledge and skills learned in one only superficially transfer to the other.  Something like parallel parking in the small car will be essentially impossible in the truck.  Computers come in different sizes just like automobiles.  One may be a small microcontroller with a few kilobytes of flash memory and 64 bytes of RAM.  Another may be a desktop PC with several gigabytes of RAM and a couple of terabytes of hard disk space.  Programming techniques that work well and make sense on one rarely transfer well to the other.  On the microcontroller, it may make sense (or be necessary) to use small, simple data structures and write code to be simple and efficient.  On the PC, it may make more sense to use dynamic memory allocation for large data structures and have garbage collection to clean up what's no longer used.  I have seen many people who have some programming background on PCs with something like Python or Java try to transfer their techniques to and Arduino.  But creating an object of some "black box" class on a PC may use a few kilobytes of memory by itself, and the Arduino may only have a total of two kilobytes.  Obviously, that isn't going to work.  A different approach is needed.  Learn what works and doesn't work on they type of system you are trying to program.  Remember that different types of computers require different development strategies.

When learning to drive, we don't memorize every road and every turn we need to take, or every place we need to stop.  We learn to read road signs and remember rules to apply in new situations, like when to give another car the right of way.  Similarly, we don't try to remember the solution to every programming problem we may encounter.  We need to learn the "rules of the road" for the types of systems we use, and the types of programs we write.  Then apply those rules to the problem at hand, developing a new algorithm (method of solving a problem) for that particular problem.  A good way to pick up new ideas (rules) is by reading other people's code; if it is good code!  Unfortunately, there is a lot of terrible code on the web, especially in Arduino land.  Part of the learning process is learning to separate the good from the bad.  Books and dedicated programming websites are often a good way to learn the basics of good code.  Asking someone you know is a good programmer is also a good way to learn.  If you have someone like that available, ask them specific questions.  Don't ask "how should I write code?" unless you brought a lunch for both of you.  Keep in mind that every programmer has different ideas of what is good and bad.  If you ask ten programmers what makes good code, you will probably get at least twelve answers.

Programming is a very rewarding pursuit.  It opens up possibilities of power to control many, many things.  It is also a great career.  If you choose to take up programming, remember that it is never-ending journey.  Keep learning and improving your skills. After more than thirty five years, I am still learning new things every day.  There is more to say about it than any one person could say in a lifetime.  So look around for what interests you.  Read books, visit websites, watch videos, and ask others for tips and techniques or ideas.  Keep pushing forward.  But most of all, have fun.  I am!


No comments:

Post a Comment