How to succed in coding optimized programs.

Most people cant be race-car drivers, yet they can drive a car. Same goes for programmers, most optimization of the code is today done by the compiler. So there is seldom any need to manually optimize loops or fiddle with the small things. This however does not excuse giving up optimization or making your program to work as snappy as possible. Here are a few steps, I will explain them after but these are good to copy paste into your word-document, print and put near your computer.

  1. Choose the correct algorithms for the problem you are solving.
  2. Write readable functional and documented code
  3. Test (on the hardware you are gonna run it on)
  4. Analyze the test’s and find the weak-spots.

Choose the correct algorithms for the problem you are solving.
This might seem obvious, but it’s not and it is the step you’re gonna correct most of the time. There are in normal software development to many variables to keep track on to choose the correct algorithm the first time. This does not mean you’re a bad developer. It’s just life.

Write readable functional and documented code.
In this step, don’t pre-optimize, don’t write hard to read code just because you can or want to show off how smart you are to the few other that could be reading the code you write. The longer it takes to understand the code you are writing, the longer it will take to fix bugs, and the slower bug fixes and new features will come to the user of your program. Now who do you really care about? think about it! Why document you ask? well, because if you write in plain English (or whatever your preferred tongue is) you explain what the code is supposed to do, if someone finds out that it doesn’t do as described the bug is probably there. Coders who say “all you have to do is read the code” has it all wrong. Think about it like a destination and driving instructions”. If you only get the instructions like this: “take a left, walk 2 houses, take a right ….” without the destination clear someone who knows the destination and how to read and write instructions wont be able to fully understand.

Test (on the hardware you are gonna run it on)
You probably have a decent to really fast computer. Do your users have that? do they need to? If you’re writing for a microprocessor or mobile-phone or similar. there is one thing I can tell you, DON’T TRUST EMULATORS. There is always small but crucial differences on running on your computer or on the actual device. It could be they way you’re holding it, the way it reads from file-system. What I’m telling you is that there is no substitute for testing it on the hardware the costumer is gonna use your program on. The sooner you test it on hardware the sooner you’re gonna find the things about your program that sucks, and you’re able to fix them. The sooner the better!

Analyze the test’s and find the weak-spots.
Did you choose the correct algorithm to solve your problem? is there a performance bottleneck somewhere that you didn’t thing of? Fix it.

Most importantly do this for every feature added. If your writing something for a platform other then the one you are writing code on, test on hardware as often and as soon as possible or you will fail.

This was a nice little Saturday morning rant. I should do this more often, I was actually angry while typing. And I borrowed a lot of the language from a book I’m going to review in a little while!

Dronesizer pt 1

Excellent news everyone. I’ve begun working on my Drone Synthesizer. I decided to use an Arduino for the generation of audio, and a simple Digital to Audio Converter in the form of a resistor ladder.  I have one of these at home and code that sends very basic waveforms to speaker out since this summer. Me and Puterman was starting to make an Arduino demo for Compusphere (a demo scene event) I made all the hardware for TV-out and sound out, but that was as far as we got. Good for now tough. I had it all done so I could start the coding. Awesome.

I’ve done a large batch of the coding, and it does sound rich and fat with and it takes very low CPU. I had not problem adding 4 voices with my engine, witch was in part inspired by gieskes hard softsynth 2. This here tutorial on make magazine on how to make a resistor ladder for the Arduino is good, not what I used but I could not find that original place I read this summer.

So I now have to think on what I should add to my Dronesizer, I really want distortion, but I can use my distortion-tester for that. Also low-pass band-pass and high-pass filters would be awesome. Perhaps an EQ then 🙂 Maybe a delay or echo just to fatten shit up. I also have to think of how I want to control the Dronesizer. I have at-least 15 parameters to control. Also I want something nicely visual to spicen the stuff up.

So now I’m looking for information on that stuff. Life is great!

Dronesizer

I want a drone-machine. You know something for creating rich drones. and by rich I mean distorted and noisy. http://casperelectronics.com/finished-pieces/drone-lab/drone-lab-v2/ might be one of the nicest sofar, and I think I’ll get me one of these. I just have to sell the Roland SP-404 first.

In the mean-time I’ll design and build one myself. Perhaps that will be good enough for me, although the casperelectronics one has some real nice features I wont be able to do.

So I’m thinking using one Arduino, with a DAC out, a resistor ladder DAC, building on an experiment I did a while ago. With some nice waveforms, and analog pot’s to control the drones. Then maybe I’ll build a few distortions to hook into the audio-path. And perhaps … something more. Now where did I my resistor ladder code.

RAIDing the os x

A friend of mine David, lost all his stuff due to hard rive failures, not one, not two, but three failures over a year. When his second drive failed and all that data was unsaveable I decided to get a proper backup system going. I did not want to loose all my songs, my photos or my source code, not that either of these will save the planet but they are important to me.

So my old way of burning stuff on DVD’s where out of the question, that took to long and besides, with the cheap DVD’s I buy it’s not like I would be able to recreate the data again. So hard-drives then or an internet-based backup then? well, I save some stuff with drop-box (free version)

Then I made a OS X mirrored raid. It’s dead easy, just follow these steps:

  1. Buy 2 identical external disks (I bought 2 1tb USB2.0)
  2. Connect them to your computer
  3. Open Disk Utility
  4. Create a new Mirrored Raid in Disk Utility and drag-drop the two new drives onto it.
  5. Press yes yes OK finish
  6. PROFIT!

This was dead easy, but as it turns out, there are no warning mechanisms in OS X, the best you can do is to use the console to do a diskutil checkRAID to se of they are online. This was not good enough for me so I did a quick versiontracker search and found a program (that I guess just calls that command) and screams,emails shop dialogs when either drives are offline. It’s called RAID Eye and I guess having that is better then having a pink eye 🙂

Now I’m secure, and I wont lose a all my shit, and there is plenty of space for my wife to put her stuff on as well.