An Important Message

November 20, 2009


#defines are EVIL

November 17, 2009

The C (and C++) preprocessor is a powerful but dangerous tool. For sure, it helps with a number of problems, from conditional code inclusion to explicit code generation, but it has a few problems. In fact, more than a few. It is evil.

evil(detail)

The C preprocessor (hereafter CPP) should be used with extreme care. For one thing, the CPP doesn’t know about the language it is applied on, it merely proceeds to the translation of the input using very simple rules, and this can leads to tons of hard to detect—and to fix—problems.

Read the rest of this entry »


The Perl 6 Logo

November 13, 2009

GnuVince just showed me the new Perl 6 logo. The butterfly Camelia:

camelia-logo

Clearly, it looks more like a logo for some kind of association for preschoolers or for a day-care center than a logo for a programming language. It’s repulsively cute. Seeying that, I joked with GnuVince that’d I rather have a logo that felt more like the hybrid, duct-taped, patchwork Perl actually is, so I drew the hippocamptopus:

hippocamptopus-handdrawn

My friend systemfault took the drawing of the cussing hippocamptopus and made a O’REILLY parody of it:

perl6-orly

*
* *

Yes, yes, I know, it’s been done before:

perl6book-parody


Is Python Slow?

November 10, 2009

Python is a programming language that I learnt somewhat recently (something like 2, 3 years ago) and that I like very much. It is simple, to the point, and has several functional-like constructs that I am already familiar with. But Python is slow compared to other programming languages. But it was unclear to me just how slow Python was compared to other languages. It just felt slow.

Lewis_chess_queen_

So I have decided to investigate by comparing the implementation of a simple, compute-bound problem, the eight queens puzzle generalized to any board dimensions. This puzzle is most easily solved using, as Dijkstra did, a depth-first backtracking program, using bitmaps to test rapidly whether or not a square is free of attack1. I implemented the same program in C++, Python, and Bash, and got help from friends for the C# and Java versions2. I then compared the resulting speeds.

Read the rest of this entry »


Log Watching

November 3, 2009

Very often, you have to keep an eye on a log, or maybe more than one log, and a couple of other things while a long-term simulation is running. The GNU/Linux distributions offer the program watch that allows the periodical execution of a command in the current interactive shell. While watch is convenient, you still have the problem of displaying the needed information in a terminal geometry aware way. Turns out, there are tools to query the terminal geometry and we can use them to write simple, effective, well displayed scripts.

telescope-small

So let us see how we can make BASH somewhat aware of the terminal it runs in.

Read the rest of this entry »


Of staircases and textbooks

October 27, 2009

This week, I’m talking you about a little identity that crops up often in the study of algorithms and which isn’t found in formula compendia—anyway, none that I have. I’m talking about this function:

\displaystyle C_{n,a}=\sum_{i=1}^n i a^i

This is a variation on the Gabriel’s Staircase function that does not have an infinite number of terms. Let us solve it without supposing that 0<a<1.

Read the rest of this entry »


Code Style: Vertical vs Horizontal?

October 20, 2009

The only difference between coding styles and religion discussions is that coding styles have claimed fewer victims—at least until now. A few post back I discussed color schemes, and this week I’ll be discussing code geometry for enhanced clarity.

fish-on-stilts

Read the rest of this entry »


Cargo Cult Programming (part 1)

October 13, 2009

Programmers aren’t always the very rational beings they please themselves to believe. Very often, we close our eyes and take decisions based on what we think we know, and based on what have been told by more or less reliable sources. Such as, for example, taking red-black trees rather than AVL trees because they are faster, while not being able to quite justify in the details why it must be so. Programming using this kind of decision I call cargo cult programming.

cargo

Originally, I wanted to talk about red-black vs. AVL trees and how they compare, but I’ll rather talk about the STL std::map that is implemented using red-black trees with G++ 4.2, and std::unordered_map, a hash-table based container introduced in TR1.

Read the rest of this entry »


More on ISIEA09 (and on Malaysia)

October 7, 2009

One thing I didn’t notice right away is that the number of female participants (including presenters) at the conference was very high.

In Canada and the U.S., it seems that women are not that interested in the hard sciences like maths, engineering, or computer science. And that’s not because they are kept out of those faculties; quite the contrary: there are numerous incentives and wooing programs; or that they can’t do it: they just don’t care, it seems. Women study more than men (in a 2:1 ratio in universities, at least in Québec) but they do not choose engineering, maths, or computer science; they prefer health and care studies, like medicine, social works, etc.

Here, in Malaysia, there seems to be a large number of women studying in engineering, computer science and maths; at least a great deal more than in Canada. I wonder if we could borrow their strategies to get women to be interested in engineering and sciences or if it is rather the result of a fundamental cultural difference between our two countries. I say I wonder if it’s not cultural because a large percentage of the women (but not all) wore a conspicuous hijab headscarf.

Readers, any ideas/impressions on this?


Nonce and other Frobnulated Words

October 6, 2009

Language is always fun to use to better effect, whether it is to make your point or break your adversary’s point. All natural languages are rich and contain a number of regional, rare or made-up words. French has a number of them and so does English.

oldbooks

Rare, nonce, or simply made-up words show up in comedy, literature, and even programming. As I am not a native English speaker (which I am sure you gathered by now by reading this blog) I do often read books about English to better my grasp of the anglo-saxon language. Not all of them too serious.

Read the rest of this entry »