Byzantine Reality

Avatar

Searching for Byzantine failures in the world around us

Articles tagged with 'ranting'

Too Much Stargate

You know you watch too much Stargate when you get ads like this targeted at you:

The weird thing is, I clicked on the link and they don’t even mention a Stargate at all…

Stack Overflow

Quite a bit of buzz on the internets is around a nifty new Q&A site called Stack Overflow. Since you can read all about what it bills itself as and how other people perceive it in other places, I’ll just give you a ‘first impressions’ review of the site.

I’ve been meaning to write about this for quite some time, since I’ve been a member of the site for about a month or so, since back when it was in beta. But I figured there was no point since you, the reader, wouldn’t be able to see it for yourself. Then again, since pretty much all of my site’s traffic right now is from people on Stack Overflow clicking on my web site link in my user profile, maybe that isn’t a valid argument.

So like most of the reviews I’ve seen online, I do like Stack Overflow. It’s free and painless enough to post a question, although this is because I was lucky enough to have an account with a provider that supports OpenID (in this case, WordPress). Others have complained about having problems with Yahoo’s OpenID, so I guess I got lucky on that one. There’s been enough people on it so far that I get a pretty fast answer to every question I’ve had so far, and most of the answers have been dead on.

The site is definitely addictive, as I’ve spent quite a bit of time answering questions in an attempt to raise my reputation (similar to karma) score as much as possible. But since the site has gone public, there’s really too many people to make a huge impact. This was originally a big downer, since I’m still not far enough on my reputation score to have the best moderator-like powers on the site, but I think it’s really for the best. Now I just use the site for what it’s meant for: asking and answering programming questions. Now I just drop a question down and while I’m waiting for an answer, I go off and answer other people’s questions. My reputation grows pretty slowly now (answering questions tends to get much more rep than asking them), but I think this is the preferred usage of the site.

Chances are exceedingly likely that if you’re reading this, you know all about Stack Overflow. But if you’re a programmer with their head in the sand, check it out. If you still need convincing, check out a question I posted and the amazing answer I got back.

Simplicity, Round 2

I originally intended these random ‘Simplicity’ updates to be about things I like in Ruby that are a pain to do in Java. And while that’s certainly the case this time around, this comes from a library perspective rather than the languge itself. Specifically, I’m talking about processing command-line arguments. It’s something you have to do all the time when you write these little scripts that come up but for some reason results in the same boilerplate code being constructed. This is why I’m exceptionally glad that Ruby has many solutions to this problem.

So, just to clarify, this is the problem. The user types in this:

./myprogram --file data.txt --optional-thing true --whatever 100

And I want to be able to make sure they put in certain flags, and that they meet some criteria, and get the data I need out of it. Coming from Java-land, I wasn’t taught anything in particular to do this, and Google really only reveals a useful how-to to write your own. Their solution seems to be the equivalent of writing an interpreter for your command line arguments, and is a bit over-the-top for something this simple.

Ruby, strangely enough, has at least half a dozen different competing libraries that specifically serve the purpose of parsing command-line arguments (two of which are built into the language). The one I chose was the first one that showed up on Google, OptiFlag. It bills itself as a Domain Specific Language for command-line arguments, which still sounds weird to me. However, their implementation is pretty solid. The way the JavaWorld article suggests seems pretty bulky, but with these guys, you download their package, include it in your program, and once you learn how to ‘speak’ their language, you can rip out everything you need in a line or two of code.

The documentation on OptiFlag is amazing too! The simple tutorial and clear pictures make it really easy to pick and grab whatever you need to do what you have to do, and the fact that arguments can be validated via regex is amazing. Not that anything is groundbreaking there, but the fact that you can saves more boilerplate code in the long run.

If you do a lot of little scripts that use the command line, check out OptiFlag, and if you use Ruby and haven’t seen OptiFlag, go check it out. It’s definitely a different take on command-line argument processing.

...And Then Came Ruby

I originally wanted to write a big long post about how I was stuck on the Java train my entire life and now I found Ruby and was in love and all that wonderful crap…but for some reason I got most of that out of my system the last time I complained about it. Therefore, I’ll just stick to some of the highlights and oddities that I’ve run into with Ruby and save all of us the time and grief involved.

Since I’m too scatterbrained to correctly sort this post into a “good” and “bad” section, I’ll just pseudo-randomly throw them out there.

  • Good: Ruby is less verbose than Java. This one isn’t too hard, considering that everyone on the damn planet is less verbose than Java, but Ruby is so much less verbose that it’s a very welcome thing to see.
  • Bad: I was under the original impression that do…while blocks and closures are basically the same thing in Ruby-syntax land, but some mild fiddling has shown that not to be the case and since I’m new to the language, I’m still learning which times get which. For example, if I want to open up a file and output everything in it, I just do this:
foo = open("ExecRuby.rb")
foo
.each { |line|
puts line
}

While learning Ruby, this looks like you could also just do this to the same effect:

foo = open("ExecRuby.rb")
foo
.each do |line|
puts line
end

Yet the first works and the second doesn’t (note that both “compile” fine). Again, this is just new-language-syndrome and I haven’t figured it out yet, but syntactically it feels like these would do the same thing (in fact, the second doesn’t do anything that I can tell). 

EDIT 09/25/08: This seems to be more of a fumbling on my part, as the comments indicate these should be identical.
  • Mostly good: Rails (maybe Ruby, not sure) has an open policy of not being thrilled about backwards compatibility. The argument given in the Agile Development with Rails book pretty much sells it as being against bloat: Do you really want to end up with what JavaBeans and XML looks like now after having to support every crappy choice made down the line? If you made a bad choice, get rid of it! I’m definitely against bloat (hence the possible Ruby conversion in the first place), but there’s the obvious problem: now I’m tied to my specific Ruby/Rails versions. This isn’t terrible, since Rails lets you package in the version of Rails needed to run so you don’t have to worry about manually fetching it, but what about a possible huge security vulnerability? If they only fix it in the newest version, you are pretty much screwed it seems.
  • Interesting: Method_missing has an incredible amount of potential (and likely danger that comes with potential). For those not familiar with it, here’s the executive summary: If you call an object’s method and it doesn’t exist, it gets caught by method_missing, who then can do whatever it feels like with it. Here’s two short little articles that explain it more with examples. The original article that sold me on it is implementing tab-completion for Ruby, which is insanely undoable in Java without the magic of Reflection (and it’s more complicated in Java, just look at how long that article is versus the first article I listed on method_missing).
  • Also interesting: Duck typing. Again, long story short: if I call a method on an object, the object doesn’t need to be of the correct type, it just needs to have the right method. Combine this with the crazy amount of overloading of standard classes you can do (the similarly dangerousmonkeypatching) and some interesting things can come out of it. So far it’s mostly that files, strings, and arrays can all be operated on in very similar manners, possibly cutting back on the DRYness involved.

I’d go on longer but I’m still new to Ruby-land and over the years Java is trying to keep on trucking by adapting little changes to try to catch up (see Java generics or Java closures). Will it be enough? Who the hell knows. But it should prove for an amusing ride at the least.

P.S. The type system seems to get everyone all crazy excited, but this amazing article can help out a bit on the education bit.

First There Was Java...

For the lion’s share of my undergraduate education (80%-90%) we got to program in Java. We did half a semester in C# (close enough), a semester in C, a semester in assembly, and everything else was Java. Although I picked up other languages before I got to undergrad life, Java was the first language that I really learned well, and a lot of how Java does things seeped into my head about how to do things in every other language. It’s not a bad thing, but it made my head spin when I ended up seeing Ruby for sure.

This article has been in the works in my head ever since I read The Perils of JavaSchools, since I went to one. Early on in the article Joel pretty much captures the problem with only teaching Java:

Java is not, generally, a hard enough programming language that it can be used to discriminate between great programmers and mediocre programmers.

This is right on. And that’s not to say Java shouldn’t be taught in schools. But I don’t know if it should be the first language to teach students (I’ll get back to you on that) and it certainly shouldn’t be the only language that students end up really knowing.

We can debate what it means to “really know” a language, but as far as I’m concerned, it’s knowing the language’s standard library. You can easily “program” in a language like Perl even if you don’t know Perl but know another imperative language (e.g., C or Java), but you don’t really know Perl unless you know all those special metacharacters and Perl’s regex syntax and blah blah blah.

I think what I’m trying to get at is that I really wish I got to learn two languages from different paradigms. Something like Java and Lisp, or C and ML, but to a degree where if a problem comes up, I can take the extra five minutes to think about which language solves the problem best, rather than having to do it in Java because I’m just not productive enough in anything else. Part of this problem is relieved by me trying to learn Ruby well and insisting that I do everything in Ruby until I get a good grip on it (or unless Java is such a blatantly better choice).

I think the problem with having Java as the only programming language is that, until I really got a good look at Ruby, I looked at the basic way we were taught to get input from the user and thought it just had to be that complicated:

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String response = in.readLine();

As I’ve said, Java is not my only language. I know it’s a lot less work to do this in C or Perl. But since I don’t really have the same grip on C or Perl that I have on Java, it’s not something that really ever hit me. Yet now that I’m looking to know as much about Ruby as I do about Java (hopefully more), all these little things are raising red flags. Like in Ruby, to get a line of input from the user, it’s:

foo = gets()

Which is closer to how it’s done in Perl or C and much shorter than Java. And of course I could go on about how Ruby is way less verbose than Java (which I will do next time), but Ruby’s not the focus of today. Java is. Java has been a great language for me over the last how-many-years. But I think we can come to a consensus that, no matter how you feel about Java, it can’t be the only tool in your toolbox.

I also think that the only thing worse than not knowing a particular language is knowing it not that well. I spent about a year maintaining O’Caml applications, and I still can’t say that I know O’Caml. I can subconsciously look at O’Caml code and say what it’s doing, but I don’t know the O’Caml standard library. Google and the O’Caml docs are my best friend when I touch O’Caml, which just isn’t something that happens when I’m using Java. Sure, I still use Google, but I don’t need to go on message boards and forums to find out what a particularly weird error I’m having means. But this is getting off-topic. What I mean to say is that I don’t really know all the amazing features behind O’Caml. I know some subset of it that corresponds to the style of the coders whose code I maintained, and that’s about it.

I’ve decided for Ruby that that’s totally unacceptable. It shows a lot of promise and I when I talk about Ruby, I want to at least appear like I know what I’m talking about. I want to approach a Ruby conversation with the same gusto that I have when I’m talking Java. And I wish that I had that knowledge with another language from my undergrad days. But there’s no time like the present, so off we go on Ruby!

You Should Use 'Screen'

Why have I not heard about screen until now? It’s an awesome little app that lets you make terminal windows on the fly, switch between them, and most useful of all, detach windows and resume them later. There have been SO many times when I have an app that prints to standard out that I need to have run in the background but doesn’t on its own.

Even if you have a nice little app that makes terminal windows for you (I have iTerm and love it), the detaching ability is well worth the small learning curve on screen. It comes standard on Mac OS X and is a quick install on Ubuntu and friends. This walkthrough does a great job teaching all the screen commands and how to use them, so if you end up using screen religiously, you’ll either be there a lot or end up memorizing all the commands.

Simplicity, Part 1

Just a random little mumbling for today: I was on the StackOverflow message forum and saw a questionasking how to find your gateway’s IP in Java. The easy way is to do it via a shell command, but in Java this got brutally complicated, and while I was doing this, all I could think was “geez, how much simpler is this in Ruby?”

Here’s why the Ruby guys are all so happy (and why I’m frustrated at Java). Here’s the Java code to do it:

import java.io.*;
import java.util.*;

public class ExecTest {
   
public static void main(String[] args) throws IOException {
       
Process result = Runtime.getRuntime().exec("traceroute -m 1 www.amazon.com");

       
BufferedReader output = new BufferedReader(new InputStreamReader(result.getInputStream()));
       
String thisLine = output.readLine();
       
StringTokenizer st = new StringTokenizer(thisLine);
        st
.nextToken();
       
String gateway = st.nextToken();
       
System.out.printf("The gateway is %s\n", gateway);
   
}
}

And here’s the Ruby code:

result = `traceroute -m 1 www.amazon.com`
result
.each do |line|
 
if line =~ /\d  (\d*.\d*.\d*.\d*)/
    puts
"The gateway is #$1"
 
end
end

Holy crap that’s a huge distance. And for those of you more into the numbers, here’s what word count has to say:

     lines   words chars
       
6      21     141 ExecRuby.rb
     
14      50     502 ExecTest.java

This is a huge difference, but since numbers can be misleading, I’d rather measure the time it took me to wrote these: it took about 5 minutes to write the Java version, and half that to write the Ruby version. I’ve known Java for a while but since I’m a little rusty, I got hung up a bit on the little syntax stuff and dumb library crap. However, I don’t really know Ruby that well and am still learning it, and I still got it done in half the time!

A lot of this owes to Ruby being much simpler on the syntax. Many argue it’s the dynamic / duck typing, but C# 3.0 is evidence against that with their new local type inference feature. It’s just easier to get it done in Ruby (at least in this example), and I’m suspecting this so much that the title of this post is numbered for possible future cases of this.

Out of It this Week

So I’ve picked up some new books and material to review over the weekend and have lots to talk about, but don’t have anything thrillingly polished for tomorrow. Check back on Monday for some new programming stuffs!

Hint: We’ll be looking into Ruby and why I can’t make up my mind on whether or not I love it or hate it.

FileVault is Mildly Annoying

While reading over the new Joel on Software book (More Joel on Software), I came across the chapter “A Game of Inches”. An important chunk of it is that all the little design choices you make (or fail to make) are the things that add up in the user’s mind. While playing around with FileVault last night, I couldn’t shake the feeling that this was right on.

FileVault is part of Mac OS X (may be new to Leopard) and encrypts your home folder. I initially turned it on right away since I’m super paranoid but over time realized that I was likely never going to put any super-secret stuff on it and would possibly need an unencrypted drive to recover data off of should the computer tank.

The big kicker though is that you can’t reclaim file space in your home directory unless you reboot. Example: I had a few extremely large data files (~500MB) that I was fiddling around with in some Perl scripts and deleted them. My initial inclination was that I would see my free space jump up by the amount of stuff I deleted, which naturally was wrong. I had to reboot the computer and get prompted to ‘recover free space’, which is then given back to me upon the next login.

This wouldn’t be too bad if it didn’t happen too often, but as I have a Windows partition on my Mac, I don’t have a whole lot of free space, and thus for a while, I was sitting at around a gig of free space. So this ended up happening all the time and quickly became an annoyance.

So I go click on the button to turn off FileVault, and after a minute (literally) it tells me I need to go free up 35GB of space to turn off the encryption. Unbelievable. I ended up having to delete the Windows partition and then some other stuff to recover that much space just to turn off the encryption.

But here’s where it really is a game of inches. FileVault tells me that I have to log out while it’s decrypting things and that once I hit ‘ok’, it’s going to need to do it’s thing uninterrupted. That’s fine with me, since that’s what I wanted it to do in the first place. But after I hit ‘ok’, it takes a moment and tells me while it’s working that this process will take FIVE HOURS. Here’s the game of inches, Apple. PUT THE FIVE HOUR MESSAGE ON THE SAME SCREEN WHERE I DECIDE WHETHER OR NOT THIS IS THE BEST TIME TO DO THIS! Don’t tell me that determining whether FileVault can be uninstalled will take a while but fail to mention how long the actual decryption will take!

Thankfully it didn’t end up taking five hours, but it still did take around two hours, which totally sucked. But at least I recovered the ~30GB from erasing the Windows partition and found a real-life application for stuff I read about.

Server Crash

So to all two of my current readers out there, my friend’s CPU (where I used to host this) fatally crashed. I had been using WordPress Database Backup, but for some reason although it has a daily backup option, it was only backing up when I told it to…

That being said, we’re back and new posts will return shortly. Enjoy! I’ve recovered a few of my posts from the Google cache of my page, and will throw in some stubs for the other stuff I couldn’t recover so I can re-write them (possibly even improve them).

profile for Chris Bunch at Stack Overflow, Q&A for professional and enthusiast programmers