Archive for the ‘hacks’ Category

About chess and nuclear reactors: the case for exception handling

Sunday, August 1st, 2010

The world of software development has more than its fair share of topics where people tend to have long religious discussions about the “correct” way to do something. I think this is partly because the field for some reason attracts the kind of person who enjoys a nice bout of verbal fisticuffs, and partly because we spend a lot of time dealing with very abstract topics where the pros and cons of a given choice have more to do with differing philosophies than with objective facts.

One classic topic for this kind of discussion, which came up recently at work, is the use of exceptions for error handling. Every modern programming language offers an exception mechanism for this purpose, and presumably it is there to be used. However, ever since they were first introduced, there has been a large and vocal subset of the community arguing that exceptions do more harm than good and you’ll be writing better code if you just use good old return values to report whether a method succeeded.

One representative example comes from Joel Spolsky, one of my favorite authors. Another oft-quoted article making the same arguments is found in the “Frequently Questioned Answers” by Yossi Kreinin. They both make the same basic points: exceptions do not reduce complexity but merely hide it, and when complexity is hidden people tend to forget about it.

These arguments have merit, but I still feel that (when properly used) exception handling delivers enough value to be worth the cost. So I am going to be arguing for the status quo here, for a change. Executive summary: the dangers of exceptions are real, but code readability trumps almost everything.
(more…)

Scripting Excel: can it really be this horrible?

Sunday, December 27th, 2009

OK, I have managed to avoid this for a long time, but I guess it was inevitable: here comes Martin’s cheap, nonconstructively sarcastic I-hate-Microsoft post.

So I was visiting my parents this week-end, and my Dad asked me to help him with a little macro job on an Excel spreadsheet. It sounded simple enough. However, I had forgotten just how astonishingly horrible Visual Basic For Applications, the sorry excuse for a programming language built into Excel (and the other Office applications), can be.

As far as I remember, the last time I did anything with VBA was probably somewhere in the late nineties. Even by the standards of back then, VBA is a really shitty programming language. By the standards of 2009, it’s spectacularly bad. The only explanation I can think of is that somewhere high up in Microsoft Strategic Command, somebody decided to spend a lot of effort on making it as useless and infuriating as possible, while still keeping it just barely functional enough to be able to do the things you want to do with it, if you’re willing to go through a lot of pain. God only knows why they made that decision, but surely a language as bad as this cannot be created by accident.
(more…)

Golfing with prime factors

Sunday, June 14th, 2009

Dirk-Jan reminded me of the Perl Golf and Code Golf contests, both of which have the aim of solving a simple programming task in as few characters of source code as possible. See his post for a stunning example.

One of the open challenges is to work out the prime factors of a given number. To make things a little more difficult, the output must be printed in a specific format:

7000: 2^3 5^3 7
123456789: 3^2 3607 3803

(more…)

Obfuscate your numbers!

Sunday, June 7th, 2009

Time for some silliness.

In a little over a month, I will be

years old.

What’s that, you didn’t get it? Here, I’ll repeat it for you in terms you may understand more easily:

At work, it has become a bit of a tradition that when people announce their birthday, they do so in an at least somewhat obfuscated format. Hexadecimal, binary and more obscure number formats are always popular, of course, as are silly descriptions of the form “my age is the ninth distinct biprime“. But last year I decided to take it to the next level, and write a little generator in Ruby for expressions such as the ones you see above. As you can probably guess, the expressions are generated using TeX.

You can play with it for yourself, if you want to, and also download the latest version of the code. But please be gentle with my server, as you can probably guess it’s a rather heavy application and I’m running this site on a little home PC..

Thinking in bits

Sunday, November 16th, 2008

The number 65,536 is an awkward figure to everyone except a hacker, who recognizes it more readily than his own mother’s date of birth
Snow Crash, Neil Stephenson

A question which I like to use when interviewing C++ programmers: what is the range of a 32-bit integer?

I don’t use this question very often anymore, or at least I don’t let it influence my decision very much (which is why I don’t mind spilling the beans here), because the correlation with other technical skills turns out to be not as strong as I thought it would be. Still, there are some interesting patterns in the kind of people who know the answer versus those who do not.

Among the people who do not know the answer, some of them react quite affronted that they would even be expected to. What is the point, they will ask, in having memorized some little piece of trivia which they could Google up in a few seconds? Isn’t “knowing where to find it” a much more useful skill? Ask me about architecture! Ask me about design patterns and data structures! All of these objections have some validity, and indeed we will certainly ask about those other things during the interview. Still, I believe that it is perfectly reasonable to expect a good developer to know the answer to the above question by heart.
(more…)

Getting VOIP plus IP forwarding to work on the Speedtouch

Sunday, June 22nd, 2008

With my subscription to XS4ALL, I received a Thomson Speedtouch 716 ADSL/Wifi router, currently running software release 6.1.9.6. Behind that router, I have a Linux server which serves as the webserver for the blog you’re reading right now, as well as my mailserver and a few other things. The Linux server also acts as a firewall for the rest of my network:

As you can see, the ADSL router and anything connected to it through the WiFi is considered untrusted: the real access point to my internal network is the Linux machine.

Among other things, the Speedtouch has the ability to support Voice-Over-IP by attaching an analog phone. Unfortunately, this functionality does not work in combination with the “assign public IP to a machine on the local network” setting. Which is a pity, because behind the router is my Linux server, running a web- and mailserver among other things, and I really want that server to have my public IP address. Partly because having the server NATted could cause problems with mail, in particular, in the sense that when I send out mail to another server, some suspicious spamblocker software may take offense if the address reported in the headers of my outgoing mail does not match my actual IP. But mostly because having a web/mail/FTP/whatever server hidden behind a NAT, just feels wrong.

(more…)

Firewall improvements from R. Scott Smith

Sunday, March 25th, 2007

In response to my article about using the recent IPTables module to fight brute-force password attacks, based on an idea from Andrew Pollock, a reader worked out the idea into a complete firewall script, with configurable whitelisting, the ability to block multiple ports, and several other enhancements. Read his post for the details.

You can download his firewall script here. You can contact the author at the address meetscott at the domain netscape.net.

IPTables against SSH dictionary attacks

Sunday, January 14th, 2007

Like everybody who has a Linux server running an SSH daemon connected to the Internet, I regularly get attacked by people (well, botnets probably) trying to do a brute-force attack against the server. Such attempts can take many hours, during which they simply try many thousands of possible username/password combinations.

As long as you have your SSH server configured properly, the most important thing being to only allow SSH access to accounts which actually need it, this is more an annoyance than a problem. Nonetheless, it is an annoyance, if only because of all the crap in your logfiles.

There are many ways to detect and block such attacks. sshdfilter works well, and a good detailed overview of the various options can be found here. One that particularly appealed to me, however, was a very simple netfilter-based technique consisting of only two lines of iptables code. It uses the recent netfilter extension, and the idea of using it to combat SSH attacks was apparently first conceived by Andrew Pollock.

(more…)