The best kittens, technology, and video games blog in the world.

Thursday, September 21, 2006

Fight to the death between Ruby and Python

Peeking Lunu by special combo from flickr (CC-NC-ND)Recently there has been a big surge in popularity of both Ruby and Python. And with it came countless discussions on which one is better than the other. Volume of such discussions baffles many people, who think that the whole thing is pointless because the differences are very tiny, and both languages are converging anyway into some sort of Rython or Puby.

However this is completely backwards - the fight is so fierce because Ruby and Python are pretty much identical, not in spite of it.

There is a well-established principle in ecology called "competitive exclusion principle" which says that no two species can occupy the same ecological niche for a long time. They either get specialized, or one of them becomes extinct. A similar mechanism exists in many other fields - including programming languages. If you have two languages - like Ruby and Python, competing for exactly the same ecological niche, and one of them marginally better than the other, what is the purpose of the other language's existance ? Even if the difference is really tiny, who would want to use a less powerful language ?

If the difference in power is really tiny, like in case of Ruby versus Python, it would be reasonable to guess that it will take a very long time before one kills the other. However, "evolutionary fitness" of a programming language has two components:

  • Power (expressiveness, performance etc.)
  • Popularity (which results in more libraries, better tools, fewer bugs etc.)
This greatly amplifies effects of competitive exclusion - if one language is gaining popularity because of somewhat better fitness, it gets more libraries etc., what increases difference in fitness even more, and in no time we have a clear winner.

Now Ruby and Python are almost identical. If you asked a Ruby programmer to take any language other than Ruby, Python would be the most popular choice. Likewise, if a Python programmer had to take a different language, they would most likely take Ruby. And in a few years one of them will survive and the other will either die or will get relegated to a small niche, and which of them survives depends mostly on which of them gets marginally better fitness right now - Ruby is a bit more powerful, Python is a bit more popular, and the situation is very unstable. The small difference today will get amplified.

So if you want Python to win:
  • Reduce the gap in power - make Python support blocks, get rid of explicit self and get better support for metaprogramming. If Python did it a few years ago, nobody would have heard of Ruby. If you don't like blocks, metaprogramming and implicit self, you don't have to use them - simply consider them a price to pay for making Python the next big thing. If it gets them today, it is still very likely to win.
  • Reverse gap in power - can Python express certain things a lot better than Ruby ? Write useful programs and libraries that would be much more difficult without this power and popularize them. Attack the enemy where it is strongest.
  • Make the most of greater popularity - work on useful things that are very useful but hard to reproduce with smaller user base - like Psyco and stable ports to JVM and .NET.
And if you want Ruby to win:
  • Increase power advantage - take powerful features from Lisps, Smalltalk, Erlang, Haskell or whatever, and integrate them with Ruby - making different paradigms work together is one of the greatest strengths of Ruby, so make use of it. Make metaprogramming and DSLs easier by writing metalibraries and tutorials.
  • Make the most of greater power - Ruby was able to get the momentum with Ruby on Rails, which would be very difficult to replicate in other languages. Ruby makes writing powerful embedded DSLs very easy, and powerful embedded DSLs are a potentially huge and pretty much unfilled niche. Take it and use it as a leverage to get more popularity.
  • Minimize effects of lesser popularity - if Python has a good library for something, simply recode it to Ruby and call it version 1.0. The languages are so similar that you should be able to do it in no time. You can get it more Ruby-like (with blocks etc.) later.
  • There are some things in which current implementation of Python is simply better - Ruby 2 is trying to fix many of those (you cannot have Ruby Psyco without YARV). If you can - help with Ruby 2.
And in either case:
  • Steal every single cool feature from the other language, indiscriminately. You can deprecate the ones that didn't work later.
And in the end, whether Rython or Puby wins, you will feel at home having a great language.

Tuesday, September 19, 2006

My first impressions of Erlang

Father & son by Jeremy_K from flickr (CC-NC-SA)There was so much buzz about Erlang on reddit and elsewhere lately that it all made my actually try it out. The first impressions - contrary to the rumors, it is definitely not The Next Big Thing, and well - it simply sucks.

Now a short list of things that really suck about Erlang - just the stuff you'll encounter in the first few minutes:

  • Lack of basic Unix decency - no man page for erl or erlc (at least in the Ubuntu package), they do not accept --help, one cannot exit by ^D. These are very basic things. If they're broken, people are likely to leave.
  • Interpreter is terribly underpowered - in most languages you can write pretty much any code in an interpreter. In Erlang you cannot even define functions there. Of course there is no online help. At this point I was pretty much willing to leave, but I forced myself to go a bit further.
  • You actually have to compile your code, by hand, before you can use it - if you wrote a hello_world.erl, you have to compile it using erlc, then run erl, and call hello_world:whatever. If you made a mistake, you need to exit the main loop (by halt()., not ^D, to waste more of your time), correct the mistake, recompile, and start again. It is so unbelievably lame that I can't imagine anyone except for C++ programmers being able to put up with it.
  • Don't Repeat Yourself ? Nah - In Erlang you have to repeat yourself a lot. In every file you need to write module name and list of all exported functions. And when you use them you have to prefix them by module name anyway. So even though foo:bar() simply has to be function bar in module foo, you have to explicitly list in on the export list in foo.erl anyway.
  • It is not even marginally object-oriented. I'm not talking about having to hack object-orientation on top of it - it's just that basic object do not know what they are. Lists of numbers cannot tell themselves apart from strings and so on. Writing "Hello, world\n" out will actually output [72,101,108,108,111,44,32,119,111,114,108,100,10].
  • String support is horrible - As I said, strings do not exist as first-class objects, they are emulated by strings. So no Unicode. No regular expressions. No high-level string functions. We're back to C.
  • Not Invented Here Syndrome - Erlang tries it very hard to be different than everything else. Syntax is different (somewhat Prolog-like), Unix conventions are disregarded, standard data types (strings, arrays and hash tables) are not provided, even io:format uses its own format strings instead of following printf. You cannot simply take a look at a few examples and start writing useful programs like with Ruby, Python or even Java. Not following conventions wastes everyone's time.
I didn't even get to distributed computing, as I was hardly able to write an useful single-thread program. On the other hand my first Python program was pretty useful - and all I did was just sitting down, typing some code, and it worked.

Now I don't care much about Erlang, but those of you that do, here's my proposal:
  • Conform to the basic Unix conventions like ^D, man pages, and --help.
  • Throw away the old syntax and add something Python/Ruby-like. This isn't Lisp - weird syntax doesn't give you anything. Writing a decent parser in ANTLR is just one evening, and you don't have to throw away the old syntax, just provide an alternative. When you're at changing syntax, make it possible to access full language from the interpretter and limit the repeating yourself part a bit.
  • Write a decent standard library - real strings with Unicode (not this lists of integers hackery), regular expressions, arrays, hash tables and so on.
  • There is absolutely nothing that forces compilation by hand. Make it automatic by default.
Such changes won't interfere with the fault-safe distributed computing part even the tiniest bit. And if Erlang stays the way it is now, I think it is extremely unlikely to get out of its telecom niche.

Friday, September 15, 2006

Attention Deficit Disorder 2.0

Just Like Cotton... by slight clutter from flickr (CC-NC-ND)I've noticed a worrisome pattern about website discovery services like digg, reddit and StumbleUpon. They almost invariably return stories that are readable in a very short time, with minimum of concentration, and they are usually funny trivia, American politics (typically from "liberal" point of view) or technology news.

Just take a look at reddit top 10 right now:

  1. video of 500kV switch opening (9 sec) - an amusing video, digestible in literally 9 seconds.
  2. FCC orders media ownership study destroyed... guess what its conclusions were? - news on politics, "big media and FCC are evil", digestible in 1 minute
  3. Unbelievable microscopic art - cute trivia, digestible in 30 seconds
  4. Default Password List - a list with high omg factor, very few will actually use it, digestible in 5 seconds
  5. Don't trash broken stuff; send it back - "how to get something for nothing" story, digestible in 1 minute, very few people will do it, most just read it for fun
  6. The Stormtrooper Effect and The Inverse Ninja Law - another funny stuff digestible in 1 minute
  7. Won't Deploy? Can't Deploy.There are no more troops to send to Iraq. - politics, "Bush and war in Iraq are evil", digestible in 1 minute
  8. A 82 year old widow rented a rotary dial telephone for 42 years, paying AT&T more than $14,000 in the process - funny trivia, digestible in 30 seconds
  9. Right-wingers Reject Senate Report and Invent New Saddam- Al-Queda Myth - politics, "Bush and right wing bloggers are evil", digestible in 1 minute
  10. LETTER: Powell Blasts Bush Plan To Authorize Torture - politics, "Bush and war in Iraq are evil", digestible in 1 minute
So 4 times American politics and 6 times humor. On digg you get less politics and more technology news, but the pattern is similar - when you use such services, you are switching your brain from one subject to another almost every half a minute. And these services are immensely popular, millions of people are getting their brain into state of very rapid subject switching every day and spending hours in it. The switching rate is way higher than it was with press or television, which are already promoting short attention spans.

Now how likely is such treatment to increase attention deficit problems after long term usage ? I have no idea, but a few studies already show that there is a global decrease in attention spans, so it is not totally unlikely.

And the real question - should you keep using digg/reddit/StumbleUpon ? Are you sure how it influences your mental abilities ? Are you worried at least a little bit ?

Thursday, September 14, 2006

Human rights crisis in Germany

May&Momo by Jeremy K from flickr (CC-NC-SA)Everybody is so concerned about genocides in Iraq and Liban, rise of neocon fascism in USA and RIAA's legal terrorism that they seem to miss a much greater human rights crisis happening in Germany.

Basically in Germany it is illegal to buy or sell anything. You cannot buy food, you cannot buy coffee, you cannot buy computer hardware, you cannot buy beer, you cannot buy anything at all ! The only thing you can legally do is wait until you die of hunger, dehydration, or boredom.

How come Germans aren't all dead yet ? The regime makes a few exceptions. It seems that you can buy stuff at designated hours - 8 to 20 Monday to Saturday, at least unless this is some sort of "no stuff for you" day, which they have plenty and at completely arbitrary times (some of them are holidays, but usually it's just some random day). That's about 35% of the total time. Of course if you wake up in the afternoon like pretty much every hacker, you can hardly shop at all ! Even in Iraq you can buy food every day. The regime used to be even more evil a few years back, forcing everything to close before 18:30 and even earlier on Saturdays.

And the shops suck so much. Instead of real shops they only have really tiny ones that hardly have anything. You need to visit at least 10 such shops in different parts of the city to get anything, and probably on two different days, because they're not open long enough to do so in a single day. In a sane country you go to a shopping mall, get stuff, and you're done in half an hour. Oh yeah, and they don't take VISA.

Do not think that this insanity is limited to trade - the whole country is screwed up like that. Is it any wonder that Germany is in constant state of economic crisis and huge unemployment ?

And by the way, I've finally left Germany and moved to some saner country :-)

Sunday, September 03, 2006

Mary Sue Fortress

Kumanoko by Seattle Roll from flickr (CC-NC-ND)I recently found a copy of "Digital Fortress" by that guy who wrote Da Vinci Code lying around. Now as I was a bit tired with writing thesis, I grabbed it and started reading. And I must say - it's the worst book I've read since high school. Well, the worst first few chapters at least, because I couldn't make myself go any further than that.

Now I'm not going to flame it due to having less clue about cryptography than Internet Explorer team about CSS. Or for having absolutely no clue about languages and trying to sound smart by saying random crap about them (yeah, because Chinese-speaking person cannot tell Japanese text for Chinese). What I am going to fflame it is rampant Mary Sue'ism.

Basically the main two characters are Mary Sue and Wesley Crusher. Basically they are simply the most intelligent, cool, popular, beautiful, flawless and what-not characters ever, just because the author was too lame to use realistic characters. I wonder how did he even got someone to publish his book, as far as I can tell he would be banned on average Xena/Gabrielle alt forum writing such crap.

Ok, now the citation time for the Mary Sue:

The guard admired Mary Sue as she began her walk down the cement causeway. He noticed that her strong hazel eyes seemed distanttoday, but her cheeks had a flushed freshness, and hershoulder-length, auburn hair looked newly blown dry. Trailing herwas the faint scent of Johnson's Baby Powder. His eyes fellthe length of her slender torso -- to her white blouse with thebra barely visible beneath, to her knee-length khaki skirt, andfinally to her legs . . . Mary Sue's legs.
Hard to imagine they support a 170 IQ, he mused tohimself.
He stared after her a long time. Finally he shook his head ass she disappeared in the distance.
And the Wesley Crusher:
Wesley Crusher. The only man Mary Sue'd ever loved. The youngest full professor at Georgetown University and a brilliant foreign-language
specialist, he was practically a celebrity in the world of academia.
Born with an eidetic memory and a love oflanguages, he'd mastered six
Asian dialects as well as Spanish, French, and Italian. His university
lectures on etymology and linguistics were standing-room only, and he
invariably stayedlate to answer a barrage of questions. He spoke with
authority and enthusiasm, apparently oblivious to the adoring gazes of
his star-struck coeds.
Wesley Crusher was dark--a rugged, youthful thirty-five with sharp green eyes
and a wit to match. His strong jaw and taut features reminded Mary of
carved marble. Over six feet tall, Wesley Crusher movedacross a squash court
faster than any of his colleagues couldcomprehend. After soundly
beating his opponent, he would cool off by dousing his head in a
drinking fountain and soaking his tuft ofthick, black hair. Then,
still dripping, he'd treat hisopponent to a fruit shake and a bagel.
But of course it's not like the characters do not have any flaws:
In Mary Sue's eyes, Wesley Crusher was as close to perfect as she could imagine. He only had one unfortunate quality; every time they went out, he insisted on picking up the check. Mary Sue hated seeing himlay down a full day's salary on dinner for two, but Wesley Crusher was immovable. Mary Sue learned not to protest, but it still bothered her. I make more money than I know what to do with, she thought. I should be paying.
I rest my case.

And I'm not going anywhere close to Da Vinci Code or any other stuff by that guy. I'd much rather spend my time with Harry/Draco slash than that.