tapetransfer

Even though my good tape decks are broken at the moment I have started on the software to transfer my techno and house mix tapes to the computer. I have written the software before in C++. It basically waits for a sound on the input and then writes the music to a file until it notices a long quiet section at the end of the tape and stops writing. The software was using threads and used the lame lib to do on the fly mp3 encoding, to make it even quicker to digitize tape. It also notified the user of any buffer underflows and clipped samples. This software is more than five years old now and all the libraries have changed and I can’t be bothered to fix it all. As I want to learn python anyway I decided to rewrite it in python and see how good I can make it. Documentation for the (multiple) alsa bindings for python is pretty bad, so I googled around and found kissrec , which is a very simple command line audio recorder with a timer and VU meter. It is GPL, so I have started with that, but I probably rewrite the whole thing to make it (in my eyes) nicer code. You can find the whole thing at http://tapetransfer.googlecode.com/ , but please don’t look to closely - it is rather ugly at the moment.

October 31, 2008 · 2 min · Christof Damian

comparing class syntax in C++, Java, PHP, Perl and Python

As I recently started learning Python one of the things I noticed which I didn’t like is the class syntax. So I wrote some minimal hello world programs in the languages I recently used to show the difference: C++ hello.cc#include class Hello { private: char value; public: Hello(char newvalue) { value = newvalue; } public: void hello() { std::cout « this->value; } }; int main() { Hello hello(“hello\n"); hello.hello(); } I like the C++ syntax, it is the language which introduced me to OOP and it it clearly states what bits are what without too wordy syntax. Java: hello.java class Hello { private String value; public Hello (String newvalue) { this.value = newvalue; } public void hello(){ System.out.println(this.value); } } class main { public static void main(String args[]){ Hello hello = new Hello (“hello”); hello.hello (); } } Also very nice, a bit clearer than C++. PHP: hello.php «/span>?php class Hello { private $value; function __construct($newvalue) { $this->value = $newvalue; } function hello() { echo $this->value; } } $hello = new Hello(“hello\n"); $hello->hello(); From the dynamic languages this one is the clearest. Except of the __construct() constructor, where I prefer the ClassName() syntax (which still works in PHP5) Perl: hello.pl package Hello; sub new { my ($class,$newvalue) = @_; bless { newvalue => $newvalue }, $class; } sub hello { my $this = shift; print $this->{newvalue}; } package main; $main::hello = new Hello(“hello\n"); $main::hello->hello(); I always hated objects (and functions) in Perl, there is no parameter syntax for functions or methods. Most of it is not enforced and you can use functions in objects in thousands different ways. Python: hello.py class Hello: _value = ”" def init(self,newvalue): self._value = newvalue def hello(self): print self._value; hello = Hello(“hello”) hello.hello() A lot clearer than Perl, but also a lot of convention instead of forced syntax. I got used to the indention by now. But I hate that I have to specify “self” as the first parameters, the init syntax and the underscore prefixing of private or protected variables. At least it has proper function parameters.

September 29, 2008 · 2 min · Christof Damian