16 June 2011
I came across the term “sandwich code” for the first time recently as part of the Ruby Koans Ruby tutorial. It’s not a common term (yet?), but refers to a common resource management problem. Here’s how a lot of people are usually introduced to it:
// Top slice of bread
FILE *f = fopen("file.txt", "r");
// The meat (or other filling, if it's a vegetarian sandwich)
if (f) {
processLinesInFile(f);
}
// Bottom slice of bread
fclose(f);
This is okay. In fact it’s completely correct code, and…
(Continue reading…)
Tags:
Programming languages
26 June 2009
This week’s post contains two short unrelated topics, one interesting and one practical.
For a while now, I’ve been casually following the birth of the Parrot Virtual Machine. Parrot’s goal is to be a general-use virtual machine for dynamic languages, most notably Perl 6 and followed by Python. (Sort of like Microsoft’s Common Language Infrastructure, but more dynamic and open source.) As someone interested in high-level language design, there’s a lot of cool things here…if only I knew enough Perl to write my own front-end. (You can do it in other languages too, including good old lex-yacc /…
(Continue reading…)
Tags:
Programming languages,
Mac OS X
06 May 2009
Apologies to anyone reading. These last few weeks are very busy and I do not have time for a legitimate post. Hopefully things will be more regular later…?
So meanwhile, I present this semi-formal proof that the C++ template system is Turing-complete, shown to me by a friend. This means that, among other things, a C++ program that uses templates can (theoretically) take both infinite time and infinite space to compile!
I am not a C++ fan, though it has a few features I appreciate. But give me a nice OO system, with a solid C-language interface…Objective-C does not…
(Continue reading…)
Tags:
C++,
Programming languages