A Site That Celebrates Tortured English

I’ve always been rather sensitive to spelling and grammar. Maybe a little too sensitive. Little errors in written English drive me nuts.

I’ve finally found a place for other people who, like me, shudder at misplaced punctuation, “creative” spelling, abused homonyms, and atrocious grammar: Wordsplosion! “Showcasing the best of the worst of the wide world of words,” its front page also deliberately bears the gastrointestinal-illness-inducing phrase “Tell You’re Friends! [sic].”

I may regret posting this entry. Once GoddessJ reads it, she’ll check out the site, and I’ll be subjected to many (more) hours of distracting laughter as she peruses it in our shared office. πŸ™‚

The Stack Overflow Website

Stack Overflow, the programmer Q&A site that Joel Spolsky (of Joel on Software) and Jeff Atwood (of Coding Horror) have been putting together, finally opened its public beta doors yesterday. I’d been following its development closely through their podcast, and when I came up with an obscure programming problem this morning, I decided to try it out.

In seven minutes I had several replies — including the perfect answer. Wow.

And the site design is pretty damn awesome too. Browsing around it, I stumbled onto an answer for a thorny problem in Project X as well, without even looking for it. Double wow.

All in all, I’m VERY favorably impressed. It immediately earned one of the few coveted places on my Firefox speed-dial screen. I can see already that it could become a huge time-sink, but hey, everybody’s got to have a hobby. πŸ˜‰

Multithreaded Programming

A little while back, I ran across a rant about multithreaded programming on The Register (NSFW due to strong language), which starts out with this paragraph:

I don’t know about you, but every time I have to program with threads and shared resources, I want to remove my face incrementally with a salad fork. Locks, mutexes, the synchronized keyword; all of these things can strike fear into the heart of a green developer. Most seasoned developers just fall into a rut of depression when it’s time for multi-threading. Developers like me simply talk our way out of it. It’s easier than thinking.

I was rather bemused by this, but I figured that some developers probably didn’t like writing multithreaded programs, just as some passionately despise pointers or date calculations.

But a few days ago, I was reading a FAQ page and discovered the comment “Threads are evil. Avoid them.” At this point, I decided I had to speak out.

Multithreaded programming is not that hard to master. There are a few extra things you have to do, and there are a few new problems to watch out for, but if you follow a straightforward set of rules, it’s easily possible to write good — and safe — multithreaded programs.

I can’t offer a complete list of these rules. I learned them the hard way; they’re embedded in the way I write code. But here are a few of them off the top of my head, geared toward C++ code:

  • Know when not to use it. Multithreading is powerful, but so is dynamite — and like dynamite, you have to treat it with respect, or it’ll blow your arm off. Multithreaded programming can be very useful in some cases, but most of the time it’s not called for.

  • Have each thread do a completely separate task. If your program can’t be split up into tasks that can be run mostly independent of one another, don’t even attempt it.

  • Don’t pass automatic variables (by reference or pointer) between threads. Automatic variables (in C and C++, at least) are created on the current thread’s stack; when they go out of scope in that thread, the memory is no longer safe to access in any thread. Passing non-array variables of built-in data types by value is generally safe, but that’s all I can promise.

  • For any variable that uses allocated memory and crosses threads, use reference-counting, with automatic cleanup in its destructor. You don’t know when it’s safe to delete such a variable. The Boost library’s shared_ptr, or something similar, is the way to go for that kind of thing.

  • Whenever possible, use a specific resources (file, block of memory, whatever) in one thread only. Try to avoid having two or more threads operating on the same block of data or the same file simultaneously. If you have to share a resource between threads, create a thread-safe interface for it — a C++ class that encapsulates it, for example. Then you can control all access to it, and use critical section or mutexes to prevent threads from trying to use it simultaneously.

  • Be careful with libraries. There are a lot of useful code libraries out there that can’t safely be used by multiple threads simultaneously. A lot of programmers these days rely heavily on bits of code written by other people. That’s fine — if you know exactly what’s going on in it. If you don’t, and the author doesn’t provide any assurance that it’s thread-safe, then you have to assume that it isn’t.

  • Watch out for cyclical dependencies. If a thread locks a resource, make sure it can’t wait on another resource that might be locked by a different thread that could also be waiting on the first resource — that will lock your program up tighter than Fort Knox. I can’t completely articulate the way I avoid this problem, but it involves knowing exactly what each thread in your program is responsible for, and what resources each one uses.

Basically, you just have to know your code and how the different threads might interact. It takes some practice to get it right — and it’s not the kind of thing you want to practice on with a program that other people are going to use — but it’s really not difficult once you get the hang of it.

The Litter Robot

(This is a follow-up to last year’s post on the cat-crap problem. As I said then, if youÒ€ℒre bored or offended by talk of the removal of feline waste products, donÒ€ℒt read this entry any further.)

Our third Littersweep Ultra died a few months ago, worn out the same way as our first one. I’m not completely happy with them anymore, since the newer ones seem to be of an even cheaper quality than the originals. And although our original Littermaid Mega is still working, word around the ‘net is that more recent iterations have lost a lot of the toughness that the original had. So rather than replace the Ultra again, I just went back to scooping it out nightly, an unpleasant but necessary chore.

Necessary, that is, until I discovered a few weeks ago that the Rolls Royce of cat-litter solutions, the Litter Robot, was finally available here. It was expensive, but according to nearly every review I’d seen it’s well worth the price, so I ordered one immediately.

It arrived two weeks ago, on Monday the 25th. I was quite impressed with the workmanship… it’s built like a tank. Between that and the fact that there’s only one part that moves (the gear that rotates the sphere holding the cat litter), it’s easy to see why it holds up so well.

I set it up where the Ultra had been and moved the Ultra across the small hall. I left it turned off at first (as recommended, so that the cats have a chance to get used to it without being startled), but put in cat litter immediately. All three of our furry friends (Oliver, Salem, and Winston) looked it over, but no one ventured close enough to peek inside on the first day. That night, Ollie apparently decided that it was fine and started using it.

With Oliver using it regularly, I had reason to cycle it manually a few times a day. Every time I did, one or two of them would come and watch. Salem was especially fascinated by it, and would sit up on her hind legs like a ferret so that she could see what was going on inside without actually getting near it. By Wednesday evening, some of the novelty seemed to have mostly worn off for them, so I started leaving it on full time.

Winston, scaredy-cat that he is, simply didn’t want to have anything to do with it. He peed on the bathroom door a couple of times before we managed to dissuade him from that, then he went back to using the old box, which I (deliberately) didn’t clean once the new one was in place. By Thursday, it was full enough that he didn’t want to use it either, but still hadn’t worked up the courage to get near the new one. He would complain vociferously when he had to go, but would end up going in the old box. GoddessJ and I tried to gently introduce him to the new one, but he would have nothing to do with it — he wouldn’t fight us, but he would struggle to get away until we let him (apparently he felt safe so long as he was at least eighteen inches away from it). Finally, on Saturday, GoddessJ gently forced him into it. He jumped out again immediately, but a few minutes later decided to climb in on his own and use it.

After using it the first time he immediately bolted out again like it had bitten him, ran downstairs and back, and then swatted it a couple of times. When he didn’t get a reaction to that, he apparently decided that it was safe, and has been using it ever since.

Salem, on the other hand… well, she was a little more stubborn. We saw her in it once on Thursday, but she kept going back to the old one. On Friday, I saw her go into the old box, poke around for a bit (obviously not happy with the housekeeping), look across the hall to the new one, then approach it carefully and swat at it. No reaction, so she cautiously climbed in to do her business before darting out again, not even stopping to try to bury it. From then on she would use it — but only to pee. When she had to poop, she’d go to the old box, vocally complaining all the while (you can see the family resemblance to her brother Winston, I’m sure). When I finally removed the old box on the second Wednesday, she was frantic, and ended up using the bathtub instead. Grumbles, sighs, and appeals to patience, and the next day there was no sign of messes, leading to general happiness on everyone’s part. Premature happiness, because there was another load in the bathtub on Friday. More grumbles and sighs, and placing her in front of the new box whenever she started complaining, and she apparently got the idea at last.

So it seems that the Litter Robot has now been accepted by everyone. I replace the bag in it a couple times a week, and drop in a couple scoops of fresh litter, and otherwise it takes care of everything itself — exactly as an automatic litter box should. Tranquility has been restored to our household.

I’ll post again if anything goes wrong with it, but I don’t foresee any problems from here on, until it dies a natural death from old age. May it have a long and happy life. πŸ™‚

“Flawed” Humans?

I was reading a LifeHacker post on How to (Not) Get Banned from Commenting this morning, when I ran across this section:

Do you ban readers who criticize your posts? Nope. We thrive on constructive criticism. We’re always listening to what you have to say and trying to improve. If you do think something we posted was inaccurate or horrible of us, follow these steps: 1.) Remember that there are real-life, flawed humans behind the words on this site. 2.) Outline, calmly and politely, what you feel the problem is, either in a comment or in an email to tips at lifehacker dot com. We correct inaccuracies the moment we know about them, and we love to hear your opinion, good or bad. However, if your comment is a disrespectful teardown that doesn’t help us learn or make the post better, you’re out.

Completely valid and legitimate — I’ve run a forum myself before, and I made it clear from the beginning that it was run as a benign dictatorship, not a democracy. But something about the “flawed humans” part just rubbed me the wrong way.

The dictionary definition of “flawed” is simply imperfect. That’s fine — “nobody’s perfect” is a truism. But saying that something is flawed, to me, implies that it could have been perfect, and that there are perfect examples out there to compare it to — a flawed diamond, for instance. That generally doesn’t work when applying the term to people. People aren’t perfect, but unless they’re physically or mentally disfigured, they’re not really flawed either.

I’m going to say something heretical: people always do the best they can. Everyone, every time. Not true, you say? Fiddlesticks.

You take a test and get a B. “I could have done better,” you chastise yourself. No you couldn’t. You could have prepared better, but at the time that you took the test, you did the best that you could — unless you deliberately marked some answers wrong, it’s the only thing you could do.

You run a race and come in fourth. “I’ve run faster than that before. I could have done better.” No you couldn’t. Your body may have been capable of running faster, but you are not solely your body — you’re also your brain, your emotional state, your knowledge, your belief systems, how well you’ve eaten and slept recently, and dozens of other factors. They all have different states and cycles, and if any one of them is below optimal, it’s going to affect the entire system.

It’s been said that free will is an illusion. That’s both true and false: you do make choices, and those choices are yours — but could you really have chosen differently, given the circumstances and what you knew at the time? Sure, you can choose whether to have a banana, an orange, or a granola bar in the morning, if all three are readily available. But could you choose to jump over your back fence to beat up a new neighbor who was minding his own business and who you’ve never met before? “Sure I could, if I wanted to,” you think — but you couldn’t want to. Not without some reason, something that seems valid to you at the time, regardless of its actual logic.

Scott Adams (of Dilbert fame) is fond of saying that we humans are simply “moist robots,” programmed by our experiences and genetics. As uncomfortable as it may be for some people to contemplate, there’s a lot of truth to that statement.

I love spam…

One of the (few) spam messages that survived to show up in my junk folder today:

Subject: Hilarious! Could it be true? See inside. Jessica Simpson Breathes Air READ FULL STORY

Um… unless Jessica Simpson is a fish, a methane-breathing alien, or dead, why would that pique my interest? Isn’t that rather like exclaiming “Amazing, Robin Williams wears pants!”?

I know some people go nuts over celebrities and follow their every move, but this would be a bit much even for a stalker. πŸ™‚

Google Chrome: Can the Hype Already!

Everybody and his brother has been nattering on about the newest contender in the Internet browser market, Google Chrome, over the last couple days. ZDNet seems to have wrapped up a lot of the best arguments in two articles: Five reasons Chrome will take over the world, and Five reasons why Chrome will crash and burn.

Since I know you guys are expecting to hear my take on its future, here it is: I’m aggressively neutral on it. πŸ™‚ It sounds like an excellent design, but I don’t know whether it will take over the world, or kill off Microsoft’s browser dominance, or kill off Firefox, or anything else. I only know that I’m not planning to use it for now — it’s still lacking in a lot of areas, especially compared to Firefox’s add-ons.

That said, I’m all in favor of the project itself — competition generally improves products, and Google is perfectly situated to know what a browser really needs. More diversity in the browser field also helps frustrate the bad guys, making it harder for them to steal enough money through any particular security hole to be worth the effort. The fact that they’re making it open-source is a pleasant surprise, since it means people can trust it more (there will be lots of source-code scrutiny to ensure that they don’t do anything underhanded in it), and other browsers can adopt anything that sounds like a good idea.

That’s all I can offer on the subject for now. I’ll take another look at it in a few months and see how it comes along.

“Please Don’t Block Us. (Please?)”

LifeHacker.com ran a poll of their readers last week to determine what their “must-have” Firefox extensions are. Surprise, surprise — AdBlock was at the top of the list. LifeHacker is an ad-supported site, so the title for the post reporting the results is no shock.

(I don’t see any need to block ads, myself — but I do block any and all scripts and plug-ins, including Flash. [I’m easily distracted, so I can’t stand things that move on the screen.] The website owners still get their ad money for text-only ads, and I can tolerate their sites, so as far as I can tell it’s a win-win situation.)

I probably don’t really need to point this out, but if Microsoft were still the only browser game in town, everyone would be forced to see animated ads, everywhere. As evidence: back in the mid-nineties, one of my then-roommates started playing with Internet Explorer when it first came out, and he reported that the back button became far slower between one version and the next. When he dug into it, he discovered that Microsoft had changed its behavior — the earlier version retrieved everything from the local cache when you hit the back button, resulting in an extremely fast and efficient transition. But advertisers had apparently complained that they weren’t getting the additional hits on their ads, so Microsoft changed it to re-retrieve all graphic images when you hit the back button.

When all the competition is essentially free, people are going to go with the alternative that gives them what they want, rather than the one that forces them to take things they don’t want. Is it any wonder that people are switching to Firefox in such large numbers?