I swear to god

December 5th, 2005

If OpenOffice 2.0 asks me to independently download one more file that isn’t part of the ports tree, I’m going to find the dev team and blow their goddamn heads off. Hey guys: if the compile process requires four files that you aren’t allowed to include in the distribution, then tell me about all of them up-front instead of mentioning one failed dependency and exiting, leaving 3 more unfulfilled dependencies waiting patiently like tripwires in the makefile jungle.

Computer Science is a Science

November 29th, 2005

That’s something Mackey used to always say at UCSC, and I think I remember Louden saying it at SJSU too. Mackey taught CMPS12B which was sorta the wake up call/filter for all the CS majors at UCSC. The class jumped really heavily into Unix and software development tools like Makefiles and version control.

Mackey generally had no web page for his course information (notes, examples, and assignments) was in a folder on the AFS server. He wrote everything in either plain text or roff. For printing he would pass the text files through enscript. I learned how to make a man page using roff during the class too.

Oh and one of the things I liked the most was that he doesn’t accept MIME/HTML email. He has an autoreply telling you about the horrible butchering of SMTP and spreading of viruses using such things causes.

Anyway so the point is a billion new foreign things are being introduced to the students. And although he provided really great examples, that were real examples, I mean stuff you would really use not just toy code, many students were still asking for help. What does this program do? How do you use it? What happens with this input?

And his repsonse. Computer Science is a Science. Go try it out. Write a test program. Write some test input to poke at it and see what the pattern of the programs behavior is.

I don’t actually know what other scientists do. But I think this is really the best way to learn computer science stuff. If someone just tells it to you, or you just read it, it never really makes sense to you. You are never really paying attention. Go out and actually type and run the programs yourself.

PeopleSoft Sucks!

November 17th, 2005

I know I should be careful about judging others, but right now PeopleSoft software is a leading cause of stress in my life. Not only do they have poor Mozilla, FireFox, and Safari support. They don’t even work that well in IE:
PeopleSoft user hostile error message.

I have now successfully registered for classes :)

November 16th, 2005

“Control-shift-backspace makes my terminal do weird things.” – Ted Wang

In praise of functions that don’t do anything

November 15th, 2005

Most functions do something. I mean, that’s why they are called ‘functions’ and not ‘nothing’, right? But lately, I’ve come to appreciate the value of functions that don’t do anything at all.

The two most obvious examples of functions that don’t do anything at all are boolean operators with just the right parameters. For instance, the truth value of X AND 1 is the same as the truth value of X, and the truth value of X OR 1 is the same as the truth value of X.

“Why,” I hear you ask, “would anyone need a value that they already have, and why would they spend a cycle or two on it?”

“And,” I reply, “that is a very good question! But fear not, for I am about to reveal the answer!”

Suppose you are writing a function that does something. In this case, it’s an function that makes an SQL query and returns a result set. Let’s say your database is pretty simple for the sake of example. It’s got a table, Author, which has just two fields: authorId (a unique identifier), and name (the name of the author). Book, which has fields bookId (the unique identifier of a book), name (the name of the book), and authorId (which ties a Book record to an Author record). So something pretty obvious to do would be to return a set of all the book names, associated with the names of their authors.


$my_query = "SELECT Book.name, Author.name
FROM Book, Author
WHERE Author.authorId = Book.authorId
";

$result = db_object->query($my_query);

And that’s about as simple as it gets. Another simple task would be to only list the books by a particular author:

$author = some_other_function();

$my_query = "SELECT Book.name, Author.name
FROM Book, Author
WHERE Author.authorId = Book.authorId
AND Author.authorId = '$author'
";

$result = db_object->query($my_query);

Hopefully you’d have a bunch of junk in there to protect against sequel injection attacks, but I’m ignoring that for now. Ok, suppose we want to get all the books written by a list of authors. If some_other_function()returns a list, our query won’t work. Let’s tinker with it some more.

$authors = some_other_function();

$my_query = "SELECT Book.name, Author.name
FROM Book, Author
WHERE Author.authorId = Book.authorId
";

if ($authors) {
//this way, some_other_function() can return either a
//list or a scalar, and we don't have to care
if (!is_array($authors)) {
$authors = array($authors);
}
$my_query .= " AND (";
for ($i = 0; $i < count($authors); $i++) {
if ($i != 0) { $my_query .= " OR "; }
$my_query .= " Author.authorId = '".$authors[$i]."';
}
$my_query .= " )";
}

$result = db_object->query($my_query);

Now, we can handle lists or scalars. Unfortunately, an empty list might end up being a problem, since an empty set of parenthesis doesn’t have a truth value of 0 like you’d hope for (in MySQL, at least, and probably other databases as well). Plus, the loop is a little awkward – having that weird if statement whose block gets passed up on the first run seems to detract from its readability. And, if the list isn’t integer-indexed, the whole thing goes to hell. We can use a foreach loop instead, but then we have $i as a non-loop variable, sort of butting in there and costing a couple lines (and the associated readability) but not doing much. On the other hand, a function that doesn’t do anything can save the day (take that, sub-space!):

$authors = some_other_function();

$my_query = "SELECT Book.name, Author.name
FROM Book, Author
WHERE Author.authorId = Book.authorId
";

if ($authors) {
//this way, some_other_function() can return either a
//list or a scalar, and we don't have to care
if (!is_array($authors)) { $authors = array($authors); }
$my_query .= " AND (0 ";
foreach ($authors as $author) {
$my_query .= " OR Author.authorId = '$author' ";
}
$my_query .= " )";
}

$result = db_object->query($my_query);

The possible error condition disappears without a test (an empty list of authors will return no results), and the function is more readable. All thanks to a no-op.

Christmas in the Clouds

November 13th, 2005

I highly recommend everyone go see Christmas in the Clouds. I guess this movie was actually made 4 years ago, but had no distributor. It is playing now at the Camera Cinemas in downtown San Jose. The movie is an awesome comedy with some good drama and a happy ending that left me feeling better after a movie than I have in a long time. I don’t suggest looking at the official website because I think it gives away too much of the movie.

Software books I’ve been reading

November 6th, 2005

Recently I started reading Code Complete, I remember looking at the first edition of this book many years ago and thinking what would Microsoft Press know about writing code. But I actually think the book is pretty good. I started looking at it after reading a review of Pragmatic Programmer complaining that the book lacked detail and specifics. This may have been done to make the book more “timeless”, but Code Complete has a lot of details that seem to have stood the test of time. Although I’m not sure how much changed between the first and second edition, probably a lot. And later the authors ofPragmatic Programmer started their own publishing company Pragmatic Programmers which has many books on applying specific programming practices, but they do still seem to keep their theory and practice books somewhat separate.

Well this article makes a good excuse to post several amazon affiliate links and get one post ahead of Ravi.

FBI continues oppression of Bot-Net operators

November 6th, 2005

CNN reports (actually from Reuters) that the FBI has arrested another Bot-Net operator.

Microsoft Announces Meta OS

November 3rd, 2005

So this post was inspired by a slashdot article. Though I wasn’t able to view Microsoft’s site on Singularity because it was already slashdotted.

Any way so that idea appears to be making an OS where the only code you can run is managed code which is Microsoft speak for interpreted code as opposed to native byte code. The only thing I think this gives you is buffer overflow prevention. The garbage collection is a bit of a an unachievable goal because you can still write in memory leaks in code with garbage collectors just by writing bade code that keeps a pointer to the object longer than you need to. And you can still write a program that asks to allocate all memory like while(true) { $a[$i++] = "some string"; }

And I’m sure there are still interpreted viruses… I think they are called Visual Basic macros, or Office Add-ins.

Overall though I like interpreted languages more than native binary compiled languages, despite the occasional speed/memory issue. So I’m all for it.

More analog than analog

November 3rd, 2005

This new watch on thingeek called the Nooka Zot Watch now lets you not only be unsure of the time, but asked the age old question is the time half full or half empty. I’m not really sure.

They also have had a binary watch if you just want to make things complicated. If binary is too much for you try the unary hour, unary decimal minute combo Ibiza LED watch.

Hmm think geek should have some kind of affialite system so we can make money off of all these gratuitous links.