Archive for April, 2008

Javascript will be the Next Big Language

Wednesday, April 23rd, 2008

I’m on JavaScript kick lately. Or rather, I have been rediscovering it ever since I read the series of Steve Yegge’s blog posts on JS and Rhino and his predictions for the next big language. I really think he is right - JS will be the next big thing that will trump Ruby from it’s pedestal or at least become its viable competitor as the next big dynamic scripting behemoth. Why? I think a better question is: why not? It almost seems like this language is destined for greatness.

For one, JavaScript or rather ECMAScript is really a kick-ass language if you look at it objectively. When I say JavaScript most people automatically think about the client-side, browser dependent, inconsistent scripting language which only works half of the time. But this is not really the fault of the language but inconsistent implementation of the DOM model across different browsers.

Internally the language is really consistent, flexible, readable and fun to use. Not only does it have most of the cool features that are all the rage now (ducktyping, closures, variadic functions, prototypes, metaprogramming end etc..) but reads a lot like C. The syntax is full of the familiar and lovely brackets and semicolons that we all know and love (or hate) and all the control sequences and language constructs follow the familiar C patterns. Coding in JavaScript is really a lot like coding in Java only 5 times less verbose which is a good thing.

And when it comes to shuffling around HTML or XML data there is no other language that is both so good at it, and so well documented. We have been using it for that purpose decades now and nothing else compares. No other language can be used int the online so effectively and seamlessly.

Also, Javascrip has something that neither Python nor Ruby possess - a real spec. So it is really a good language - a Language with capital L. It is just burdened with a bad stigma of being a browser specific toy language.

This stigma is slowly dissipating as the Web 2.0 craze is raging on. I don’t care who you are right now - if you are doing any web development right now, you have to deal with Javascript whether you want it or not. You can avoid it, you can claim you are server side guy but if you want to be competitive right now your web app needs to use AJAX and if it is, then Javascript is becoming a big internal part of your code base. You can hide behind a framework, and have it generate AJAX code for you the way RoR does, but sooner or later you will have to do something complex and will end up hacking on js files. Whether you love it or hate it - you will be exposed to it at some point.

So your code is now roughly half Javascript and Half something else which is a bit messy, but that’s Web 2.0 for you. Does it have to be that way though? Of course not. You don’t need a dedicated client side language ad another dedicated server side language. You could really do all your scripting on both sides with Javascript. Yes, Server Side Javascript is not a joke or some pipe dream - it is reality. Believe it or not, but there is a lot of development going on in this area - there are tons of projects out there which use JS on the server side.

These projects range from very simple to very complex full featured solutions. For example, mod_js is an Apache module loosely based on Perl’s CGI.pm which implements ECMAScript on the server side. It is astonishingly simple, and compact but also very immature project.

If you want something more robust and mature there is Jaxer - a self contained Java based server which supports server side scripting in Javascript. The whole idea behind this environment is unifying your code base. With Jaxer you can use the very same language to query the database, dynamically rearrange the HTML output, and make asynchronous calls back to the server. Added bonus is that it is bundled with the very popular Aptana IDE (aka. the Eclipse for web designers) which means it is already near ubiquitous.

If you are allergic to Eclipse and it’s forks and you like NetBeans then Phobos is probably what you will want to sink your teeth into. It uses Glassfish server and uses Javascript as it’s default server side language. Same concept, different approach. The project seems to be mature, well supported and have a big community.

Want more? Theres Helma which is a Rails like framework which leverages server side Javascript and Rhino. The whole thing runs in the JVM and uses Jetty as the default, self contained web server - but you can also put it behind Apache or IIS if you want. How come you can go wrong with a combination like that? You get a MVC framework with a self contained server and set of useful tools and utilities that only requires you to have a basic JVM installed. You get to script it with the dynamic and flexible language that requires no compilation, and no SDK. You get the entirety of the Java API at your disposal courtesy of Rhino. Not only that, but you can simply drop in your custom precompiled Java libraries and classes and seamlessly integrate them into your project.

But there is more - recently I spotted another interesting project called Junction. Like Helma it is a Rails like MVC framework that uses Rhino but in addition, it also has a built in support for Google Gears. This means that apps built on the Junction framework get to benefit from the offline persistence features offered by the Google technology.

There is all this development going on out there. It’s not very visible yet - most of it is somewhat behind the scenes. But it’s like that distant rumbling before the storm. You know something big is coming. Just look around.

You want to develop rich client interfaces? There’s XUL and Adobe Air for you - both using Javascript at their core.

You want dynamic web UI framework? There is JQuery, Prototype, Dojo, Google Web Toolkit and YUI just to name few.

Want to use Java API? Use Rhino. Want to tap into the richness of Microsoft CLR and interact with the rest of .NET ecosystem? Theres JScript.NET. You want to do some native scripting on MacOS? There is Javascript OSA.

You want to add oflline persistence to your web applications? You need Google Gears which is also using Javascript.

The language is everywhere. Everything that is new, that is hot and that relates to the web is at least touching or benefiting from it. Every developer will see it, and work with or alongside it sooner or later. It’s ubiquitous.

The pieces are slowly falling in place and setting up the stage for the upcoming explosion. It’s no longer question of whether we will reach that critical mass, but when will it happen. We have the tools, we have the technology, we have the hook and the need (unifying the client and server side under one language) - now we just need to wait for the hype. And for that, we need branding. Steve Yegge talked about this during his Ted talk - we need to re-brand the language to make it more sexy. Everyone thingks that Javascript is a toy language, and ECMA sounds like a some sort of acne prescription so we need a new, cool name. We also have a good reason for re branding - the upcoming release of Javascrip2 standard which brings about many new features to the language such as classes, interfaces, namespaces, packages, destructuring assignments, structs, type declarations and more.

It is a bucket load of new features so why not start fresh, with a new sexy name and identity. I mean look at AJAX - the acronym really means “using the asynchronous calls in Javascript” but if you say it like that, people immediately fall asleep and run away. But AJAX is cool and sexy. Javascript can be to - and I predict it will be, sooner or later.

Cylons don’t use Backups

Tuesday, April 22nd, 2008

There are two storytelling crutches that often come into play to “hand wave” over some plot inconsistencies or explain something odd and unusual. One of them is called magic, and the other one is called technology. They are both used as explanations of improbable and impossible events which are supposed to help the viewers suspend their disbelief.

It is usually very easy to make viewers accept magical events. All you have to do is to make up some magical system and say “this is just how magic works in this mystical world”. After all, we don’t have magic in the real world, so we might as well go with it. As long as the rules governing this magical system seem logical, consistent within the story, and do not contradict themselves it is easy for us to accept it.

Technology tends to be used the same way. Unfortunately, unlike magic we are pretty good at science. A lot of viewers have scientific degrees and at the very lest, most people took a science class or two in school. So if you start bending and contradicting laws of physics, we can easily call you on it. When you introduce a futuristic technology it must not only be consistent, but also plausible. Of course if you are blatant enough about it, and make it obvious you don’t even pretend to be using “real science” you end up in the same realm as magic. For example Lightsabers are so far fetched that we just accept them even though it would be impossible to construct them. Same goes for various methods that allow spaceships to travel faster than light. We all know it’s impossible, but we agree on this convention because it makes the story more interesting. These devices have no scientific basis for them so they are really nothing more but techno-magic. But closer you show us something that looks and acts just like existing real world technology, we will sort-of expect it continue working within the same limitations and in the same way.

Having a degree in Computer Science and working in IT for a long time doesn’t help me suspend my disbelief when writers try to include technology in their stories without actually bothering to understand how it works in the real world. Usually any movie or show that features “hackers” or computer security experts and etc.. makes me roll my eyes so hard, and so often that it actually hurts. P Science Fiction often doesn’t cause as much eye strain for me - often because it’s usually pretty good about portraying science and technology in plausible way. Still, every once in a while even hard SF or Space Operas manage to drop the ball and annoy me with inane or poorly researched and thought out “future tech”.

For example, let’s take one of my all time favorites - Battlestar Galactica. The Cylon resurrection system that is an important part of the story has been pissing me off for a while now. I don’t have a problem with the system itself but it is portrayed as having an inherent flaw that more than once was used as a plot device. It’s just that the flaw is ridiculous, and it is almost inconceivable that no one ever worked out a countermeasure for it. Any engineer or sysadmin would ask two questions during his first visit to a Cylon resurrection shop - “how do you do backups?” and “What is the emergency restore procedure to the when a unit fails away from the ship without having a chance to transmit the latest state?”. Sad part is that it seems that no one ever thought about that.

For those of you who haven’t watched the series let me explain.

In the BSG universe, when an individual Cylon dies his or her consciousness is instantaneously transferred into a vat grown spare body which is kept on a specialized, well protected Resurrection Ship. The transmission seems to be instant, and happens at the exact moment of death but this process seems to have a limited range. This is why every Cylon fleet takes at least one Resurrection Ship with them wherever it goes. So far, so good - I don’t have a problem with that - in fact it is a pretty good system. Personally, I’d have a resurrection chamber on each Base Star and turn it into a distributed system, but I guess growing new bodies requires space and resources so centralizing this function is not such a bad idea.

The show however came up with an interesting idea. Want to truly kill your Cylon enemies in a way that prevents them from ever coming back? It’s easy as pie. All you have to do is to destroy the local Resurrection Ship and then simply do your thing. Yep, it’s that easy. Imagine being a Cylon and having to deal with that. If you accidentally die 10 feed beyond the range of the closest R-ship then BOOM! Permadeath! Your near immortality is over.

The sysadmin part of me reels in horror after hearing this. Who designs systems like this? What we have here is a permanent, irrecoverable data loss happening every time an expendable and temporary shell for your AI expires beyond the range of your wireless network. Thats is a criminally stupid design flaw - and one which could be easily fixed! Didn’t these people hear about backups?

Let’s think about it - the transmission of consciousness is almost instant. We have seen it on the show many times. Old body dies, and the Cylon wakes up in a vat of goo almost instantly. This tells me that it takes only a split second to send given Cylon’s memories and personality back to the resurrection ship, and few more seconds to actually upload it to a spare body. Since they are able to do this at all I think it is indisputable that heir consciousness can be fully digitized. There is this notion out there that digitizing human consciousness will never be possible because there is actually more to it than a mapping of neural connections and distribution of electric charges. I don’t know whether or not this is true, but obviously Cylon psyche can be transmitted digitally without any problems. If you can digitize something, you can back it up to permanent storage.

In other words, if Cylons have technology to upload the transmitted consciousness to a vat grown body, then they absolutely must have a technology to temporarily or permanently store this data on some sort of media. I mean it is a prerequisite - before you can put the consciousness in a body, you have to be able to store it somewhere. In fact, I imagine that the Resurrection Ships must be buffering these transmissions in some way before they do the body uploads.

For example, what happens if a Base Star is destroyed? Now you have instantaneous transmission from hundreds if not thousand Cylons streaming down from the wreckage, probably on the same frequency. What happens if the vats are not ready? What if there is a temporary power outage in the vat room? What if the prepared bodies turn out to be defective and need to be discarded? What if the transmission comes in with potential errors caused by outside interference? It’s just simple engineering concerns - you need to have a buffer which will hold the upload until the body is ready. Otherwise you would often miss the window of opportunity and consciousness transfers would simply get lost in space for silly reasons. Not to mention the need to check for transmission errors. It would be a pity to see a Cylon emerge from a vat half-retarded because the post-death transmission included static noise that could have been easily removed in some pre-processing CRC check.

So, if they are processing and buffering the signal there is no reason why they couldn’t just dump it into storage for safe keeping. What is the difference between storing it in memory for 20 seconds and saving it in storage for 3 days? Well, main difference is that the latter is cheaper than the former on all counts - at least by current technology standards.

So why not do a daily backup? Or even hourly incremental backup for that matter? Or even a continuous rolling sync to the R-Ship storage since it seems the consciousness transfer is almost instant? If the Resurrection Ship kept the “last good copy” of each Cylons consciousness then instead of permanent death, a stranded Cylon would simply loose last few hours or days of his/her life. If you would make Resurrection Ships sync up their backup data on regular basis, you now have a highly efficient distributed system that offers you virtual immortality. Permadeath would only be possible if someone would manage to track down all the Resurrection Ships with the copy of your consciousness.

I’ll go even further - why not allow Cylons to make emergency backups to personal storage they could then stow away in a safe place. Drop a thumb drive in a safe deposit box on Caprica before going on an important mission and you can be restored even if your whole fleet was wiped out.

So yeah, I don’t buy the whole “Oh noes, where is the R-ship? If we die now we die FOR REALS!” I just refuse to believe that a race of sophisticated intelligent machines would neglect something as important and basic as backups. It is a small thing, but it bugs the hell out of me.

Smart Business Move: Letting Viewers watch TV Shows Online

Monday, April 21st, 2008

In the past if you missed an episode of your favorite show you had very limited choices. If you had Tivo or a similar service you could just pray and hope it was smart enough to record it. You could also hope it was available on some sort of on-demand service provided by your cable. Failing that, you could either wait for a re-run, or go online and download the episode from your favorite P2P network. Added bonus was that the friendly folks who were uploading the shows usually grabbed them from HD feed, and were kind enough to remove commercial breaks. I did this myself several times for this or that show. There is just no way to prevent it.

At the time I used to wonder why the networks didn’t simply put the episodes online, complete with commercial interruptions. Since they already circulate in the wild, why not turn around and profit from it. This rejection of adopting a viable stream of revenue out of fear that it will make it easier for pirates to “steal it” seemed silly to me. I mean, some groups out there are able to start seeding an episode 15-20 minutes after it was aired - all they need to do is to grab the file from their VDR, and cut out the commercials. Not releasing a digital copy of your show didn’t necessarily impede their work.

Conversely, if you stream the episodes from the official website, surround them with one or two advertising banners and include commercial spots embedded in your stream, you are capitalizing on several of the 8 generatives Kevin Kelly talked about in his essay Better than Free. Since this is an official release the fans of the show know immediately where to find it (they can bookmark the page, instead of searching P2P networks), and furthermore they know the content is authentic and trustworthy which is not always the case with the less than legal sources.

Well, lo and behold - this idea is starting to take ground. This Friday I missed the new Battlestar Galactica episode and to my surprise I noticed that all 3 episodes of the new season are available via SciFi Channels Rewind service. Yes, the quality is low, and the commercial breaks are a tad annoying but you know what - I don’t really care. I just want to catch up with so that I can participate in online discussions and the obligatory Monday lunch hour BSG discussion at work. And for that the grainy, slightly above Youtube quality compressed FLV is just fine. Hell, it’s in fact more convenient since all I need to do is to click a button and watch. I don’t need to wait for the download to finish, and I don’t need to worry that part 5 of 6 will be taken down before I am able to watch it as it is often the case on the TV-Links like link services.

I wanted to commend Scifi and all the other networks which choose to follow this route. I’m glad people are slowly begging to see the light. When you put episodes online like this we all win! You get an extra stream of revenue and I get to watch my show whenever I want. This is exactly how you should combat piracy - compete with them on terms they cannot match. The streaming show on your website is official, safe, permanent and readily available when needed - it is better than free.

Is this an indicative of change? I don’t think it’s just Scifi that is doing this. I think ABC was doing something very similar for Lost episodes, although I’m not sure if they just offer the last episode, or all of them. So there are networks out there that are beginning to understand how to make a buck in the digital world, and that is filling me with hope. Perhaps future is not as bleak as we all suspected. )

Teaching about Programming: LOGO

Friday, April 18th, 2008

The semester is almost over. I was convinced that I will actually have one regular class in May before the finals, but I was wrong. The regular schedule at MSU ends on the 5th and then we go into the two week final examination period. Since I teach an evening class, I get to give the exam on May 13th which is I think the very last day of exams. So naturally I already have students clamoring that we should push the exam up.

One guy even told me he booked a trip on the 10th and he doesn’t know what to do now. Sigh… I could understand this if the official final exam schedule was not posted on the university website on like the first day of the semester. But it was, and I could have told him the exact date and time of the final on Sept 1 if he asked. Sigh… I had professors who didn’t even tell us when the final was - they expected you to look it up and show up at the right time, or they failed you. I sometimes wonder how some of these folks actually survive in college.

So I’m not moving the exam up (I’ll work with my “special” cases on individual basis, and figure out what to do with them) but since I only have 1 regular lab period left I think my students will get to skip the LOGO exercise. I actually never did this lab before and it was supposed to be sort of a test run. But they won’t have enough time. will need to skip it.

Back in February I asked you what programming language should we teach first to CS majors. We pretty much established that it is usually a good idea to start with a lower level language like C or C++ and then bump them up to something more friendly like Java or Python as needed. What do you teach non CS majors though? It is generally a good idea to expose people to programming to show them it is not some sort of scary arcane magic.

This is where LOGO comes in. It is a is a functional programming language considered to be a distant cousin of Lisp. It doesn’t share Lisp’s peculiar syntax though. It is actually very, very simple - it uses one word which usually take a single argument. There are no brackets, semicolons or fancy control structures. It supports very simple loops and naturally recursion (after all it is based on lisp) - which is probably not something I would show to my 109 class. Simple iteration though is probably something that they could handle.

I was planning to have them use Tortue which is a Java based app with a built in interpreter and a canvas for drawing shapes. I actually found it via the CMPT 109 community on blackboard and it seems for this purpose. It doesn’t support all of LOGO but it does support a significant portion. In fact, it makes the language even simpler. For example, it does not support the short versions of the keywords, or the square bracket notation, which make code more compact, but may impact readability if you are a fresh user.

I like it because it requires no installation (which is something students cannot do in the lab) and is astonishingly simple. Students simply type the code in the left pane, hit run, and the results are drawn on the canvas. Yes, logo programming revolves mostly around drawing shapes. Let me show you a very simple code snippet:

REPEAT 4
	FORWARD 100
	LEFT 90
END REPEAT

This little snippet for example will draw a 100 pixel wide square on the screen. Tortue basically only supports drawing functions and very basic arithmetic. Logo itself is actually full featured and can be used to solve complex problems, but drawing on a canvas is really it’s favorite thing to do.

I’m not exactly sure what kind of program I would assign them. Probably something really simple that could be accomplished even without loops. I was thinking along the lines of tetris blocks since there is more than one way to draw them. You can either use stacked squares, rectangles, or just draw them with a single continuous line.

Perhaps I’ll manage to squeeze this exercise in next semester. What do you think about this approach? I’m not really expecting to teach these people any hard core programming. I just want to expose them to coding, debugging and solving problems. Or is logo to complex? I know some teachers use the 3D Alice framework to teach these concepts. It was being pimped at the same community portal where I found Tortue and I actually saw Alice files all the computers in the adjunct office so someone out there is using it. I looked at that toolkit, the first impression kinda to my first time using Macromedia Flash - I was overwhelmed by it’s complexity. I had to look at the tutorials to actually figure out what was one supposed to, so I can only imagine how my students would feel.

In comparison, simple textual commands like FORWARD 100 or LEFT 90 don’t seem that bad. Which reinforces my long standing opinion that CLI interfaces are actually easier to learn. While a well designed GUI can be self explanatory and can be learned by instinct, complex ones quickly become overwhelming. CLI on the other hand has to be learned gradually and because of it’s inherent modal nature, the user is only exposed to small portion of the system at once.

If you had a choice, would you teach Alice or Logo?

I just think Alice

Setting up Dell 3100cn Printer on Kubuntu Gutsy

Thursday, April 17th, 2008

My office has several network printers. Most of them are HP and have zero issues using them from under Linux. They worked right out of the box - all I had to do was to set them up as Windows/Samba shared printers via the KDE printer setup GUI. One that always gave me problems was the big, black and bulky Dell 3100cn color printer sitting in the corner which was not supported.

I finally figured out how to bend it to my will. If you digg around on the Dell website you will notice that it does offer Linux drivers for that machine. Only they are Red Hat drivers. No debs, despite the fact that Dell is officially distributing Ubuntu with their systems. Why is that? Who knows. The important part is that they are there.

snapshot18.png

These are Linux drivers, and that makes our life easier. If they work for Red Hat, they can be made to work for Ubuntu. The systems are not that different after all. Here is how we are going to do this.

First grab the Red Hat drivers from the Dell website:

wget ftp://ftp.us.dell.com/printer/Dell-Laser-Printer-3100cn-1.3-1.noarch.rpm

Next, let’s transform the rpm into a deb package using alien:

sudo alien Dell-Laser-Printer-3100cn-1.3-1.noarch.rpm

If all goes well, this should spit out a deb file into the same directory. The name is exactly the same, but for some reason alien likes to lower-case the whole thing. You should be able to install it bu doing the following:

sudo dpkg -i dell-laser-printer-3100cn_1.3-2_all.deb

This should do it, unless you run into some dependency issues (I had none) or some other problem. That was the hard part. It’s smooth sailing from here my brothers. Just pull up the KDE printer interface and let’s try to add our new printer:

snapshot13.png

Nothing out of unusual yet. By trial and error I learned we need to use the TCP/IP Network Printer option on the next screen:

snapshot14.png

On the next screen just put the IP address of your printer. You know what it is, right? In my office the printer is actually hooked up to a wireless printserver from Linksys which actually does have an IP address of it’s own. If you are using the built in networking logic this step might be different. Anyways, this is insignificant detail.

snapshot15.png

Finally you should be able to specify a printer by picking it from the driver list. A DELL entry should automagically appear in there, and it should have a 3100cn option for you to choose. If you don’t see it, you probably installed the package wrong. If you do see it, pick it, then keep clicking next until you are prompted for a printer name, enter it and you are done.

snapshot16.png

Easy as pie (that is if you consider pies to be easy)! Now I can finally print in color! Wohoo!

Btw, this worked on Gutsy. If you are running Hardy, you are on your own. )