Ramblings of Narc

When the issue isn't confused enough.

Archive for January, 2009

From Alex_Boly: Common Sense in Programming

I was just reading a post from Alex_Boly’s blog, and found this brilliant explanation of what programming common sense actually is:

[Common] sense is a very elusive concept. How do you express it, how do you explain it to those people violating it in such an unimaginable manner? How can they learn it, use it, teach others? How did you get into its possession?

Hard questions, with no answer. Until now, when I have finally developed a theory of common sense. It may be proven right or wrong, but at least it’s a theory that is, I believe, worth exploring.

My theory can be summarized as following:

  1. We start learning programming because we are attracted by it
  2. We continue to learn and read more and more because it’s more and more interesting
  3. The knowledge pieces we gather connect to each other
  4. The connections solidify in patterns
  5. The patterns become the second nature and the common sense is born

You can read the rest of Alex_Boly’s theory on common sense at his blog. It’s very much worth it.

WordPress RSS and Atom = WTF?

Okay, so, if you’re a subscriber to this blog’s RSS feed, I apologize from the bottom of my heart. Having taken the time to subscribe and read that feed, I have come to the conclusion that it is absolute, unfettered crap. It’s severely incomplete, obviously generated automatically, and ends up cutting a HUGE amount of the original post off, in spite of the fact that I specifically asked WordPress to include the complete article in its generated feeds!

Unfortunately, there didn’t seem to be any solution (other than, probably, getting a plugin to do the right thing instead). Until I looked closer…

Compare this:

Fig. 1: Ramblings of Narc RSS feed sample

To this:

Fig. 2: Ramblings of Narc Atom feed sample

That’s right, the atom feed is much, much better. Like, infinitely better. So much better, in fact, that it’s now the only feed I’m advertising for this blog. If there is demand, I will probably throw the Atom feed through FeedBurner and point people to that, but until then, the Atom feed, which rocks immensely, is king.

A:Visited (or, channeling Jakob Nielsen)

I posted a “dent” (God, is that a silly name or what?) recently on identi.ca about how I hate not being able to tell visited links from fresh ones. And then I had a look at this blog and realized it had the exact problem I was ranting about.

The reason for this is that I got this theme from elsewhere, and never really cared enough to look at it very closely.

But, if there’s anything that can get me out of my usual lazy stupor, it’s being (or being called) a hypocrite, so I’ve set out to fix my most obvious failing.

So I’ve added a:visited CSS selectors to all the important places I could find here, on the Ramblings of Narc, and the final result is reasonable, as far as I’m concerned.

As a result, I can now whine all I want about websites that don’t make any obvious visual distinction between visited and unvisited links. But wait, there’s more — I also have a (decent) solution, in the form of a bookmarklet I picked up a long while ago called “zap”. To use it for yourself, all you need to do is drag and drop Zap to your bookmarks toolbar. You can even click it for a live preview.

Oh, the wonders of Javascript bookmarks :)

Update: Oops, the wonders of Javascript bookmarks, indeed. Somewhere along the way I think WordPress probably mangled it. That’s what I get for not testing carefully enough. Use this link to get to it, instead.

Acronym Soup

Here’s one that should be entertaining — a listing of all the acronyms I come across on a daily basis, along with my opinion (or other tidbits) on them:

  • PHP — originally “Personal Home Page”, now the recursive acronym: “PHP: Hypertext Pre-processor”. Not too painful to use, given the alternatives.
  • PERL — “Practical Extraction and Report Language”. AcronymFinder also lists “Pathologically Eclectic Rubbish Lister”, which is reasonably accurate, from my experience with it.
  • SQL — “Structured Query Language”. Not “Standard”. Unfortunately.
  • SSH — “Secure SHell”. Uses SSL (see below). Very solid and reliable, in my experience.
  • SSL — “Secure Sockets Layer”. A technology for implementing mostly-transparent secure data transfer.
  • HTTP — “HyperText Transfer Protocol”. Stateless, Simple, and Stupid. Also, very useful.
  • HTTPS — either “HTTP, Secure”, or “HTTP over SSL” (which, IMO, should be HTTP/SSL), depending on who you believe. See also HTTP, SSL (above).
  • SFTP — “Secure File Transfer Protocol” (not to be confused with FTPS, which is actually FTP/SSL, and doesn’t have much traction in the real world), a service provided by (Open)SSH servers in addition to the shell service.
  • AIM — “AOL Instant Messenger”. Crappy software, but with a third-party client like Pidgin is actually reasonable. See also AOL (below).
  • AOL — “America OnLine”. Shitty company, well known for being asshole-ish towards its customers (known internally as “members”).
  • Y!M — “Yahoo! Messenger”. Semi-crappy messenger service. Reasonably functional, though, and quite stable.
  • GTalk — “Google Talk”. Another messenger service, this one built on Jabber/XMPP (see below) and made by Google, the “Don’t be evil” company. Not too evil.
  • XMPP — “eXtensible Messaging and Presence Protocol”. An open standard for exchanging (instant) messages over an XML-like protocol. Speaking of which:
  • XML — “eXtensible Markup Language”. I just love these X-acronyms, they always make me feel like I’m living in the future.
  • IRC — “Internet Relay Chat”. Yes, people still use it. Some pretty awesome people, in some cases, as it turns out.
  • APT — “Advanced Packaging Tool”. So far, the best package management tool I’ve seen. However, my experience is limited, so a grain of salt is recommended.
  • PTS — “Pseudo-Terminal Slave”. What your SSH session spawns into: a terminal with no associated hardware (virtual or otherwise).

There are probably more I’ve missed, but these will do for the time being. How about you? What are the interesting/important acronyms that you work with every day?

Pimpin’ the Desktop

First off, apologies for the graphics-intensive post, but the subject matter demands it. :)

I’ve seen various pictures of desktops on the Internet, and they usually tend to be cluttered with a bunch of icons, sometimes clustered in such a way as to suggest organization, sometimes not so much.

What I haven’t really seen (well, I haven’t looked very much, either) is what I have:

Presenting… the icon-less desktop!

I assume that makes you think I use the start menu a lot? Far from it, my friend. I happen to consider the Start Menu “no man’s land”, for “those few brave souls who’ve dared to enter it… have never come back”. Instead, what I have is…

The auto-hiding Quick Launch (and more) toolbar. The icons up there are the tools I tend to use the most, though not in that order (or any order, really). The very important ones (for work) are Cygwin (for starting vpnc), PuTTY, and WinSCP. There’s also a Komodo Edit icon, but I don’t really use it — it’s my default editor, anyway, so who needs the extra link?

Because it’s the Quick Launch bar, most installers ask if I want an icon there, so it gets mostly the same type of mileage as the Desktop would. But wait, what’s that over to the right? Could it be…?

That’s right, it’s the Desktop. Now cleanly organized in menu/drawer-like fashion, it still has all those other links I might need once in a while (like, a My Computer to right-click), and can also be used to drag the icons from those applications whose installers don’t ask if you want an icon on the QuickLaunch bar.

There’s one minor problem, though — with this setup, the Recycle Bin tends to try to open automatically if you hover your mouse over it. And if it’s full of a whole lot of stuff, that’ll take a while. Plus, you don’t really see it, do you? Thus, that “Special” folder, er, “on” the Desktop.

It’s the source of a toolbar that sits right next to the Start button (didn’t notice it, did ya?) that contains only a shortcut to the Recycle Bin. So you can see it when it’s full, and can right-click, Empty away.

There’s also a pretty direct mapping between the Games folder and the Games toolbar/menu, but I suspect that’s obvious.

What I love about this is the fact that there are no desktop icons. I rarely see the desktop, anyway (outside of the times when I’m taking screenshots of it, of course), so it’s useless to keep anything there. And the background picture doesn’t get all cluttered up, either. What do you think?

ShittyCodeException

I’ve just had the immense pleasure of reading a bunch of code written by someone who is, or should be, a non-programmer.

Among other things, this piece of code (written in PHP) tends to take very roundabout routes to get where it’s going, its functions are mixed up with program logic (including such things as if(condition) function something() {};, which hurts my brain just thinking about it), and calls a Perl script to do something that’s eminently simple to do in PHP — querying a URL.

Thanks to an unattributed image found on Jeff Atwood’s blog, I can now express what the person writing this code should have been seeing as he wrote it:

Because that’s what was happening in my brain as I was reading it.

Now, I can appreciate code reuse, and the fact that the Perl script this one is calling is written mostly by myself gives me a nice ego-boost, but I’m questioning the validity of the current approach.

Firstly, what’s the point of having someone who is so obviously not a programmer write a bunch of code when I and my co-workers are generally available throughout the entire Toronto workday?

Secondly, does anyone doubt that this piece of code will end up having to be supported by us, the same people who should’ve been asked to write it in the first place? As evidence of this, I present the fact that I was the one asked to “fix it”. All I know is, at some point, I’m going to end up having to do some more in-depth maintenance on this code, and I’ll end up rewriting the whole thing, top to bottom. It’s just that bad.

And don’t even get me started on the excess trailing whitespace I just removed by saving the file. Or the shitty indentation that’s sometimes done with spaces, and other times with Tab. And even when done with spaces, it’s inconsistent between two spaces, three spaces and four.

I just noticed another thing: it calls mysql_free_result() at the very end of the application. How clever! It’s as if the “programmer” didn’t realize it would be done automatically the moment the script ended execution.

I’m also curious if the person who wrote this, ostensibly someone with the username “tony”, can even speak English. The reason I’m asking is this comment here: “Retrive Form Value and Assosate Vlaue for Xsell ID”.

Fun stuff, isn’t it?

Why This Hatred For The Shift Key?

You’ve probably seen it — heck, you’ve probably done it yourself, many times. Almost everywhere you go online, if comments are available, or if there’s any kind of open forum, you will see these posts:

this is my opinion: i think [X] should be [Y], [Z]

Now, I’m very specifically not trying to draw attention to the content of the post, because some number of them are very decent, and the rest are mostly ignorable. No, what I’m specifically looking at is the writer’s apparent hatred for the Shift key on his keyboard. With the exception of the [X], [Y] and [Z] I used as placeholders, that post has no uppercase characters whatsoever.

So, my question is, why? Usually, the answer I get is “its extra effort to use the shit^Hft key, and im too lazy”. I don’t buy that. I’m possibly the laziest person I know, and to me, it’s harder not to use the Shift key. It actually takes more mental effort to write like that than it does to write with proper capitalization, punctuation, and spelling (typos notwithstanding). And I’m sure my readers (all two of you) appreciate it.

So why do we see so little capitalization? What is the hatred for the Shift key? Are we moving towards an e. e. cummings-style Internet, where the Shift key is banned, or limited only to articles on media websites like CNN.com? Same for the apostrophe, and (in extreme cases), the period. What’s going on here?

…And we’re back up

The toughest parts proved to be:

  • Finding an optical drive that worked (I found one… from 1998 (!))
  • Getting everything (postfix, apache, mysql) migrated

Total downtime was about six hours or so. The final result is excellent.

Now if you’ll excuse me, I need to get some sleep :)

Update: Wait one goddamned minute, I just noticed my permalinks aren’t! Valid, that is — they 404. Bah, I have to fix this…

Update to the update: Yeah, that worked. mod_rewrite wasn’t enabled. Oops. Wonder what other modules I’m missing.

OK, Down We Go… [pre-planned downtime]

As announced, I’m starting the setup for some downtime, with intent to switch my mail/web server to Ubuntu Server edition. It will still take some time to get everything set up (backups in place, etc), so this post should reach RSS readers (including the Google Feedreader), but at some point there will be downtime. If all goes well, it shouldn’t take too long. Wish me luck! :)

Whitespace, Indentation, And All That Other Fun Stuff

I want to comment a bit more on Coding Style, this time as it very much applies to what I like to see and what I don’t.

At one point, I played around with Python, and I remember liking it to some extent. But, surfing around the Web, I keep finding references to one particular feature of Python I don’t like: indentation-based scope. For the longest time, I put this down to mere preference (“it just looks better to me with the curly braces”), but thinking about it now, I realized: I like the curly braces. That is, I find them useful in the task of reading code, mostly because they introduce a bit of vertical mostly-white space, which adds to the scannability of the code.

Incidentally, I dislike Perl‘s “feature” of forcing you to put curly braces around single-line if() { /* code blocks */ }. In my mind, the code block is a part of the if, and there’s no reason to separate it with syntactic garbage. Now, I know Perl also offers the alternative syntax of putting the if part after the single line statement, and not requiring curly braces there, but reading “do(something) if(x is not null)” makes less sense to me than “if(x is not null) do(something)“. I assume that’s because of the peculiarities of the mental model I create in my mind, and like everything else I’m talking about in this article, this is a very specific “feature” of my own brain. Also, I can eventually read the former, too, it just requires an extra bit of mental effort.

What I also can’t stand are the semi-abbreviated code styles that urge you to put blocks’ opening braces on the same line as the if, while, or function definition that starts them. This harks back to my original preference of curly braces as whitespace — I’d rather see:

if(x is not null)
{
    x += 0;
    if(empty(x))
        return;

    do_something_with(x);
}

than something like:

if(x is not null) {
    x += 0;
    if(empty(x)) return;

    do_something_with(x);
}

And let’s not talk about “} else {“. That kind of thing should never have existed.

If you can read PHP, an example of my code is available on narc.ro, and was referenced earlier in this blog, as part of a discussion on recursion.

Finally, my preferred tab width is 4, and I prefer files that have been formatted using TAB (0×09) characters as opposed to multiple SPACE (0×20) characters. That’s because I can then read code written by people who prefer tab widths of 2, 3, or 8, or whatever else, and not care because the formatting will still be consistent. Which is also why I tend to turn on whitespace rendering when I edit, and correct to tab-indented whenever I can do so easily.

So what are your personal preferences, and what makes them work for you?

My Anti-Spam Solution

I rely on a very simple technique for anti-spam — I sign up to new websites using throwaway email addresses (usually, “narc-domain.tld [at] narc.ro”, or something like that), and if an address starts getting spam, I try to notify the interested parties, or, failing that, I blacklist it altogether.

So far, this has been very successful, in that the only spam I ever get tends to come from addresses I posted publicly, like an idiot, on this very website. To address this problem, I’ve set up a very simple contact form to get straight to me instead, and am now blacklisting all three (haha!) addresses I posted publicly in the past.

If you want to help, for whatever reason, I wouldn’t mind being notified about any mailto: links left anywhere on www.narc.ro or its sub-sites. I think I’ve killed them all, but I could very well be wrong. If you actually do this, I’ll buy you a beer the next time I see you. Or your favorite soft drink, if you’re not a drinker ;)

Switching Gears

I’ve detailed before, but not recently, the many computers I have around the house (I should probably post the current situation at some point). These computers have served me very well in the past couple of years, and I’m very proud of all of them (yes, even the 486).

Still, there comes a time when we all must start thinking of software updates. Now, for the single Windows computer left (the only one I want to keep, that is), and for the two Ubuntus, that’s a pretty simple task — updates come automatically, requiring very little interaction to keep them up to date. For the Linux From Scratch computers, however, that’s… a bit more difficult.

One of the LFS computers (named Bast) is my Web server (serving this website, yes), as well as my mail server (for everything @narc.ro). It’s done its job excellently so far, but I’ve been thinking of switching it to an Ubuntu Server edition. Bear in mind, though, that this computer is a 500 MHz Pentium III with 128 MB of RAM — it’s not going to do very much very well. But by keeping it free of a GUI, it’s behaved admirably so far. I suspect it should handle the Ubuntu Server install just fine. And the ease of having the apt package management system will be awesome.

And since stuff doesn’t get done until you sit down and just decide to get stuff done, I’m taking my own advice here and resolving to get this done this weekend.

As a result, this website may be down for a few hours this weekend while I play around with this (especially difficult since it will require plugging a keyboard and monitor into Bast, and babysitting the install; oh, and let’s not forget backing up beforehand). However, ideally, the result will be just as good, performance-wise, while also allowing me to finally move the DNS over from the old Windows Server, which is probably going to end up with an install of FreeNAS. Because I’m cheap and I don’t want to pay for Windows. :)

Lottery Scams and Spelling

Recently, I remembered a joke I’d heard a few times before. Allow me to share it with you, maybe you’ll recognize it:

Johnny was a devoutly religious man — he believed very strongly that God would help him win the lottery, and so, every day for forty years, he prayed to God to help him win the lottery.

Unfortunately, one day Johnny was hit by a bus. He died on the way to the emergency room, and being a good and faithful person, was admitted to Heaven, where he met God for the first time.

“My Lord,” he asked, “do you remember me praying to you all these years for your help winning the lottery?”

“I do,” God replied.

“Why did I never win?” Johnny asked. “Was it a test of my faith?”

“Well, Johnny,” said God, “did you ever consider buying a lottery ticket?”

This joke reminds me of the several lottery scams I’ve received in email over the past few years (the connection is obvious, I’d say). Maybe you’ve received one or two yourself — they tend to be very generic in their greetings (“Dear sir or madam”), tell you you’ve won some sum of money in a lottery (usually the national lottery of a country you don’t live in), and then ask you for personal information (full name, address, telephone number).

Now, clearly these are scams, and the very first sign should be “I never bought a lottery ticket!“. There are further signs, too — like, why don’t they already have your personal details, why aren’t they greeting you by name, and so on. As far as I know, these are another type of advance fee scam, whereby you will be asked for some sums of money needed to “clear” the funds from your winnings; those winnings, you will never see, as they never existed in the first place.

But the actually scary part here is the fact that all of these types of emails that I’ve received have had perfect spelling and grammar (well, excluding typos, of course). Many times (including recently), I’ve seen recommendations to watch out for misspellings and bad grammar as a first indicator of a scam. Assume phishing emails will follow the trend here — phishing is notoriously more difficult for non-technophiles (“regular people”) to detect, so we tend to tell them to look for the first warning sign: spelling and grammar. If we don’t have those for much longer, then we need to start focusing on teaching people how to tell the somewhat more subtle clues instead — like checking the URL — or even just plainly telling them to just assume that if an email asks them for personal information, then it is a phishing scam and should be ignored.

And it extends still further — those websites featuring popup ads offering you “free anti-spyware scanners” that are actually spyware themselves, they’re going to get better spelling and grammar, too. Overall, what we’re seeing here is all those years of telling people to look for these common signs are coming to fruition — the scammers, spammers, and malware authors are listening. And if that isn’t a scary thought, I don’t know what is.

That’s odd…

Now, here’s an odd one for you, courtesy of my friend, Cristian Chilipirea (Dark Hunterj):

#include <stdio.h>

int* holy_crap()
{
	/*static*/ int s;
	printf("%i\n", s);
	return &s;
}

main()
{
	int* x = holy_crap();
	*x = 2;
	holy_crap();
}

So, what are we looking at? Well, if you uncomment the “static”, you get the intended effect — holy_crap(), when called for the first time, (prints “0\n” and) returns the address of its static variable; the value in that address is changed to contain a 2, and then holy_crap() prints out “2\n”. This is as intended, and it is a very silly thing to do, but it works and is legal.

And then, you comment out the static as I’ve done, and… it still works? That’s odd… In theory, at least, the allocation of a non-static local variable can take place absolutely anywhere in memory, so the address read and returned by the first call to holy_crap() could be different from the address checked and returned by the second call. Yet, on my compiler (gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu3)) and on Dark’s, it actually does print “2\n” on the second call to holy_crap().

Granted, gcc does complain: “warning: function returns address of local variable”, but it still works, for whatever reason.

And it gets better! Check this out:

#include <stdio.h>

int * holy_crap()
{
	int s;
	printf("%i\n",s);
	return &s;
}

int huh_what()
{
	int test;
	test = 3;
}

main()
{
	int* x = holy_crap();
	*x = 2;
	huh_what();
	holy_crap();
}

This actually prints “3\n” on the second call to holy_crap()! We could probably reduce this further by removing the initial call to holy_crap() and the assignment of 2 to that pointer, but it doesn’t matter, because this is still some weird shit going on here.

Oh, and, I probably don’t need to tell you this but don’t ever rely on this happening for you! It’s very likely a combination of compiler, OS, and unoptimized compilation. I haven’t tried this in any conditions other than “gcc file.c -o file”, and I definitely do not recommend writing anything like this in any application beyond the most trivial/educational.

Still, any ideas to explain why this happens?

Is (Coding) Style, Substance?

Okay, call me slow, but I’ve only just discovered the post Style Is Substance by Ken Arnold, and I had an epiphany (nor was I the first to have it, as evidenced by the attached comment thread): coding style (i.e. the rules of whitespace, formatting, and whatever) should be IDE-specific.

Wait, let me backtrack a minute first: the post in question specified that a language’s syntax should be standardized in the official language documentation, and that any deviation from it should be flagged as a compiler/interpreter error. Forcibly. With no way to relax the setting.

I’m going to let you digest that for a second.

Ready? Okay, here’s the next interesting part:

In the end, this requires only that editors and IDEs used by coders will let the user type stuff and it will make it look right. This is basically just reformatting on the fly, which many editors already do. We don’t need you to type zero, one or seventeen spaces between an if and its open paren, we just need the editor (assuming K&R C) to put exactly one space there. And getting even this right will be easier if there is only one style to worry about. It’s one of those things that those reformatting or style adapting cycles can go to.

(emphasis mine)

Now my epiphany: if the IDE could do this (and there’s absolutely no reason why it couldn’t), why can’t it also do the reverse, i.e. translate the standard form into something you like? And if everyone’s IDEs did that, it would finally let Billy code in his personal style, old timer Gabe in his, and have the assurance that the result won’t have several formatting styles because there is only one style!

Where does all this break down? Well, there are a few things, such as:

  • whitespace for emphasis — in the comments thread, there is an example of a tic-tac-toe game board expressed as a continuous array, C-style, formatted into “lines” and “columns”, making it infinitely more readable than the equivalent all-on-one-line version.
  • whitespace for emphasis, again — another example was of vertical whitespace (and comments) used as a delimiter for important code, making it stand out.
  • uncheckables are given in the article — namely, Hungarian notation, and {get,set} method prefixes.
  • IDE standardization was also put forward as a possible bad idea, but I personally fail to see the issue — it’s not standardization, but rather adding to a common feature set requirement.
  • On that same point, though, I’d like to add in the inability to edit in Notepad, at least, not with ease. Maybe you have two or three IDEs to choose from, but you will have to use an IDE — Notepad just won’t cut it anymore. Not that it really does nowadays, what with the lack of syntax highlighting, but it’s still a valid point.

For some of these, I can envision some creative solutions, such as some (hopefully standard) special comments used as “hints” for extra whitespace or special formatting for display, while still forcing the generated code to adhere to the standard style — but once we do that, we’re back to square one since all the current style problems will get pushed into the comment hints instead. Maybe there’s a midway point there where we could (at least theoretically) have our cake and eat it, too. Maybe not. Any ideas?