The writings of Peter Stuifzand

Archive for February 2009

When I am programming I will try things out. When I don't know if or how a feature of a programming language works, the way to find out is just trying it. The nice thing about computers and programming languages is that they won't work or will complain, when something isn't the way they expect it.

For Trying and experimenting to work, you'll need two things: feedback and reasoning skills. I could write here that you also need creativity, but I can't write anything useful about that yet.

Feedback is the way that the computer will tell you that the thing you just did, didn't work. Feedback exists in many forms: log files, error messages, CPU usage, load times, process lists, files and blank screens, all give you some information about your program. Every thing that gives some notion of the state of the working of the program, can help you find out what's going on.

Most of the time, more feedback is better. Of course with more feedback there comes more noise. Knowing where to look for certain kinds of problems will help you find your problem faster. Grepping and tailing can also help a lot when examining logfiles.

For websites there is a extension to Firefox called Firebug, which will let you inspect the HTML, Layout, CSS and DOM tree of you webpage. You can also try out if a part of your website will look better if you change margin or other parts of the CSS file without actually making the change to your websites.

Reasoning skills will help you help compare your model of the program with the actual reality of your program. Having such a model of the program in your head is the most useful thing. By trying and experimenting you will build this model. When your model is not good enough, you reasoning skills will help you find out where a problem is occuring. It is useful to add more feedback. Adding a 'print' statement before, between and after lines of code, will show which lines are executed and which aren't.

This way you can also see what the values of variables are. By comparing the values of the variables with the values that you expect, you can see where your model differs from reality.

Walking trough your code line by line is useful if you want to find out which line makes the output differ from the expected output.

Creativity will help you find new solutions or new theories for the problems you find. That's all I have to say about this.

Trying and experimenting is a safe and useful way to find problems and their solutions.

Question of the day:

Which kinds of feedback do you use while coding?

A few days ago I found out that my camera can make little stopmotion movies. It's really easy, but the quality is really low, only 320x200. My camera can make pictures at a resolution of 2560x1920 and I want to make use of the available pixels. So I start my search for the most amazing way to create a stopmotion movie.

The first method of putting pictures after each other to create a stopmotion movie I remembered was animate, a program bundled with ImageMagick. When I tried to use it on the 2.5MB pictures, it took a lot of time. After I resized the pictures to 800x600 it created the animation in a few seconds. But it was not exactly what I was looking for.

The second way I tried was using ffmpeg. I used the explanation from snippets.dzone.com. But my version of ffmpeg doesn't seem to work really well. I didn't want to create a movie for me.

The third and final way I tried to make a movie was with mencoder. It is part of mplayer.

mencoder mf://*.jpg -mf w=800:h=600:fps=12:type=jpg \
  -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell      \
  -oac copy -o output.avi

This command will create a video called output.avi from the jpegs in the current directory with a fps of 12 and a size of 800x600.

Creating the sound file is not really hard. I created it by recording myself, while watching the movie. I trimmed the soundfile with audacity to make it sync with the video. You can use mencoder to add sound to the video with the following command.

mencoder source.avi -o destination.avi -ovc copy -oac copy -audiofile file.mp3

See here the result:


Dubbelvla from Peter Stuifzand on Vimeo.

View archived entries