Why I don't write 'if (NULL == foo)' in C code
One of the infamous trivial bugs in C code is accidentally writing' = ' instead of ' == ' in conditional expressions; you get assignmentinstead of equality checking. One common piece of advice for avoidingthis is to reverse the order of the check, putting the constant first.This way, if you accidentally write ' NULL = foo ' instead of the == version, you'll get a compile time error.
I can't stand to write this version, because it looks wrong to me.
Weekly spam summary on November 19th, 2005
Once again, I'm leading with Hotmail's stats to highlight their spam problem :
- three email messages accepted.
- 320 messages refused because they came from non-Hotmailemail addresses.
- 22 messages refused because their sender addresses had already hitour spamtraps.
- 21 messages refused due to their originating IP address (17 in theSBL, two in the CBL, one in the XBL, one because it's fromGilat-Satcom).
Gilat-Satcom is a serious problem here; it
Solaris 9 sendmail irritations
Here's how to give a system administrator a heart attack: the defaultSolaris 9 sendmail configuration apparently allows other machines thatyour Solaris machine thinks are in your local domain to relay throughyou. I say 'apparently' because there's nothing in the sendmail.mc aboutthis, and nothing clear in the generated /etc/mail/sendmail.cf either.
In other fun discoveries, the default sendmail configuration is alsoset up to relay all your mail through a machine called 'mailhost' inyour domain
SQL as metaprogramming
I'll start by quoting Glyph Lefkowitz from a recent article (okay, recent for my techblog writing):
Metaprogramming is hard, and dress it up however you like, that'swhat using SQL is. Your code is generating other code, andevaluating its results.
Because metaprogramming is so hard, it is almost exclusively theprovince of frameworks, environments and operating systems. For goodreason, too. Whenever code generates other code, there arepotentially very serious mistakes that can get made. [..
Why Linux threads use up so much memory
If you write a simple threaded program in C on a modern Linux systemand fire it up, you may rapidly notice that you can't have more than acouple hundred threads before you run out of memory. Even if you don't need that many threads, you may discover that your program is using anabsurd amount of (virtual) memory.
(This can also happen in other languages; I know it happens inPython.)
What's eating all the memory is the default NPTL thread stack
How not to do DNS for internal domains
Here's a brief recipe for how not to do DNS for your internal domains,as illustrated by eBay:
- Allow your internal subdomains leak into your externally visiblenameservers, so that when outside people query for 'sjc.ebay.com'they get back NS records instead of 'no such domain'.
- Use RFC 1918 private IP addressesin 10.*.*.* for your internal network, including the DNS serversfor your internal subdomains. Such as sjc.ebay.com.
The scope of the peril of having a highly dynamic web site
In ADynamicSitePeril , I wrote about how dynamically generating variousaspects of this blog means that WanderingThoughts has a lot of Atomfeeds. Since MSN Search's aggressive fetching of several hundred ofthose feeds has been on my mind recently , I thoughtit would help to put some concrete numbers on this.
WanderingThoughts is built on top of a directory hierarchy, where eachentry is a file and categories are subdirectories. Right now (before Ipost this entry), it has 10 directories (nine 'categories' and the
Banning MSNBot: an open letter to MSN Search
I understand that MSN Seach wants to be bigger than Google in search .One necessary step towards this is that people must be willing to letMSNBot, your search spider, index their content. Today, I changed our robots.txt to ban MSNBot, joining various other people , and soyou're a little bit further from your goal. (Probably not enoughfurther that you care very much.)
I'm not doing this because I dislike Microsoft. I'm doing this for asimple reason,
Weekly spam summary on November 12th, 2005
This week I'm leading with Hotmail's numbers, because they continue tobe a depressing testament to Hotmail's spam problem . This week'sHotmail statistics are:
- one email accepted, probably advance fee fraud spam from the Hotmailuser name.
- 14 Hotmail messages refused due to their originating IP addresses (4in the SBL, 4 in the XBL, three from Nigeria, two from SAIX, and onefrom the Cote d'Ivoire).
- 31 Hotmail messages refused because their sender addresses had
Why using local variables is fast in Python
One piece of Python optimization lore is that access to localvariables is very fast, so if you repeatedly refer to something in aloop in a function you can optimize it by copying it to a localvariable first (this often comes up when you are repeatedly calling afunction). This fast access comes about because of some implementationdetails in CPython.
The CPython interpreter doesn't run Python code directly, but firstcompiles it to bytecode for a relatively simple stack-based virtualmachine. You can see the actual