I just got back to work after a lovely, lovely break, and will get back to blogging Real Things soon. In the meantime, recording of a milestone:
I had what I like to think of my "first" "release" of ScrabbleCheat. In a match of Scrabble without it, Madly Brilliant beat me by 97 points. I used it successfully for the first time (with her knowledge and permission) and beat her the following game by about 83 points. There's still tons of work to be done, but its core is there, certainly.
I learned a ton from writing it, and hope to create a few animations/blog posts about it in the near future. This flowchart to writing Good Code, by xkcd, is relevant, mostly in relation to the quality differential between the hacktacular client code and less hackey server code.
Showing posts with label code. Show all posts
Showing posts with label code. Show all posts
January 6, 2011
December 13, 2010
How to tell someone their code sucks
Some days I just wish I were David Korn:
No, it's completely wrong-headed, insane and unreasonable. Your code is 100% bogus and should be taken out the back, lined up against a wall, and machine-gunned.
Then the bleeding corpse should be hung, drawn and quartered.
Then burnt.
Then the smouldering rubble should be jumped up and down on.
By a hippo.
December 7, 2010
STOP IT WITH YOUR STATE
Alright forks, time for some smugness. I know, on this blog?!? But bear with me.
I'm just completely frakking pissed at a number of bugs I've been chasing down, at work and at home, and after looking for the more general problem, it's all about state. ALL OF IT.
Okay, not all of it. Most of it has to do with poor abstractions at the programming language level. But the primary one is state, and mostly, I think it's about time just done gone outgrown that shit.
Java was such a rousing success in part because it was so completely idiot-proof. When you remove memory management and pointers from C++, and sandpaper a few of its edges (no header files or need to declare methods, for example), virtually everyone can program in it and not make too big a mess. While I think Java is a completely neutered language (not to mention a liability issue), I think it really didn't go far enough. No, forks, let's learn from our friends in the 1970's and 80's and just flat out remove mutable state already, since most programs don't need it and most programmers can't handle the responsibility of it. The same goes for pointers, but you already knew that.
Despite it being un-rantey, let's qualify this for a second: I'm not saying all programs should be written statelessly, or that nobody should be using pointers. And Lord knows all programmers would ideally know more than just the basics on these topics. We'll always have a need for embedded systems, operating systems, very fast media processing, and scripts we'll use only once and not want to think too hard about.
The problem comes with all the rest of the programs, that don't need instruction-level efficiency; many are still written with mutable state as the default rather than a last resort. This is like solving your problems with beatings before you try reason. Most programmers use it willy nilly, thinking they're holding firecrackers when they're really holding grenades.
Here's ultimately the reason: in today's day and age, knowing what we know and writing the programs we want to write on the hardware we have, state is an abstraction that is too easily broken for the power it gives you, and it's about time we outgrew it. Let's look at the popular programming paradigms from the abstractions they rested on, and you notice a trend:

Structured programming: this was at first met with resistance: why would you eliminate gotos? The answer was the best noun-made-command I know: goto hell. As programs got larger and larger, there came a point where there was just too much complexity associated with being able to arbitrarily jump to any lexical location in your code. Since this was often in languages with file inclusion, this meant you could jump anywhere in any file you were including from anywhere else!
What was the solution? Was it moar gotos? IDE's to help with goto-related programming? No forks, they just cut that shit out and started structured programming. This led to a great bloom in software, where we got all our delicious *nix dinosaurs we know and love even today.
But what about GIANT programs, like Word? What made that possible? Because again, at a certain scale, this paradigm got unmanageable. Namely, keeping track of all the data associated with a function got to be way too complex. Structs of structs of structs would lead to 3-star programmers that made code a vile mess to work with and debug. It was only when we decided to encapsulate data with its related function in objects that we got to Object-Oriented programming.
And that led to its own bloom of awesomeness. But really forks, have we solved software? Is it too unreasonable to think that maybe objects* rely too much on state to be as scalable as the programs we want to write these days?
(Never mind the other, non-state objections to OOP, such as modeling programs that do things entirely with nouns, or the avoidable lame hoop-jumping called Design Patterns that objects make us use).
It sounds extreme, but you don't know the shackles you're programming with until you break free of them. Once the outputs of a function depend entirely on its inputs, it actually becomes reusable. You only have to test the outputs for every set of inputs, not the outputs for every set of inputs at every possible state the whole rest of your program can be in!
Further, once you eliminate the null value or null pointer, a function call must return "Whatever I promised," not "Whatever I promised or NULL lol go debug that."
And the sooner we do this, the sooner we don't have to sit at our debuggers stepping through reentrant code looking at register values for the exact moment the memory's head a splode.
Most of all, I'd have to find another way to be inflammatory, rantey, and use too much formatting markup.
*= Note that my beef isn't entirely with objects, per se. there are object-oriented languages that don't rely on state. Scala is the most popular that encourages functional programming, and Reia has immutable objects.
(for those curious, I'm mostly up to proverbial here with my last bug on a major ScrabbleCheat feature. I veered away from Erlang to write the UI in Ruby with an ncurses wrapper, and now that I've dabbled in a stateful solution I'm fighting memory corruption in a language without explicit memory management. Bleh.
Meanwhile, I'm hating on C++ because a) I use it at work, b) in the playtimes I've used it, I've only ever regretted it, and c) it's C++, what kind of language snob would I be if I treated it fairly?)
I'm just completely frakking pissed at a number of bugs I've been chasing down, at work and at home, and after looking for the more general problem, it's all about state. ALL OF IT.
Okay, not all of it. Most of it has to do with poor abstractions at the programming language level. But the primary one is state, and mostly, I think it's about time just done gone outgrown that shit.
Java was such a rousing success in part because it was so completely idiot-proof. When you remove memory management and pointers from C++, and sandpaper a few of its edges (no header files or need to declare methods, for example), virtually everyone can program in it and not make too big a mess. While I think Java is a completely neutered language (not to mention a liability issue), I think it really didn't go far enough. No, forks, let's learn from our friends in the 1970's and 80's and just flat out remove mutable state already, since most programs don't need it and most programmers can't handle the responsibility of it. The same goes for pointers, but you already knew that.
Despite it being un-rantey, let's qualify this for a second: I'm not saying all programs should be written statelessly, or that nobody should be using pointers. And Lord knows all programmers would ideally know more than just the basics on these topics. We'll always have a need for embedded systems, operating systems, very fast media processing, and scripts we'll use only once and not want to think too hard about.
The problem comes with all the rest of the programs, that don't need instruction-level efficiency; many are still written with mutable state as the default rather than a last resort. This is like solving your problems with beatings before you try reason. Most programmers use it willy nilly, thinking they're holding firecrackers when they're really holding grenades.
Here's ultimately the reason: in today's day and age, knowing what we know and writing the programs we want to write on the hardware we have, state is an abstraction that is too easily broken for the power it gives you, and it's about time we outgrew it. Let's look at the popular programming paradigms from the abstractions they rested on, and you notice a trend:

Structured programming: this was at first met with resistance: why would you eliminate gotos? The answer was the best noun-made-command I know: goto hell. As programs got larger and larger, there came a point where there was just too much complexity associated with being able to arbitrarily jump to any lexical location in your code. Since this was often in languages with file inclusion, this meant you could jump anywhere in any file you were including from anywhere else!
What was the solution? Was it moar gotos? IDE's to help with goto-related programming? No forks, they just cut that shit out and started structured programming. This led to a great bloom in software, where we got all our delicious *nix dinosaurs we know and love even today.
But what about GIANT programs, like Word? What made that possible? Because again, at a certain scale, this paradigm got unmanageable. Namely, keeping track of all the data associated with a function got to be way too complex. Structs of structs of structs would lead to 3-star programmers that made code a vile mess to work with and debug. It was only when we decided to encapsulate data with its related function in objects that we got to Object-Oriented programming.
And that led to its own bloom of awesomeness. But really forks, have we solved software? Is it too unreasonable to think that maybe objects* rely too much on state to be as scalable as the programs we want to write these days?
(Never mind the other, non-state objections to OOP, such as modeling programs that do things entirely with nouns, or the avoidable lame hoop-jumping called Design Patterns that objects make us use).
It sounds extreme, but you don't know the shackles you're programming with until you break free of them. Once the outputs of a function depend entirely on its inputs, it actually becomes reusable. You only have to test the outputs for every set of inputs, not the outputs for every set of inputs at every possible state the whole rest of your program can be in!
Further, once you eliminate the null value or null pointer, a function call must return "Whatever I promised," not "Whatever I promised or NULL lol go debug that."
And the sooner we do this, the sooner we don't have to sit at our debuggers stepping through reentrant code looking at register values for the exact moment the memory's head a splode.
Most of all, I'd have to find another way to be inflammatory, rantey, and use too much formatting markup.
*= Note that my beef isn't entirely with objects, per se. there are object-oriented languages that don't rely on state. Scala is the most popular that encourages functional programming, and Reia has immutable objects.
(for those curious, I'm mostly up to proverbial here with my last bug on a major ScrabbleCheat feature. I veered away from Erlang to write the UI in Ruby with an ncurses wrapper, and now that I've dabbled in a stateful solution I'm fighting memory corruption in a language without explicit memory management. Bleh.
Meanwhile, I'm hating on C++ because a) I use it at work, b) in the playtimes I've used it, I've only ever regretted it, and c) it's C++, what kind of language snob would I be if I treated it fairly?)
November 13, 2010
The Road to Lisp Survey
I, Paul Meier, do solemnly offer these responses to the Road to Lisp Survey:
When did you first try Lisp (meaning here and throughout the survey "any member of the Lisp family") seriously, and which Lisp family member was it?
I took Lisp seriously after my first exposure to it, in Shriram Krishnamurthi's programming languages course, based on his excellent book, PLAI (download it! it's free!). We mostly used Scheme for the course (the implementation now called Racket), and while I could call the programming from that class my first exposure, I really only explored it during self-study after the course.
In the Preface to his book, Shriram mentioned The Little Schemer as a good introduction to thinking in Scheme. In the Acknowledgments, he said "Please read those magnificent books even if you never read this one" of two books, one of them being Structure and Interpretation of Computer Programs. I picked them both up that Winter, and I was hooked.
What led you to try Lisp?
The answer is really in the next question, but I'll also mention that this was not just my first exposure to Lisp, but functional programming as a whole. While I enjoyed programming to a point, what really interested me in Computer Science was the strong theoretical results we'd achieved: the fact that we could prove undecidability kept me awake for weeks.
So part of my migration to Lisp wasn't just to homoiconic syntax and dynamic type systems: it was also the wonders of functional programming I would find prominently in Scheme.
If you were trying Lisp out of unhappiness with another language, what was that other language and what did you not like about it, or what were you hoping to find different in Lisp?
I took the languages course at the same time I took our excellent graphics course, where we used C++. I found I spent much, much longer debugging the C++ programs, for a much less interesting class of bugs. You'd pull your hair out, looking at memory addresses and pointer values only to find you did your pointer arithmetic wrong (we were investigating a two-dimensional matrix stored as a linear array), or that a state change occurring in an edge case was leaving your program in an inconsistent state. It was frustrating, to say the least.
In Scheme, I was only fixing logical bugs. I spent more time thinking than typing. My programs were shorter and elegant. It's as if, by framing the problem differently, hundreds of edge cases and corner cases simply ceased to exist.
And there's something to that. Removing state means putting a lot more effort up front, but ultimately makes your programs worlds easier to write and maintain after you've invested. Not to mention spending your brain cycles modeling is worlds more fun spending them debugging.
Of course, I didn't know that back then; I moved because I just had the feeling they were doing something right, and I could learn something valuable.
How far have you gotten in your study of Lisp? (I know, that is hard to measure)
This is very hard to say. In many ways, I'm still a novice, since most of my Lisping doesn't take full advantage of macros, Lisp's crown jewel. I'm still much more comfortable in Scheme than CL, Clojure, or Arc; I'd call myself a competent Lisp programmer having written a few small programs and baby scripts, with a toe in advanced and a longing to go expert.
What do you think of Lisp so far?
I think it's still a very advanced, progressive way to approach programming, at least with smaller engineering teams. I'm completely unsurprised it's not used in industry as much; it's a large investment, and languages rely heavily on community. Incidentally, I feel the only real rival to Lisp in caliber would be Haskell, who's unofficial motto is "avoid success at all costs." ^_^
--------------
Also, any of you see atomo? It looks pretty hip, if ambitious...
When did you first try Lisp (meaning here and throughout the survey "any member of the Lisp family") seriously, and which Lisp family member was it?
I took Lisp seriously after my first exposure to it, in Shriram Krishnamurthi's programming languages course, based on his excellent book, PLAI (download it! it's free!). We mostly used Scheme for the course (the implementation now called Racket), and while I could call the programming from that class my first exposure, I really only explored it during self-study after the course.
In the Preface to his book, Shriram mentioned The Little Schemer as a good introduction to thinking in Scheme. In the Acknowledgments, he said "Please read those magnificent books even if you never read this one" of two books, one of them being Structure and Interpretation of Computer Programs. I picked them both up that Winter, and I was hooked.
What led you to try Lisp?
The answer is really in the next question, but I'll also mention that this was not just my first exposure to Lisp, but functional programming as a whole. While I enjoyed programming to a point, what really interested me in Computer Science was the strong theoretical results we'd achieved: the fact that we could prove undecidability kept me awake for weeks.
So part of my migration to Lisp wasn't just to homoiconic syntax and dynamic type systems: it was also the wonders of functional programming I would find prominently in Scheme.
If you were trying Lisp out of unhappiness with another language, what was that other language and what did you not like about it, or what were you hoping to find different in Lisp?
I took the languages course at the same time I took our excellent graphics course, where we used C++. I found I spent much, much longer debugging the C++ programs, for a much less interesting class of bugs. You'd pull your hair out, looking at memory addresses and pointer values only to find you did your pointer arithmetic wrong (we were investigating a two-dimensional matrix stored as a linear array), or that a state change occurring in an edge case was leaving your program in an inconsistent state. It was frustrating, to say the least.
In Scheme, I was only fixing logical bugs. I spent more time thinking than typing. My programs were shorter and elegant. It's as if, by framing the problem differently, hundreds of edge cases and corner cases simply ceased to exist.
And there's something to that. Removing state means putting a lot more effort up front, but ultimately makes your programs worlds easier to write and maintain after you've invested. Not to mention spending your brain cycles modeling is worlds more fun spending them debugging.
Of course, I didn't know that back then; I moved because I just had the feeling they were doing something right, and I could learn something valuable.
How far have you gotten in your study of Lisp? (I know, that is hard to measure)
This is very hard to say. In many ways, I'm still a novice, since most of my Lisping doesn't take full advantage of macros, Lisp's crown jewel. I'm still much more comfortable in Scheme than CL, Clojure, or Arc; I'd call myself a competent Lisp programmer having written a few small programs and baby scripts, with a toe in advanced and a longing to go expert.
What do you think of Lisp so far?
I think it's still a very advanced, progressive way to approach programming, at least with smaller engineering teams. I'm completely unsurprised it's not used in industry as much; it's a large investment, and languages rely heavily on community. Incidentally, I feel the only real rival to Lisp in caliber would be Haskell, who's unofficial motto is "avoid success at all costs." ^_^
--------------
Also, any of you see atomo? It looks pretty hip, if ambitious...
November 7, 2010
THE LAND OF LISP
It's been a while since I've been able to run through a code book, with life throwing me so many welcome curveballs since the summer. But I'm finally taking the time to work through a book like old times; this go-round is with Conrad Barski's Land of Lisp. I probably wouldn't have gone for it, but the music video he made was just too cute:
The book is peppered with cute cartoons and a whimsy feel that is endearing, not overbearing. I highly recommend it, if only for the comics (though working through the examples is fun, the games you make really highlight Lisp's strengths).
Some may recall that I've dabbled in CL before; sadly that affair was over before it started (curveballs!), but my next project after ScrabbleCheat will likely be in either Haskell or Common Lisp ^_^
And how goes ScrabbleCheat? Quite well, actually! The technologically adventurous can download and play with it now. What I'm working on now is a simple UI in ncurses, which will probably take another week or two. But as soon as that's up, the program should not only be functional (which it mostly is now), but usable!
The book is peppered with cute cartoons and a whimsy feel that is endearing, not overbearing. I highly recommend it, if only for the comics (though working through the examples is fun, the games you make really highlight Lisp's strengths).
Some may recall that I've dabbled in CL before; sadly that affair was over before it started (curveballs!), but my next project after ScrabbleCheat will likely be in either Haskell or Common Lisp ^_^
And how goes ScrabbleCheat? Quite well, actually! The technologically adventurous can download and play with it now. What I'm working on now is a simple UI in ncurses, which will probably take another week or two. But as soon as that's up, the program should not only be functional (which it mostly is now), but usable!
September 16, 2010
Living Openly
I just wrote a long blog post talking about why it sucks playing Zerg in Starcraft 2. But friends, there has been too much whining on this blog of late! It's time to bring back two things we've missed for some time: computers and whimsy!

So a few things: I'm living the dream, and finally installed Linux on a personal box. It's a small step (this is my laptop, not my main) but Perfect is the Enemy of the Good, and after using Mac, Windows, and Linux at work, it's incredibly obvious which direction I'd like to move in for the future.
Currently I'm running Ubuntu. I wanted to run Debian like we did at Brown CS, but I'm too much of a weenie at the moment. Besides, Ubuntu's easy as a dream to set up, and I've done it for work twice already. Naturally, I'll be using XMonad as my window manager ^_^
I've written twice that I've "picked up" ScrabbleCheat again, but they were lies. This time I've actually picked it up again (see the commit history!) and it's finally going in the right direction. I had a substantial amount in the first tagged release, but that approach (the anagram solver) was ultimately doomed because it didn't take the board into account when generating words for moves. If I ever get productive again, I'll write about this process, this has been the most fun I've had coding in a while.
Part of the fun has been because of Erlang, which has just had another release. There are so many reasons to use Erlang, and this application contains almost none of them (not super parallelizable, no need for hot-swapping patches, binary syntax, or fault-tolerance). That being said, I really miss my functional programming, and refactoring calls to a series of folds and maps just feels nice. I can't imagine how powerful I'd feel if I'd properly learned macros, or had use of Haskell's type system. Those are for the next ones ^_^
Finally, Diaspora open sourced today. It's too early to really tell anything about its future, but I'm thinking of looking at it and seeing what they did. If we're lucky, the community will take well to this I can finally stop being a dumb fuck who trusts Zuckerberg.
(Note that while I don't love all aspects of the product, my family will always be eternally grateful to Facebook for helping us communicate to so many, so easily during the roughest parts of Annalisa's recovery. I also think their approach to engineering, like many of the coders I know there, is brilliant).
Finally, I'm turning in my iPhone in late October and getting me an Android (probably an Evo), since I'll be paying that bill pretty soon and will use the opportunity to go to a more open land, containing the closed platform I work on ^_^.
So that's it, kids! Open source OS, programming an open-source hippie language, slowly migrating out of Facebook while decking it out with a new, more open phone. All that will be left will be a bed that's also a Reprap.

I'll try to post more; I still sleep next to too much cardboard and styrofoam, and will probably be comfortably moved in and adjusted after Christmas ^_-.
So a few things: I'm living the dream, and finally installed Linux on a personal box. It's a small step (this is my laptop, not my main) but Perfect is the Enemy of the Good, and after using Mac, Windows, and Linux at work, it's incredibly obvious which direction I'd like to move in for the future.
Currently I'm running Ubuntu. I wanted to run Debian like we did at Brown CS, but I'm too much of a weenie at the moment. Besides, Ubuntu's easy as a dream to set up, and I've done it for work twice already. Naturally, I'll be using XMonad as my window manager ^_^
I've written twice that I've "picked up" ScrabbleCheat again, but they were lies. This time I've actually picked it up again (see the commit history!) and it's finally going in the right direction. I had a substantial amount in the first tagged release, but that approach (the anagram solver) was ultimately doomed because it didn't take the board into account when generating words for moves. If I ever get productive again, I'll write about this process, this has been the most fun I've had coding in a while.
Part of the fun has been because of Erlang, which has just had another release. There are so many reasons to use Erlang, and this application contains almost none of them (not super parallelizable, no need for hot-swapping patches, binary syntax, or fault-tolerance). That being said, I really miss my functional programming, and refactoring calls to a series of folds and maps just feels nice. I can't imagine how powerful I'd feel if I'd properly learned macros, or had use of Haskell's type system. Those are for the next ones ^_^
Finally, Diaspora open sourced today. It's too early to really tell anything about its future, but I'm thinking of looking at it and seeing what they did. If we're lucky, the community will take well to this I can finally stop being a dumb fuck who trusts Zuckerberg.
(Note that while I don't love all aspects of the product, my family will always be eternally grateful to Facebook for helping us communicate to so many, so easily during the roughest parts of Annalisa's recovery. I also think their approach to engineering, like many of the coders I know there, is brilliant).
Finally, I'm turning in my iPhone in late October and getting me an Android (probably an Evo), since I'll be paying that bill pretty soon and will use the opportunity to go to a more open land, containing the closed platform I work on ^_^.
So that's it, kids! Open source OS, programming an open-source hippie language, slowly migrating out of Facebook while decking it out with a new, more open phone. All that will be left will be a bed that's also a Reprap.
I'll try to post more; I still sleep next to too much cardboard and styrofoam, and will probably be comfortably moved in and adjusted after Christmas ^_-.
July 23, 2010
GADDAG and Capitalism
I decided to revisit ScrabbleCheat (took a break for administrivia), and wrote my first Wikipedia article, on the data structure I'm refitting it with, to celebrate. It's rare that you can write something on Wikipedia that isn't there, so I had to pounce.
Hope I can keep editing it with diagrams and the like, as it's a little lame at the moment. Against mybetter other judgment, I'm still writing it in Erlang ^_^
---
Also, while I do believe in capitalism and it's ability to generate wealth, here are a few lame things from the last few days:
Forgive the poor sound quality, but this Louis CK bit comes to mind:
Hope I can keep editing it with diagrams and the like, as it's a little lame at the moment. Against my
---
Also, while I do believe in capitalism and it's ability to generate wealth, here are a few lame things from the last few days:
- This infographic, What BP could have bought with all the money they lost, is striking. I'm not so shocked that they lost all that money, but that they had it in the first place. One company was worth all that cumulative wealth, what are the others who haven't had cataclysmic disasters worth? And what are they doing with it?
- Then there's this: "The 400 richest families in America, who saw their wealth increase by some $400 billion during the Bush years, have now accumulated $1.27 trillion in wealth." Their tax rate is also the lowest on record. But hey! They generated wealth, didn't they? Look at the economy now!
- Some graphs visualizing the awful. Guys, something isn't working.
Forgive the poor sound quality, but this Louis CK bit comes to mind:
June 28, 2010
Coding socially
Many other Scrabble cheaters have been written, but mine is in a silly functional language! Also, I have plans to make it more than just an anagram/word generator, even though that's all this release contains. You'll need an Erlang VM to run it.
I'll also mention I have a BitBucket account, but no public repositories. My video games group used Mercurial, so now that two of us have graduated we moved our project to BitBucket. I put Rat Race and FlipTile on there as private repos. If you'd like to friend, follow, or want access to those codebases, let me know ^_^
Finally, though this is on the sidebar, I'm also on Stack Overflow.
(the pic is my Gravatar, used in all these sites; a picture taken when I was in Guatemala last year, with much longer hair and a budding beard. I think it's one of the few pictures that's not unflattering with that style. I look a bit different now.)
June 23, 2010
Type Systems, From 1000 feet high
I posted a link to one of my favorite articles ever on Facebook that is now gone. Here's the reddit link; the article was about what you should know before you debate type systems, since most people have fuzzy notions of what type systems are, what they do, and their properties. He said it best, but now that it's gone, I'll go over a few points that I remember the author addressed.
(edit: Reddit provides a Wayback Machine link, so you can read the original!).
First off, what is a type system, really? This is a bit hard to answer, but the a simple way to describe it is as a mechanism to prevent your code from executing nonsense by investigating what operations you are performing to what data. An example of this would be if you had "2 + potatoes" in your code: a type system would see that you cannot add a number and the symbol "potatoes" (nonsense!) and prevent you from doing so.
Note that we've already encountered a subtle distinction that is the source of confusion: when does this happen? There are two major forms of type systems: static types and dynamic types. A static type system will investigate your code before you run it, reporting any errors it sees, whereas a dynamic type system will tell you of errors during runtime.
When most people talk about a type system, they almost always mean static types. This does not mean that dynamically typed languages don't have type systems. Far from it. Compare this 'untyped' Ruby code:
my_array = [1,2,3]
0.upto(100){ |i| puts (my_array[i] + 1).to_s }
with the 'typed' C code:
unsigned array[3];
array[0] = 1;
array[1] = 2;
array[2] = 3;
unsigned i;
for(i = 0; i < 100; ++i) {
printf("%d\n", array[i] + "Stack Pointer!");
}
The output of the Ruby:
2
3
4
types.rb:2:in `block in': undefined method `+' for nil:NilClass (NoMethodError)
from types.rb:2:in `upto'
from types.rb:2:in `'
And the C:
3915
3916
3917
3917
1606417842
... (continues for 100 lines) ...
We see that Ruby stops and C will plow right through! (To be fair, the C compiler will warn you of the type mismatch). Ruby's type error shows that, while dynamic, Ruby does have a type system, and shouldn't be called untyped. And while C has something people call a type system, it doesn't really function as one might expect.
Which brings up the next point: What should a type system do?. There are two major properties that a type system should strive to provide (incidentally, C/C++/Java don't provide these):
Type systems that provide these properties mean that if your program passes the type checker, it can't "go wrong.", by that we mean, "the computer will always know what do to (progress), and never lead you into a false corner (preservation)." This doesn't mean your program will be bug-free, just that any bugs are logical bugs, or unhandled exceptions (basically, your own fault).
Languages with great type systems (SML, OCaml, Haskell) have proven these properties about their type systems, and it makes programming in those languages a joy.
My favorite part of the article, however, was the Fallacies section. Things people believe which just aren't true. I covered the one of the biggest ones already with the example ("dynamic typing means untyped!"), but here are two others that really get my goat:
It's a pity the original link is gone, he said a lot more than I did, and a lot more clearly. Still, type systems are fun, and go a lot deeper than this. If you're looking for a good introduction to programming with types, The Little MLer is hard to beat. For the theory, people seem to love Pierce. I'm not too far into it, but it looks promising.
(edit: Reddit provides a Wayback Machine link, so you can read the original!).
First off, what is a type system, really? This is a bit hard to answer, but the a simple way to describe it is as a mechanism to prevent your code from executing nonsense by investigating what operations you are performing to what data. An example of this would be if you had "2 + potatoes" in your code: a type system would see that you cannot add a number and the symbol "potatoes" (nonsense!) and prevent you from doing so.
Note that we've already encountered a subtle distinction that is the source of confusion: when does this happen? There are two major forms of type systems: static types and dynamic types. A static type system will investigate your code before you run it, reporting any errors it sees, whereas a dynamic type system will tell you of errors during runtime.
When most people talk about a type system, they almost always mean static types. This does not mean that dynamically typed languages don't have type systems. Far from it. Compare this 'untyped' Ruby code:
my_array = [1,2,3]
0.upto(100){ |i| puts (my_array[i] + 1).to_s }
with the 'typed' C code:
unsigned array[3];
array[0] = 1;
array[1] = 2;
array[2] = 3;
unsigned i;
for(i = 0; i < 100; ++i) {
printf("%d\n", array[i] + "Stack Pointer!");
}
The output of the Ruby:
2
3
4
types.rb:2:in `block in
from types.rb:2:in `upto'
from types.rb:2:in `
And the C:
3915
3916
3917
3917
1606417842
... (continues for 100 lines) ...
We see that Ruby stops and C will plow right through! (To be fair, the C compiler will warn you of the type mismatch). Ruby's type error shows that, while dynamic, Ruby does have a type system, and shouldn't be called untyped. And while C has something people call a type system, it doesn't really function as one might expect.
Which brings up the next point: What should a type system do?. There are two major properties that a type system should strive to provide (incidentally, C/C++/Java don't provide these):
- Progress: A well-typed expression can be evaluated further, unless the computation is finished. In short, if the expression is well typed, the rules of evaluation and type system guarantee "there's something we can do with it" (this excludes exceptions: "1/0" is well-typed, but we can't detect this beforehand without solving the Halting Problem).
- Preservation: Evaluation of a well-typed expression leads to another well-typed expression.
Type systems that provide these properties mean that if your program passes the type checker, it can't "go wrong.", by that we mean, "the computer will always know what do to (progress), and never lead you into a false corner (preservation)." This doesn't mean your program will be bug-free, just that any bugs are logical bugs, or unhandled exceptions (basically, your own fault).
Languages with great type systems (SML, OCaml, Haskell) have proven these properties about their type systems, and it makes programming in those languages a joy.
My favorite part of the article, however, was the Fallacies section. Things people believe which just aren't true. I covered the one of the biggest ones already with the example ("dynamic typing means untyped!"), but here are two others that really get my goat:
- Typed code is longer, more verbose. This, again, is untrue. Most people saying this are referring more to type annotations, which is text you write in your program to tell the compiler what the type of everything is. You'll find these in C, C++, Java, and C#; I once had a really ugly line of Java that looked something like:
HashMap<String, ArrayList<Integer>> scoreMap = new HashMap<String, ArrayList<Integer>>();
(I've ranted about Java's verbosity before). You won't find lines like that (or at least they're not mandatory) in SML, Haskell, or Scala. Using technology from 70's, we can infer types from the context of the code. So those ranting about statically typed code being verbose should really rant against type annotations, which are distinct. - Strong typing vs. Weak typing. THESE TERMS MEAN NOTHING. At least, nobody's agreed upon what they should mean. Even Wikipedia agrees with me. So stop saying it, and say what you mean; it's like saying a food is 'flavorful.'
It's a pity the original link is gone, he said a lot more than I did, and a lot more clearly. Still, type systems are fun, and go a lot deeper than this. If you're looking for a good introduction to programming with types, The Little MLer is hard to beat. For the theory, people seem to love Pierce. I'm not too far into it, but it looks promising.
June 8, 2010
Keep Up that Racket!
PLT Scheme, formerly my favorite Scheme implementation and mentioned before in my writings, has been re-branded as Racket. I'm very excited about this: Racket is a language of unbelievable potential, and hopefully it's re-branding will make people aware of this.
(while it is just a name change and new website, I doubt Clojure would have gotten it's momentum if it were just called "JVM Lisp").
One of the wonderful things about Racket is its mailing list, and a cute discussion there generated a major treasure. Namely, someone brought up that computer programming isn't really that related to computer science, to which someone else mentioned that you could very much be a successful programmer even if you haven't studied the science.
This is sadly true (many people making their livings don't know what they're doing, many examples at The Daily WTF), but then a user named Joe Marshall simply wins:
I attribute this more to the fact that we're living in the cave-writing stages of software: we've had computers for fewer than 70 years, personal computers for maybe 30, and connectivity for less. I'm sure after the invention of the steam engine, all sorts of idiots were designing inefficient, dangerous factories, and we've now got the software equivalent.
I'm lucky in that I got to study the science, and am genuinely interested in it to keep learning. But what a wonderful day when people who develop software who know at least what I do will come standard.
(while it is just a name change and new website, I doubt Clojure would have gotten it's momentum if it were just called "JVM Lisp").
One of the wonderful things about Racket is its mailing list, and a cute discussion there generated a major treasure. Namely, someone brought up that computer programming isn't really that related to computer science, to which someone else mentioned that you could very much be a successful programmer even if you haven't studied the science.
This is sadly true (many people making their livings don't know what they're doing, many examples at The Daily WTF), but then a user named Joe Marshall simply wins:
> It's quite possible to be a productive and successful programmer without having a
> solid understanding of computer science.
That's the problem. Maybe it shouldn't be the case. Variations on this
statement are alarming:
"It's quite possible to be a productive and successful physician without having a solid understanding of medicine."
"It's quite possible to be a productive and successful airplane engineer without having a solid understanding of aerodynamics."
'Rocket Scientist' : 'Newtonian physics'
'Brain Surgeon' : 'neurology'
I attribute this more to the fact that we're living in the cave-writing stages of software: we've had computers for fewer than 70 years, personal computers for maybe 30, and connectivity for less. I'm sure after the invention of the steam engine, all sorts of idiots were designing inefficient, dangerous factories, and we've now got the software equivalent.
I'm lucky in that I got to study the science, and am genuinely interested in it to keep learning. But what a wonderful day when people who develop software who know at least what I do will come standard.
June 1, 2010
Really, Apple?
Apple just showed themselves to be a bit lame about security, at least on Mac OS X two years ago. Here's the story:
My sister had a MacBook to use for college when she was supposed to enroll in 2008. A few weeks later she got sick with her encephalitis, and had her remarkable recovery story.
Unfortunately, she didn't remember the root password she used for her laptop, and it wasn't any of her 'standards' (we'd tried them all). So while she could still use the computer via the auto-login function, she couldn't install or update software (since this requires an authorized user to enter their password). Regarding use of passwords, this was a stranger's computer.
This presented mild problems over the last few years, but this came to a fore last night: with a very outdated iTunes, she couldn't sync her iPhone on her laptop while a summer student at Columbia's School for Continuing Education. This is on top of using and outdated and insecure OS, being unable to install new software...
So I googled "recover lost root password Mac OS X," and lo and behold, the instructions I found worked!
This should not happen. I shouldn't be able to set or reset root passwords with physical access to a stranger's computer. Below is the fix, in both technical terms and non-technical metaphor terms, for the curious:
Technical: Holding Command-S on startup allows you to run in single-user mode, as root. So a simple mount -uw / followed by passwd root allowed me to set the password of user 'root' to letmein. Then I reboot, and log into Mac OS X normally with admin privileges as user root.
Non-technical Metaphor: Suppose you're building is guarded by a lazy doorman. He has a list with all the tenants in the building, but when you walk up to him, you notice he just looks at the placards on the mailboxes. I effectively scribbled 'root' on a postcard, taped it to a mailbox, and walked up to the guard the next day and said "My name is root!" Seeing it written on a mailbox, he let me in and I changed the locks on a stranger's apartment.
While I haven't felt that elated in years (and saved my sister's computer from having its reset to disk factory settings, our best alternative), this is a major lame sauce from Apple.
My sister had a MacBook to use for college when she was supposed to enroll in 2008. A few weeks later she got sick with her encephalitis, and had her remarkable recovery story.
Unfortunately, she didn't remember the root password she used for her laptop, and it wasn't any of her 'standards' (we'd tried them all). So while she could still use the computer via the auto-login function, she couldn't install or update software (since this requires an authorized user to enter their password). Regarding use of passwords, this was a stranger's computer.
This presented mild problems over the last few years, but this came to a fore last night: with a very outdated iTunes, she couldn't sync her iPhone on her laptop while a summer student at Columbia's School for Continuing Education. This is on top of using and outdated and insecure OS, being unable to install new software...
So I googled "recover lost root password Mac OS X," and lo and behold, the instructions I found worked!
This should not happen. I shouldn't be able to set or reset root passwords with physical access to a stranger's computer. Below is the fix, in both technical terms and non-technical metaphor terms, for the curious:
Technical: Holding Command-S on startup allows you to run in single-user mode, as root. So a simple mount -uw / followed by passwd root allowed me to set the password of user 'root' to letmein. Then I reboot, and log into Mac OS X normally with admin privileges as user root.
Non-technical Metaphor: Suppose you're building is guarded by a lazy doorman. He has a list with all the tenants in the building, but when you walk up to him, you notice he just looks at the placards on the mailboxes. I effectively scribbled 'root' on a postcard, taped it to a mailbox, and walked up to the guard the next day and said "My name is root!" Seeing it written on a mailbox, he let me in and I changed the locks on a stranger's apartment.
While I haven't felt that elated in years (and saved my sister's computer from having its reset to disk factory settings, our best alternative), this is a major lame sauce from Apple.
May 18, 2010
Today's study break
Still studying like a madman for Neuroscience, but took a few minutes to catch up on some news. First, a co-creator of Flash makes the best defense of Flash as a platform contra Steve Jobs I've seen, many echo my sentiments exactly. Some money quotes (emphasis mine):
On Apple's devices as a whole:
Apple aside: yes, I've read Designing with Web Standards, and absolutely believe in the future of a better Internet, one that is standards-based, with fewer applications relying on closed, commercial plugins.
But, if it's a challenge for me, a Computer Science concentrator at a top university, to use a programmatic technology that's only been available for a few years (HTML5) to make even a simple graphic react to the most basic inputs that will only work for some browsers... well, it's no surprise that a company filled in the void for rich content, and that designers flocked to it in droves.
Throw all this in with Apple, who have their own crummy record of openness, supporting developers, and economic interests and well... I'm not buying most of Jobs' arguments.
(Adobe isn't excused from this either, mind you: they are also driven primarily by profit motives, and Flash as a technology certainly has its flaws. Yes, they are guilty of not being perfect, but I think Apple is currently more guilty of willful, opaque obstruction, and do more harm to developers and ultimately end users).
---
The other major story was that Facebook and Zynga have entered a formal agreement. Facebook is a company I've been thinking a lot about these days. As a game developer, game player, and privacy/civil liberties enthusiast, Facebook and Zynga's recent turmoils have been a hot, hot topic for me.
(another great post is Diaspora's curse, on why the author believes (and I agree) that Diaspora is doomed to fail, unfortunately).
I think Steve Jobs is willfully missing a key point with his arguments against Flash. The important reason to put Flash on the iPhone is that millions of developers have invested millions of hours building Flash content in Flash. The Flash content out there in the world is an asset of our society and the people who created it. People built it in Flash because there was no other decent technology from companies like Apple, Microsoft or Real Networks that enabled this kind of content to be created and delivered. To say that all this content should be discarded because Steve Jobs is afraid that people will build Flash content that runs on mobile devices running any operating system instead of building content that will only work on Apple mobile devices is doing a disservice to the efforts of all those individuals.
Personally, I think that Flash content will probably outlive iPhone and iPad apps because Flash is designed to deliver media content while the iPhone/iPad development tools are designed to build applications for a specific hardware platform that will be obsolete in 5 or 10 years.
On Apple's devices as a whole:
The iPhone/iPad model certainly has some of the appealing traits of the personal computer market but it also borrows heavily from the business models used by the cell phone, and cable industries. With my computer, I feel like I own it and can do what I want with it. With my iPhone and with an iPad, it’s more like you are leasing a device for a few years until the battery wears out and it’s time to buy the new one.
Apple aside: yes, I've read Designing with Web Standards, and absolutely believe in the future of a better Internet, one that is standards-based, with fewer applications relying on closed, commercial plugins.
But, if it's a challenge for me, a Computer Science concentrator at a top university, to use a programmatic technology that's only been available for a few years (HTML5) to make even a simple graphic react to the most basic inputs that will only work for some browsers... well, it's no surprise that a company filled in the void for rich content, and that designers flocked to it in droves.
Throw all this in with Apple, who have their own crummy record of openness, supporting developers, and economic interests and well... I'm not buying most of Jobs' arguments.
(Adobe isn't excused from this either, mind you: they are also driven primarily by profit motives, and Flash as a technology certainly has its flaws. Yes, they are guilty of not being perfect, but I think Apple is currently more guilty of willful, opaque obstruction, and do more harm to developers and ultimately end users).
---
The other major story was that Facebook and Zynga have entered a formal agreement. Facebook is a company I've been thinking a lot about these days. As a game developer, game player, and privacy/civil liberties enthusiast, Facebook and Zynga's recent turmoils have been a hot, hot topic for me.
(another great post is Diaspora's curse, on why the author believes (and I agree) that Diaspora is doomed to fail, unfortunately).
May 17, 2010
I'm still neck-deep in exam studies...
... but there's a really, really great post on the various meanings of the word 'functor' in 4 different languages. It's the clearest example I've seen for SML, especially. Also note the 'This space reserved for JELLY STAINS' at the top ^_^
May 15, 2010
Another game on Android Market!
My games group is happy and proud to release Momenta (development title Platformer) to the Market today!

As with my first Market release, you can click here if you're browsing from an Android phone, or search "Momenta" in the Android Market.

What would you pay for this Eyjafjallajökull eruption of fun? You might say $10,000, but wait, it's free! Download it, PLAY IT, enjoy it, and please provide feedback!

As with my first Market release, you can click here if you're browsing from an Android phone, or search "Momenta" in the Android Market.

What would you pay for this Eyjafjallajökull eruption of fun? You might say $10,000, but wait, it's free! Download it, PLAY IT, enjoy it, and please provide feedback!
May 9, 2010
PAUL IS BOTHERED
You can talk all you want about 'practicality,' but one way in which I see functional languages will ALWAYS beat imperative is the built-in love of lists. I simply can't express my distaste for always writing:
import java.util.Collection;
import java.util.Iterator;
// crap elided
Iterator<String> iterator = myCollection.iterator();
while (iterator.hasNext()) {
doSomethingWithString(iterator.next());
}
over, say:
(map do-something-with-string my-collection)
But Paul! says you, Java gives you static typing! The Scheme example above doesn't, so it can get away with that kind of dynamic-language brevity! Well, so does Haskell:
map doSomethingWithString myCollection
and SML:
map(doSomethingWithString)(myCollection)
For fun, lets just see it in a smattering of other languages I've used. Ruby:
my_collection.each { |x| do_something_with_string x }
Erlang:
lists:foreach(fun do_something_with_string/1, MyCollection),
Common Lisp:
(mapcar #'do-something-with-string my-collection)
Naturally, this isn't even the whole picture. The example assumes you're iterating for side effects; if you needed the list with its elements transformed, that would be another 5-7 lines of Java. And the list can only exist because it was constructed to begin with, which if you did it in another class, requires 3-6 more import declarations there.
I know its trendy to hate on Java, and I've mentioned before that PL hating like this is unproductive. Still, we use and work with variable-sized lists all the time, and what functional designers figured out (long, long ago) is that it's quite nice to have them built-in.
Bleh, sorry. Android programming is fun, despite the Java.
I did say "imperative" above, not just Java. Kind of a misnomer, as CL and Ruby, above, provide one-line map and are arguably imperative. In that case, I let my biases shine through and used "imperative" interchangeably with "luddite." But let's never forget our buddy C++:
#include <list>
using namespace std;
list<string>::iterator iter;
for (iter = my_collection->begin(); iter != my_collection->end(); ++iter) {
do_something_with_string(*iter);
}
PUKE
import java.util.Collection;
import java.util.Iterator;
// crap elided
Iterator<String> iterator = myCollection.iterator();
while (iterator.hasNext()) {
doSomethingWithString(iterator.next());
}
over, say:
(map do-something-with-string my-collection)
But Paul! says you, Java gives you static typing! The Scheme example above doesn't, so it can get away with that kind of dynamic-language brevity! Well, so does Haskell:
map doSomethingWithString myCollection
and SML:
map(doSomethingWithString)(myCollection)
For fun, lets just see it in a smattering of other languages I've used. Ruby:
my_collection.each { |x| do_something_with_string x }
Erlang:
lists:foreach(fun do_something_with_string/1, MyCollection),
Common Lisp:
(mapcar #'do-something-with-string my-collection)
Naturally, this isn't even the whole picture. The example assumes you're iterating for side effects; if you needed the list with its elements transformed, that would be another 5-7 lines of Java. And the list can only exist because it was constructed to begin with, which if you did it in another class, requires 3-6 more import declarations there.
I know its trendy to hate on Java, and I've mentioned before that PL hating like this is unproductive. Still, we use and work with variable-sized lists all the time, and what functional designers figured out (long, long ago) is that it's quite nice to have them built-in.
Bleh, sorry. Android programming is fun, despite the Java.
I did say "imperative" above, not just Java. Kind of a misnomer, as CL and Ruby, above, provide one-line map and are arguably imperative. In that case, I let my biases shine through and used "imperative" interchangeably with "luddite." But let's never forget our buddy C++:
#include <list>
using namespace std;
list<string>::iterator iter;
for (iter = my_collection->begin(); iter != my_collection->end(); ++iter) {
do_something_with_string(*iter);
}
PUKE
May 6, 2010
Social Golfer problem
One summer I spent working with a professor, the father of a friend heard my plans and remarked (to my friend, not to me)
After some thinking, my guess was they were probably confusing programming with data entry. Moments like these make me realize how much I take computer literacy for granted, especially among older folk. The Supreme Court makes similar mistakes, to much lulz.
I frequently find it helpful then to describe a problem that we work on, since lots of them can be easily described without mathematical notation. One of these has been a real hair-puller these last few days, called the Social Golfer Problem.
The premise is this: you're organizing a golf tournament with 9 people in it. They play every week in groups of 3, and want to play for three weeks.
Here's the catch: they are social golfers, meaning if possible, they never want to play with the same people twice. Your job is to organize the tournament; you have to arrange who plays with whom every week.
So rather than use names, we'll just use numbers. The first week could look something like this:
Since players 1, 2, and 3 are playing together in the first group, next week you need to organize the tournament a little differently to make sure 1 isn't in a group with 2 or 3, 5 isn't in a group with 4 or 6, and so on. A complete tournament schedule might look like this:
So here's the question: could you organize a tournament like this with 100 people, in groups of 10, for 10 weeks?
Because if you could, you could get published in a Computer Science paper. Whether or not its even possible to schedule such a tournament is an open problem.
For Solving Hard Problems, we have to write a program that takes three numbers
and either prints a schedule for a social golfing tournament, or tells you its impossible.
It's a really cute problem. Hopefully in a few days, when it's done and gone, I can write about how I wrote the program. In the meantime, how would you go about it?
I can't think of anything less intellectually stimulating than writing computer code for 7 hours a day.
After some thinking, my guess was they were probably confusing programming with data entry. Moments like these make me realize how much I take computer literacy for granted, especially among older folk. The Supreme Court makes similar mistakes, to much lulz.
I frequently find it helpful then to describe a problem that we work on, since lots of them can be easily described without mathematical notation. One of these has been a real hair-puller these last few days, called the Social Golfer Problem.
Problem Statement
The premise is this: you're organizing a golf tournament with 9 people in it. They play every week in groups of 3, and want to play for three weeks.
Here's the catch: they are social golfers, meaning if possible, they never want to play with the same people twice. Your job is to organize the tournament; you have to arrange who plays with whom every week.
So rather than use names, we'll just use numbers. The first week could look something like this:
| Group 1 | Group 2 | Group 3 | |
| Week 1 | 1 2 3 | 4 5 6 | 7 8 9 |
Since players 1, 2, and 3 are playing together in the first group, next week you need to organize the tournament a little differently to make sure 1 isn't in a group with 2 or 3, 5 isn't in a group with 4 or 6, and so on. A complete tournament schedule might look like this:
| Group 1 | Group 2 | Group 3 | |
| Week 1 | 1 2 3 | 4 5 6 | 7 8 9 |
| Week 2 | 1 4 7 | 2 5 8 | 3 6 9 |
| Week 3 | 1 5 9 | 2 6 7 | 3 4 8 |
So here's the question: could you organize a tournament like this with 100 people, in groups of 10, for 10 weeks?
Because if you could, you could get published in a Computer Science paper. Whether or not its even possible to schedule such a tournament is an open problem.
For Solving Hard Problems, we have to write a program that takes three numbers
- g - the number of groups in a week.
- s - the size of each group.
- w - the number of weeks.
and either prints a schedule for a social golfing tournament, or tells you its impossible.
It's a really cute problem. Hopefully in a few days, when it's done and gone, I can write about how I wrote the program. In the meantime, how would you go about it?
April 29, 2010
Videos with me!
ME ME ME! <STOP>
MY GAME IS BETTER <STOP>
THE GAME I MADE WITH MY TEAM <STOP>
I WILL TRY TO WRITE MORE, FEWER VIDEO-ONLY POSTS <STOP> UNLESS OF COURSE YOU LIKE VIDEOS <STOP>
MY GAME IS BETTER <STOP>
THE GAME I MADE WITH MY TEAM <STOP>
I WILL TRY TO WRITE MORE, FEWER VIDEO-ONLY POSTS <STOP> UNLESS OF COURSE YOU LIKE VIDEOS <STOP>
April 17, 2010
On Programming Interviews
Lots of great things have been written on the subject of programming interviews, but since I'll be entering the workforce very soon, I've taken away a few notes on how I would like to conduct them in the future, having just run the job search gauntlet.
Regarding phone screens, I learned a lot from Steve Yegge's post on his process. To summarize, he believes the candidate should demonstrate some basic proficiency and understanding in five areas to get the on-site: coding, OO design, scripting/regexes, data structures, and binary. It's alright if the candidate struggles a little, but if their answer to 'describe a function to sort an array of integers' is 'Collections.sort(array),' you might want to think twice about bringing them in.
Another advantage of living in 2010 is that we can actually see some code during a phone screen: one interviewer had me use EtherPad while on the phone with them, and I would probably do something similar.
More generally, diversity in the phone screen process will help you eliminate candidates who can talk big in one or a few fields, but don't have (or can't form) a more complete picture of what's going on.
If the candidate makes it to on-site, I would extend the diversity principle, but probably ask a few questions not listed above (if they demonstrated that they can write a regular expression in the phone screen, they don't need to show me one on-site). Here you could look at another round of fun brain-warpers that Joel Spolsky points out: pointers and recursion. I would love to write out a few problems as he has that just show they can read/write programs that use these techniques.
Brain teasers are a contested form in the interviews, but I love them too. Well, good ones anyways. I would like a candidate who smiles when they know a puzzle is headed their way. They would be very hintable, so I'm not anticipating an 'aha!' moment. An example of one of these that I think would rock, comes from Skorks:
Now I've written about it, I probably wouldn't use it. A risk you run with any type of programming question that is meant to challenge is that they've run into it before, or researched the standard questions before arriving. While there's nothing wrong with researching beforehand, you probably want to see the candidate think, not just what they can remember. For this reason:
A few more notes:
The only flaw in my plan is, with all the material I've mentioned, I'd probably need more than 45 minutes to get a feel for a candidate, and I doubt I'd be given more than that at a time. I'll have to find a way to resolve this ^_^
Regarding phone screens, I learned a lot from Steve Yegge's post on his process. To summarize, he believes the candidate should demonstrate some basic proficiency and understanding in five areas to get the on-site: coding, OO design, scripting/regexes, data structures, and binary. It's alright if the candidate struggles a little, but if their answer to 'describe a function to sort an array of integers' is 'Collections.sort(array),' you might want to think twice about bringing them in.
Another advantage of living in 2010 is that we can actually see some code during a phone screen: one interviewer had me use EtherPad while on the phone with them, and I would probably do something similar.
More generally, diversity in the phone screen process will help you eliminate candidates who can talk big in one or a few fields, but don't have (or can't form) a more complete picture of what's going on.
If the candidate makes it to on-site, I would extend the diversity principle, but probably ask a few questions not listed above (if they demonstrated that they can write a regular expression in the phone screen, they don't need to show me one on-site). Here you could look at another round of fun brain-warpers that Joel Spolsky points out: pointers and recursion. I would love to write out a few problems as he has that just show they can read/write programs that use these techniques.
Brain teasers are a contested form in the interviews, but I love them too. Well, good ones anyways. I would like a candidate who smiles when they know a puzzle is headed their way. They would be very hintable, so I'm not anticipating an 'aha!' moment. An example of one of these that I think would rock, comes from Skorks:
Write a quine, in whatever language you like (for those who don't know, a quine is a program that prints its own source code without reading itself).
Now I've written about it, I probably wouldn't use it. A risk you run with any type of programming question that is meant to challenge is that they've run into it before, or researched the standard questions before arriving. While there's nothing wrong with researching beforehand, you probably want to see the candidate think, not just what they can remember. For this reason:
- Pick nonstandard problems. For coding samples, probably avoid direct library functions, or anything from here. They should be simple, so maybe library functions with a twist. A favorite of mine was "write a function that takes a string, and returns whether the braces, brackets and parenthesis are matched." Challenging, but appropriate, and more applicable to any job than reversing a string.
- Have backups. One interviewer asked me what a good data structure would be for the search function of an address book. Given that I'd just finished the Facebook Breathalyzer puzzle, we were finished with what might have been twenty minutes of material in five.
A few more notes:
- I personally don't like whiteboard coding. I get nervous, can't edit/iterate the function rapidly, and can't go at an appropriate speed. So when my time comes, I might minimize that. Regardless, you can't be an actor unless you audition, so it'll stay.
- A short quiz, on paper, would probably be included. This wouldn't be multiple-choice or anything silly, just a block of code, and ask the candidate to comment on all of its qualities.
The only flaw in my plan is, with all the material I've mentioned, I'd probably need more than 45 minutes to get a feel for a candidate, and I doubt I'd be given more than that at a time. I'll have to find a way to resolve this ^_^
April 8, 2010
Software and Evolution
I think the software is growing, and will continue to grow, the way lifeforms have grown and evolved on Earth. By this I mean we started with a single ancestor, likely of a few proteins or perhaps a single cell, only to become a planet housing humans, echidnas, sponges, fungi, insects, trees, and more.
This mostly comes to mind when I look at essays like this series, by Mike Taylor, on how so much of coding these days is just playing plumber between various libraries, fixing leaks and disasters that occur when the piping isn't perfect. The argument is stated well by jdietrich commenting on the story (where else?) on Hacker News:
I happen to agree with most of the posts, but their symptomatic of something that's been on my mind: our code is really inefficient. But more importantly: that's okay, and further, we will have to live with it in order to reach software at the level that humans are at biologically.
Allow me to clear up the mapping. When we started with computers, we wrote in raw, unadulterated binary. Every machine instruction was treasured, coddled, and several amazingly clever hacks were developed so operations could use minimal resources.
This was a necessity! We had to! But then we moved up to assembly, then the Capital Languages (FORTRAN, COBOL), and so on, until computers got powerful enough that we could afford ourselves some abstractions. What level of abstractions? Imagine how Mel the Real Programmer and other hackers of the binary era must feel when we're using languages with immutable strings, and someone writes code like:
String container = "";
for (String suffix : suffixes)
container += suffix;
return container;
In which every iteration of the loop allocates a new string! And the code doesn't render the program unusable!
How does Mel feel? Probably how a bacteria (or other single-celled organism) would feel when I scratch an itch, and kill or damage hundreds of skin cells ostensibly for nothing.
Single cell organisms are still with us, and will almost certainly outlast us. We still have them in programming as well. To this day, if you want to really bust out the performance, you still gain lots by living close to the metal: I know a student in the introductory graphics class who implemented his linear algebra package by including x86 in his C. And almost all projects for my combinatorial optimization class are done in C only because, true or not, we believe "it's the fastest." (it is really fast).
The truth is, while people are still busting out assembly and squeezing whatever hardware gains they can, most of us can now get away with being pretty wasteful. And its the only way we can build the truly large, monolithic systems people pay big money for.
What am I trying to communicate with this metaphor?
First, stop arguing that speed be the limiting factor of a language or technology's eventual success. Every abstraction we use today (structured programming, object-orientation) was painfully slow during its introduction, but it will be one of these abstractions that will be the key to the next step in software evolution.
I recognize there are many good arguments against the use of functional programming, logic programming, and other alternate paradigms. Having speed comparable to other non-C languages today and calling it slow is not one of them.
Second, the diversity of software will propagate. Bacteria, fungi, plants, and eagles all live in radically different ways. Learn this and love it. Saying 'my form of programming is the real way' is like saying fungi are a real life form, but plant life isn't. Embedded systems have different needs than white-collar users of 'enterprise' software, different than logicians.
Finally, as it relates to Mike Taylor's article, what we are seeing now with library hell is the bad mutations of software evolution, the ones that will die out until we figure out how to do it right. If software at this point is at a jellyfish level, us sorting out library or framework programming are all the failed experiments to grow bones, gills, feet, and wings. One of them will work eventually, but lots and lots of our software will die until it does.
This mostly comes to mind when I look at essays like this series, by Mike Taylor, on how so much of coding these days is just playing plumber between various libraries, fixing leaks and disasters that occur when the piping isn't perfect. The argument is stated well by jdietrich commenting on the story (where else?) on Hacker News:
My biggest gripe with modern programming is the sheer volume of arbitrary stuff I need to know. My current project has so far required me to know about Python, Django, Google App Engine and it’s datastore, XHTML, CSS, JQuery, Javascript, JSON, and a clutch of XML schema, APIs and the like.Don’t get me wrong, I’m grateful for all of it, but it just doesn’t seem like what I was promised when I followed SICP for the first time. It just feels like I spend most of my time scouring through documentation and trying to remember umpteen different sets of syntax and class names rather than actually thinking in code.
Back in ye olden days, most programming tasks I performed felt quite natural and painless, just a quiet little chat between me and the compiler. Sometimes longwinded, sometimes repetitive, but I just sat and though and typed and software happened. The work I do these days feels more like being a dogsbody at the tower of babel. I just don’t seem to feel fluent in anything much any more.
We talk about ‘flow’ quite a lot in software and I just have to wonder what’s happening to us all in that respect. Just like a conversation becomes stilted if the speakers keep having to refer to their phrasebooks and dictionaries, I wonder how much longer it will be possible to retain any sort of flowful state when writing software. Might the idea of mastery disappear forever under a constant torrent of new tools and technologies?
I happen to agree with most of the posts, but their symptomatic of something that's been on my mind: our code is really inefficient. But more importantly: that's okay, and further, we will have to live with it in order to reach software at the level that humans are at biologically.
Allow me to clear up the mapping. When we started with computers, we wrote in raw, unadulterated binary. Every machine instruction was treasured, coddled, and several amazingly clever hacks were developed so operations could use minimal resources.
This was a necessity! We had to! But then we moved up to assembly, then the Capital Languages (FORTRAN, COBOL), and so on, until computers got powerful enough that we could afford ourselves some abstractions. What level of abstractions? Imagine how Mel the Real Programmer and other hackers of the binary era must feel when we're using languages with immutable strings, and someone writes code like:
String container = "";
for (String suffix : suffixes)
container += suffix;
return container;
In which every iteration of the loop allocates a new string! And the code doesn't render the program unusable!
How does Mel feel? Probably how a bacteria (or other single-celled organism) would feel when I scratch an itch, and kill or damage hundreds of skin cells ostensibly for nothing.
Single cell organisms are still with us, and will almost certainly outlast us. We still have them in programming as well. To this day, if you want to really bust out the performance, you still gain lots by living close to the metal: I know a student in the introductory graphics class who implemented his linear algebra package by including x86 in his C. And almost all projects for my combinatorial optimization class are done in C only because, true or not, we believe "it's the fastest." (it is really fast).
The truth is, while people are still busting out assembly and squeezing whatever hardware gains they can, most of us can now get away with being pretty wasteful. And its the only way we can build the truly large, monolithic systems people pay big money for.
What am I trying to communicate with this metaphor?
First, stop arguing that speed be the limiting factor of a language or technology's eventual success. Every abstraction we use today (structured programming, object-orientation) was painfully slow during its introduction, but it will be one of these abstractions that will be the key to the next step in software evolution.
I recognize there are many good arguments against the use of functional programming, logic programming, and other alternate paradigms. Having speed comparable to other non-C languages today and calling it slow is not one of them.
Second, the diversity of software will propagate. Bacteria, fungi, plants, and eagles all live in radically different ways. Learn this and love it. Saying 'my form of programming is the real way' is like saying fungi are a real life form, but plant life isn't. Embedded systems have different needs than white-collar users of 'enterprise' software, different than logicians.
Finally, as it relates to Mike Taylor's article, what we are seeing now with library hell is the bad mutations of software evolution, the ones that will die out until we figure out how to do it right. If software at this point is at a jellyfish level, us sorting out library or framework programming are all the failed experiments to grow bones, gills, feet, and wings. One of them will work eventually, but lots and lots of our software will die until it does.
April 6, 2010
Common Lisp
I've been playing around with Common Lisp recently, using Practical Common Lisp and Let Over Lambda as guides (not gonna lie, having LOL on the spine of your book is wonderful). Last year when I went through my Scheme phase (the original URL of this blog was littleschemer.blogspot.com), I never thought I'd see the day that I'd switch sides.

FWIW, this is my iPhone background image.
I do feel like a traitor though, since even though I'm a theory-head and advocate of FP, I'm loving Common Lisp. There are a few reasons for this:
This isn't to say its all peaches and cream: I still prefer Scheme's single namespace over Common Lisp's, I prefer Scheme's naming conventions (map vs. mapcar, or worse, loop for elem in list collecting). And issues with lambdas, namely sharp-quoting and not being able to place functions in the function position (especially after learning the beauty of Scheme's semantics so well last semester) still throw me for a loop.
But after a year of mounting tension with the residents of Shelbyville, I realize they've got quite a bit right ^_^.

FWIW, this is my iPhone background image.
I do feel like a traitor though, since even though I'm a theory-head and advocate of FP, I'm loving Common Lisp. There are a few reasons for this:
- Simpler macros. I'll bet some hardcore Schemers will disagree with me on this, but I feel that defmacro is much, much simpler to learn than syntax-case, and syntax-rules always leaves me wanting more. Maybe I'm deficient, but I took to defmacro immediately, whereas when I want to do anything non-trivial in Scheme, I feel myself always going back to Dybvig's explanations, taking far longer than I'd like.
While in principle I'm for hygiene as the default, it's not too big an issue in practice. Hoyte gives a great little macro (one of the first in his book) that ensures you fresh variables whenever you want them, without even having to declare them! - Language libraries. CL comes with every function you could ever want. It comes back to what Peter Norvig said in Paradigms in Artificial Intelligence Programming (paraphrasing): Scheme is one of the smallest languages to define (< 50 pages), whereas CL is one of the largest (> 1200 pages).
While some Schemes provide these, since they aren't part of the standard you aren't guaranteed anything across implementations. In fact, my favorite Scheme in terms of libraries (good ole' PLT) even broke across versions when they enforced module declarations at the top of every file.
Besides, once a Scheme gets these, they stop wanting to be called Scheme.
This isn't to say its all peaches and cream: I still prefer Scheme's single namespace over Common Lisp's, I prefer Scheme's naming conventions (map vs. mapcar, or worse, loop for elem in list collecting). And issues with lambdas, namely sharp-quoting and not being able to place functions in the function position (especially after learning the beauty of Scheme's semantics so well last semester) still throw me for a loop.
But after a year of mounting tension with the residents of Shelbyville, I realize they've got quite a bit right ^_^.
Subscribe to:
Posts (Atom)
