Friday, November 2, 2007

Seagate Sued over Industry Convention

I'd hate to be a me-too blogger and just pass the latest links around, but this news really shocked me. I mean, I know deep down in the heart of every computer user is an urge to fix this stupid industry convention, but can they really sue a company for doing the same thing as everyone else?

But really, I'm happy to see these things are changeable! What long-standing bad convention can consumers attack next? Lets pick out the biggest producer of electronics schematics we can find and sue them because electrons are negative and actually flow in the opposite direction as the "current" in their electrical diagrams. I am sure someone out there can sound confused and irate about this! Current does not flow as advertised!

Either way, I'm surprised to see Western Digital didn't take the fall here, as they seem like a more household name.

Hey (non-existant) commenters: post some bad conventions and who you'd like to sue about them.

Thursday, November 1, 2007

Now You're Programming with Power

If you asked me last year what makes a good programming language, I would have said it's one that is simple and easy to read. I'd design languages like this in my head, daydreaming about clean syntax and beautiful understandable code. Lisp programmers would look down on me scornfully as I moaned about their parenthesis. It turns out they knew something I didn't.

Functions rule.

I can thank Stumble-Upon for this revelation, as it randomly tossed me to a video of the first ten minutes of a series of computer science lectures recorded in 1986! It is somewhat hard for me to believe that this has existed this long, yet has not seeped into any classes in the UCSC Computer Science (read: Java C Perl) department other than in an elective called "Comparative Programming Languages". Though it would make sense when you consider some of these professors still live in 1970, and bicker over ancient differences between vi and emacs and the number of characters that really should be displayed on a single line in the terminal.

What I learned is that functions can do anything. This may seem like common sense, but if it really was common then there wouldn't be so many languages out there that make creating functions at runtime extremely difficult. I'm looking at you, Java! Other languages tend to hack this feature in as a side-thought, and pitch the Object Oriented Paradigm as their primary facet. Well guess what: you can implement objects with dynamic functions!

Here's a rather simple way to do it in scheme:

First, lets make a constructor. Every class of objects needs one of those. This one will have three fields in it: foo, bar, and baz.
(define (thing-constructor foo bar baz)
(lambda (choose)
(cond ((equal? choose 'foo) foo)
((equal? choose 'bar) bar)
((equal? choose 'baz) baz))))
What we've really created here is a function that returns another function. The function it returns holds on to the three values from before, and allows us to choose which one we want out. Lets create an instance of our class and test it out.
(define x (thing-constructor "Joe" 'Mel 5.17)) ; an instance

(x 'foo) ; gives us "Joe"
(x 'bar) ; gives us 'Mel
(x 'baz) ; gives us 5.17
Well hey, look at that! We just created an object using only functions. Want methods instead of just data? You can put those in too.
(define y (thing-constructor sqr sqrt (lambda (x y) (* (+ x y) (- x y)))))

((y 'foo) 3) ; -> 9
((y 'bar) 16) ; -> 4
((y 'baz) 5 7); -> (* (+ 5 7) (- 5 7)) -> (* 12 -2) -> -24
Neat, huh? And of course you can also put in other objects, and put objects in those objects, and so on, and thus create a traversable tree, list, graph, you name it. And all it took to implement this was cond, equal?, and lambda. Functions are pretty darn cool.

As a disclaimer, I'd like to say that I'm new to scheme, and that this example should be pretty obvious to any good schemer. There are much better implementations of object oriented programming in scheme out there, with all the bells and whistles. But still, functional programming is powerful, and this example was surprising enough to me. Hopefully it will be inspiring to some other programmers out there who have yet to try a functional language.