Friday, November 7, 2008

Destructive String Operations Suck

Some of you may know that I started maintaining a 20+ year old assembler sometime in March this year. Sadly enough, most of my time so far has been spent on refactoring. The reason is simple: I often can't fix a bug or add a feature the users want because I run into some impenetrable wall of code that nobody in their right mind could possibly want to grok. :-(

So I bite the bullet for everybody else, try to understand the code without going nuts, and then rewrite it at least somewhat more cleanly. Drudgery for sure, but not without merit since I keep learning quite a few things in the process. Yes, I still learn new things about programming! Nobody is ever really done learning this stuff, even when you teach it year-in and year-out.

In my recent refactoring travels, I have finally recognized The One Big Truth about string operations: They should never be destructive. Not ever!

Case in point, I had a cute little function char *strlower(char*) that converted a string to lower case destructively, mostly because it's simpler to write the code that way. Of course, as I started putting more and more const into the code as part of my refactoring, I kept having to work around this function in various ways. Today it finally got too annoying, so the function lives no more. 8-)

The new function is size_t strlower(char *dst, const char *src, size_t size) instead, somewhat obviously inspired by strlcpy and strlcat of BSD fame. Granted, the rest of the code is now full of local buffers, but that's better than having to contort myself around a destructive string operation.

Of course, now that I've made the changes and written this blog entry, I have the weird feeling that this is going to bite my again later. Nothing like making a really embarrassing mistake to learn something about programming, eh? :-)

Update 2011/10/09: Sad but true: I've not been able to keep up my maintenance work as well as I would have liked. Also, I've learned something more important in the meantime: You better decide between maintaining messy code and rewriting messy code when you embark on a project like this. Today, if I were to go back to this project, I'd run two concurrent branches in a git repository: One with fixes to the old code, and one with conservative refactorings that don't change the deep structure of the product. Oh well, live and learn.

Monday, October 27, 2008

Gaming Lab File Server

So I spent a few hours at school on Saturday to assemble the file server for the Johns Hopkins Gaming Lab. It's the first piece of hardware for the lab, and while it won't be impressive to some of the real geeks out there, it sure was lots of fun for me to spec out and (almost) build. I still have to actually put the motherboard in and test it tomorrow, but I hope that won't really be a problem. Here are some shots of the whole thing, first the case with the power supply and the six 640 GB SATA drives mounted:

File Server Case-Drives-Power

(Yes, there's also a DVD writer at the top, who cares... :-)) A shot from the front, showing the cooling fans for those drives in their little fold-out cages:

File Server Drive-Cooling-Fans

And finally the assembled motherboard waiting to be popped into the case and wired up tomorrow:

File Server Motherboard-CPU-RAM

This thing will have 2.5 TB capacity as a RAID-6 array, and the only thing that could stop it from being really cool is one of the SATA drives freaking out. Sad fact: The more drives you have, the more likely a failure becomes. :-( Wish me luck! :-)

Update 2008/11/06: I finished assembling the server a few days after the original post, and until 2008/11/04 I was still trying to get it to run using a huge variety of operating systems. I mean I tried everything short of Windoze and Plan 9, but nothing worked right for my setup. Now I finally settled on something that does work: OpenBSD!

Once again, about 10 years after I established the infamous nil.ics.uci.edu server using OpenBSD, I am using this conservative piece of secure low-tech-ness. And I am loving it! :-)

I had really started to hate on Theo a while ago when all the childish craziness between him and the bcm43xx guys went down. I sort of "swore" never to touch OpenBSD again because of it. But now I have to admit: Theo, you are sitting on one hell of a stable OS there. I still don't like what you pulled off with the Linux driver guys, but I can admit when I make a mistake: Regardless of your behavior, OpenBSD still rocks! :-)

The only two things you guys desperately need is a better software raid solution and something like LVM, I miss those things sorely. :-( Yeah, I am stuck running RAID-10 now, no RAID-6 in sight, and static partitions all over. Oh well, at least it works. :-)

Update 2009/04/17: Actually, I take that back. OpenBSD does suck! What happened was that I tried to install a web application that needed PHP, and in the process OpenBSD hosed itself so much that it wouldn't boot anymore. Yes, I used the standard OpenBSD package system, I did nothing directly with the install. Wow. So I ended up putting Gentoo on it right before the semester started. That was a little hectic, but the server has been up for a while now:

gaming ~ $ uptime
17:41:41 up 72 days, 5:23, 1 user, load average: 0.00, 0.00, 0.00


I have RAID-1 with spares for the boot, root, and swap paritions, and RAID-6 for the rest. LVM2 makes sure that I can resize the various pieces of that RAID-6 to whatever the students need. Another Gentoo success! :-) Seems like my BSD days are numbered... :-(

Update 2009/09/08: I rebooted for the first time in a long while, and almost everything worked on reboot (I was afraid it may not). Before the reboot, I had this:

phf@gaming ~ $ uptime
12:25:32 up 216 days, 6 min, 2 users, load average: 0.00, 0.00, 0.00
phf@gaming ~ $ date
Tue Sep 8 12:25:33 EDT 2009


Pretty impressive. No complaints ever from students about the performance of the thing either. So yeah... Gentoo FTW. :-D

Update 2011/10/09: Sorry for the broken images, I am not sure I can recover those anytime soon. But the same setup is still running perfectly! I've had a few disk failures in the meantime but I never lost any data thanks to the RAID-6 setup. One of these days I may want to re-install everything from scratch just because some crud has accumulated in all these years, but it's really not too bad. And the fun thing is: Now I can buy a single disk to backup the whole machine on if I decide to re-install it. At least the human race is making progress in one dimension: the size of cheap SATA disks. :-D

Tuesday, October 14, 2008

The Business of Generals

The Carey Business School just announced its Leaders and Legends lecture series. I'll refrain from commenting on the title itself, what's really interesting is the first speaker they chose: General James E. Cartwright. I assume very few people see anything wrong with this, but of course I do. I'll quote what one of the more honest generals, Smedley Darlington Butler, had to say about the intersection of business and war:

I spent 33 years and four months in active military service and during that period I spent most of my time as a high class muscle man for Big Business, for Wall Street and the bankers. In short, I was a racketeer, a gangster for capitalism. I helped make Mexico and especially Tampico safe for American oil interests in 1914. I helped make Haiti and Cuba a decent place for the National City Bank boys to collect revenues in. I helped in the raping of half a dozen Central American republics for the benefit of Wall Street. I helped purify Nicaragua for the International Banking House of Brown Brothers in 1902-1912. I brought light to the Dominican Republic for the American sugar interests in 1916. I helped make Honduras right for the American fruit companies in 1903. In China in 1927 I helped see to it that Standard Oil went on its way unmolested. Looking back on it, I might have given Al Capone a few hints. The best he could do was to operate his racket in three districts. I operated on three continents.

I am sure "Hoss" would be quick to claim that Smedley was a "pinko commie", or that the "modern" military does not do any such thing anymore. I won't spend $35 to hear his talk only to get thrown out during the Q&A session when I ask something inconvenient. I hope nobody else goes either, and empty hall is probably the easiest way of commenting clearly on the choice of speaker.

Not sure yet? Just try to think through what a general knows about business. He knows that "funding" never runs out. He knows that "employees" will do what they are told or else. And he knows that "laws" can be broken without consequence whenever that is convenient.

Still not sure? Why don't you read Smedley's War is a Racket for some historical perspective and then follow it up with Naomi Klein's Risky Business in Iraq for some more recent examples. I wonder how long it'll take them to invite Naomi to speak... :-)

Friday, September 26, 2008

Got an old iMac!

The nice ACM guys handed me an old iMac today! Thank you so much! :-) So now I can finally add a (permanent) PowerPC machine to my park of weird architectures for the compilers course.

Future students beware: You'll have to write a backend for a *real* machine, and we'll roll dice to determine the architecture you'll have to do it for. So far I have MIPS, SPARC, PowerPC, ARM, and of course x86. I need to find at least one more so I can roll a D6. :-)

I'll try to install NetBSD on it tomorrow, I just have to find a USB mouse somewhere that I can use for a few hours. The harder thing will be to cross-compile NetBSD-current and get it on the box, we'll see how long that'll take.

Update 2008/09/29: They actually handed me another iMac last Friday, I just forgot to post about it. I've not played with the new one yet (actually it's older than the old one, but anyways :-)).

The one I got initially now works fine under NetBSD 4.0, still working on getting NetBSD-current on it. Two problems: First the console driver sucks, so text output to the console is super-slow. Second the screen doesn't blank off, so now I need to find some way of at least moving a textual cube around to save the screen. Also, since the screen doesn't switch off, the thing gets pretty darn hot. Oh well...

Update 2011/10/09: Turns out that I got rid of most of these old PowerPC machines during my recent move from the 3rd floor to the 2nd floor of NEB. In the meantime I had replaced most of my physical machines with virtual ones anyway, so there was really no reason anymore to keep them. Also, I still have some trusty G5 servers, so there's still PowerPC hardware in my new office, just not any of the machines I talked about in this old post.

Monday, September 22, 2008

Why all economists should downgrade to a real job...

I just ran across this /. story and read the linked Stanford article as well. I probably shouldn't have, because now I got myself into all kinds of trouble by writing the authors of that rant the following email:

Dear Professors Mendelson and Lee,

It is nice to see that in times where many people try to free themselves from the clutches of closed-sourced and closed-minded applications, you jump right into the breach and make a wonderful little theoretical case helping out the poor beleaguered millionaires. The fact that "embrace and extend" has been wreaking havoc for decades for engineers all around the globe who just want their standards to be adhered to certainly doesn't matter when yachts are on the chopping block. Oh no, that mustn't happen, can't let the "dumb masses" take over those precious slices of market share. One of these days, pay the computer science departments at your respective schools a visit. Maybe to give a talk on this very subject? They'll help you out with a slightly more educated perspective about what's good for whom. Of course, I doubt that you care.

Warmest regards,
Dr. Peter Froehlich

Only time will tell whether they will mobilize enough support over in the new business school to run me out of here for saying such bad things. If I ever hear back from them in any way, I'll let you know... :-)

Update 2008/09/26: I actually got a reply from Haim Mendelson, sort of predictable but not quite. Here it is in full:

Dear Dr. Froehlich,

We try not to let our social or political beliefs affect our science. If you don't like commercial software firms, don't buy their software, but please don't try to silence researchers who analyze their optimal strategies. In fact, a cold analysis of these strategies may be more helpful to you than ranting.

Best
HM

Maybe you want to let that sink in for a second. I of course totally agree that I sent a ranty email, but the rest of his reply is almost as ludicrous as raising cattle on the moon would be for the next, say, 100 years. In my reply, I properly quoted his pieces and interspersed mine, but that won't work well here so I'll just post it in one fell swoop:

Hi Professor Mendelson,

First, thank you for writing back.

Why did you end up in business school? Why did you write this paper and not one of many other possible papers? Of course your "social and political beliefs" have affected your work, just like they have affected mine. Hiding behind some veneer of objectivity like FOX news may work when you chat with freshmen, but not here.

Your positive position on "embrace and extend" and associated network effects is based on the hope that I won't have that choice anymore, is it not? If I still had it, the commercial vendor couldn't possibly win. Even if I am not a programmer, I can easily find someone to add the feature I need, probably with a quicker turnaround too.

You know very well that I am not silencing anyone. If I was in a position to control what you publish, what your salary will be next year, where you can live based on what your write, then you'd actually have a claim. But I am in no such a position. In fact, I think it's great that someone can actually get paid and make a career based on this kind of research.

I may have couched my email to you in a nasty rant, but the central point that the things you encourage are bad for everybody *except* that one company and it's subsidiaries stands. The prime example for "embrace and extend" is Micro$oft, and if you dig a little you can find out that it has mostly succeeded in making things like the web or collaborative work a lot more difficult for everybody by violating established standards or not publishing specifications for their own. That's why I encouraged you to spend some time with engineering types in your respective computer science departments. Even people who agree with you in terms of "social and political beliefs" will, if they are honest engineers, explain to you what the problems are.

And regarding your "cold" analysis: I don't know too many people who needed to be told what you write about. Did you think it wasn't obvious that big company can outspend a bunch of part-time hackers in the short run?

Let me close with this: I am giving you a hard time about all this because I have a glimmer of hope that you'll follow up and reflect on who really needs your help. I know I may not get anywhere with this, but I had to try. If I upset you with my original email I am sorry about that. In my defense, I wanted to make sure I get a reaction.

All the best,
Peter

I did not receive another reply yet, and I doubt I ever will. He already threw a lot of the "default" academic dirt my way, and while he could follow up with something like "you don't understand economics, you're an engineer after all", or the ever popular "you're just a communist and I have no time for your lunacy," I probably won't hear anything ever again. Good riddance, too. I am just glad he didn't have a substantial defense, otherwise I would have had to spend the time to construct a more comprehensive attack. :-)

Friday, September 12, 2008

What's up with blogs.jhu.edu?

When I first found this site a few weeks ago (yeah, I know! :-)) I thought it's a really cool idea to have blogging easily available for people all around JHU. But apparently I am the only one using this thing right now? Come on, write up some random stuff! Start conversations about something of interest to you at JHU! I am feeling a little too lonely with my silly posts dominating the aggregator!

Wednesday, September 10, 2008

Nothing's ever set in stone...

I started this semester thinking I'd teach 600.490: Software Development for Scientists and Engineers to a bunch of eager graduate students from outside the CS department. Fail! :-( Then I thought I'd teach 600.328: Compilers and Interpreters to a bunch of eager graduate students from inside the CS department. Fail! Again! :-( Now I finally have a third course: I'll teach 600.226: Data Structures to a bunch of eager undergraduates from all over the place. Woohoo! :-)

Seriously, I love that course! And since Joanne Houlahan is handing it to me, she'll stay around to keep tabs on my tendency to give too much homework. So to the students I'll meet tomorrow: Relax! It won't be a "full dose" of Peter-style homeworks this semester. That may well be a good thing, I just might learn how to cut down the workload in my other courses as well. Probably a good idea since I am scheduled to teach 600.107: Introduction to Programming next semester. Wouldn't want to scare too many people off after all. :-)

Tuesday, September 9, 2008

Letter about Greener Johns Hopkins

I sent this "Letter to the Editor" to the Johns Hopkins Magazine after their September 2008 Green Idea special. In case it doesn't see print there, it'll at least be here.

Dear Johns Hopkins Magazine,

I have to admit that I read the repeated claims about JHU becoming greener in your last issue with somewhat mixed feelings. Since July 12, 2008 I have been trying to get someone to switch off a useless air conditioning unit in the Stony Run parking lot, so far (September 5, 2008) without success. This is particularly sad because we have a security person sweating in the summer heat about 100 feet away from the useless unit. Someone needs to either move the unit to the occupied booth, move the security person to the empty booth, or switch off the unit and apologize to the poor guy for not keeping him cool.

Regards,
Dr. Peter Froehlich
Senior Lecturer
Department of Computer Science

So there you have it. I would venture a guess: This is simply a sad example of administrative gridlock. There are too many hands to coordinate, and even more hands trying to do the coordinating. If I could just identify the right person responsible for that booth (which I can't!) I am sure that thing would have been switched off in a matter of days.

Monday, September 8, 2008

Guess what?

I now have a silly blog to do silly things with. We'll see what happens with it, for now I am mostly testing it out.