Giving Advice

AdviceAs am experienced programmer I am often asked for advice by novices (or maybe I just give it?) on coding topics, or how to approach problems, especially related to Arduino topics. Herewith a collection of these pearls of wisdom …

  1. Architects may doodle before they put final pen to paper, but they don’t start building in a haphazard way and expect the building to keep standing. You should not underestimate the insights that you need in order to write an elegant solution to a problem, and these usually come from brain work, not fingers on keyboards.
  2. Think about the problem you are trying to solve and how you would solve it before you launch into coding. You may need to write small aspects of the code separately to clarify your thoughts. Print out results to check that what you expect is happening. Then the same things applied in more complex code won’t be as daunting.
  3. Design requires an understanding what you are trying to build. There are standard functions that you always need in real-time programming (open, close, read, write, update, flush, etc), so studying the standard system libraries that exist will give you a clue around what types of classes and methods you will need to implement.
  4. Stretching the building analogy, make sure that you have a good foundation for what you are doing. A separation between the code to handle the hardware and the application makes it easy to implement relatively sophisticated functions relying on solid underlying services.
  5. Don’t be afraid to initially implement and get a simple system working before building all the bells and whistles. Remember the simple system will provide a solid foundation for the rest. When building a library, work on the application while you work on the library.
  6. The first version of what you do will not be the final version. In fact, often you need to see the first version as a way to work out the final ‘real’ structure of what you are producing. Just like for any textual document, editing and revising code makes what you have better, more structured and more concise.
  7. Read other people’s code to see how things are done in standard ways. These standards make your life easier and make your code much more readable to others. Certainly in the case of Arduino coding, Finite State Machines are king as you can’t rely on multitasking constructs, so learn the standard ways these are implemented.
  8. You need to get your head around variables and variable types. A variable is like a pigeon hole that holds a value. That value can be many different types (like int, long, char). You can also define your own types (like uint8_t defined in the Arduino libraries) or others that are derived from or groupings of different types. Data is just bits – how you interpret those bits is up to you as a programmer.
  9. Use good code techniques. This means good and consistent formatting, lots of pertinent comments, etc. I always think of it as if I was writing prose rather than code. Remember then when you come back to the code in 12 or more month’s time, you will NOT remember much about what is there. If you code and comment for this situation, your code will be readable and maintainable for everyone.
  10. When changing code, implement and thoroughly test each feature as you go. If you find bugs they can only be in the small changes you have made since the last good baseline. In a similar vein, make sure that you use a versioning system (like git) so you can go back to a last known good version when all else fails.

What other advice would you give a novice? Add it in the comments below.

Advertisements

One thought on “Giving Advice

  1. Hi Marco, Pedro147 (Peter) from the Arduino forum here. I just came across your blog and wanted to compliment you on a fine job. I don’t get on the forum much these days since I have been involved in flying and building quadcopters for the past 18 months. The ones that I have started making myself from a design released under Creative Commons are proving a challenge as this is the first SMD reflow work I have ever done. Anyway enough of that i subscribed to your blog and look forward to any future entries. I still keep an eye on the downloads of the Bigger Parola file downloads and notice that people are still using them which is gratifying. Thanks again for letting me put those on your Codeplex site it is an honour to be a very small cog in the great project that is Parola 🙂 P.S. Here are some pictures of my PedroWii flight control board http://www.pedrosdigitalsolutions.com/PedroWiiSlider.php#

    Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s