October 2008 Archives

2008-10-30

Mailfilter

Ever tried to do something advanced with procmail? I did. Enough pain to sit down and find something better.

So fire, who is a friend of mine, and I came together one afternoon to write Mailfilter. This enables you to do your mail filtering with Python.

I really like the result. Check out this few lines which automatically result in one folder for each mailinglist I am subscribed at.

@filter("List-Id", "(.*)$")
@filter("List-Post", "<mailto:(.+)>")
@filter("List-Id", "[^<]*<([^>]+)>")
def mailinglists(mo):
    return "ml." + esc(mo.group(1))

@filter("Mailing-List", "contact (.*)-help@(.*); run by ezmlm")
def ezmlm(mo):
    return "ml.%s-%s" %(esc(mo.group(1)), esc(mo.group(2)))

Posted by Alexander Bernauer | Permanent Link | Categories: Publikationen

2008-10-25

secrets

Only the small secrets need to be protected. The big ones are kept secret by public incredulty.
Marshall McLuhan

Posted by Alexander Bernauer | Permanent Link | Categories: Zitate

2008-10-25

economy

Anyone who believes exponential growth can go on forever in a finite world is either a madman or an economist.
Kenneth E. Boulding

Posted by Alexander Bernauer | Permanent Link | Categories: Zitate

2008-10-25

const or not const

From the C++ FAQ:

const identifiers are often better than #define because:
  • they obey the language's scoping rules
  • you can see them in the debugger
  • you can take their address if you need to
  • you can pass them by const-reference if you need to
  • they don't create new "keywords" in your program.
[...] There are cases where #define is needed, but you should generally avoid it when you have the choice.

Nice said, and everybody believes it. Util you realize that these "const identifiers" in real are "const variables" which is an oxymoron. Already the fact that const variables have an address shows that they are no identifiers.

"Distinction without difference.", you think? Well, then look at this example:


const double FACTOR = 0.75;
const unsigned HEIGHT = unsigned(FACTOR * 5);
unsigned char a[HEIGHT];

which let's the compiler dump the following error
error: array bound is not an integer constant
Ah, yes, an unsigned const variable is no integer constant, right.... wtf?

As far as I understood the standard the compiler does not have to calculate the value of HEIGHT at compiletime. This is allowed because const identifiers are nothing but read only variables. So this simple example already is a case where you have no other choice but use the good old C style:


#define FACTOR 0.75
#define HEIGHT unsigned(FACTOR * 5)
unsigned a[HEIGHT]; // unsigned a[unsigned(FACTOR * 5)]

This example compiles. The C++ compiler is now forced to do the calculation at compile time.

Posted by Alexander Bernauer | Permanent Link | Categories: C++

2008-10-05

Who said C++ was unintuitive!?


Posted by Alexander Bernauer | Permanent Link | Categories: C++