Sunday, August 23, 2009

I'm taking JavaScript seriously

Well after reading an article by Larry O'Brien @ SD Times magazine (sorry no link, I read the physical copy) about how people aren't taking JavaScript (JS from now on) seriously, I decided to do blog about it.

So what's JS? It's a programming language mostly used @ client-side programming, it is the key to all those awesome effects you see or experience in your favorites websites, one of the crucial components in AJAX (which itself is only a technique), but as I called it: "The technique which built the Web 2.0", so AJAX is something important, we all know it, but JS is important too.

So JS allow us to add some nifty effects like changing the value of some of the HTML elements of a page, ok nothing out of this world, but if we add all the jQuery (include your preferred library here) DOM effects and AJAX-powered page dynamics and you got the current web, not only the current but the web we'll probably be building for the next 5 years (10 if the adoption of the semantic web or web 3.0 as Tim O'Reilly likes to call it takes longer). Again, you maybe asking yourself that I'm not saying anything you didn't know, but guess again you 're wrong.

JS is a programming language and as all languages have bad scripts and good scripts, I bet most of you don't optimize your JS code, probably if Firebug doesn't show an error, you are done working on that script, what about optimization? there's always room for that (yeah we the dinosaurs who know C++ are optimization freaks), JS is becoming more important on the web with each passing day, so is obvious that the future bottlenecks on websites will be because of bad JS code. So if you start know taking JS seriously, you probably will avoid these network traffic problems in the future, so the question remains what can you do?

The first thing to do is to learn that JS is an incredible dynamic and object oriented language and that the fault for the slow JS is in ourselves. Second you can start using tools such as YSlow and debugging, performance and benchmarking tools to see where your JS code is taking the hit. Finally we are all afraid to change our code, "it worked yesterday, now I made a couple of changes and bang it doesn't work. Darn it, let me clone the repo again.", yeah that's why programmers began using TDD and BDD (mostly TDD for this scenario) because with a full test suite you can change your code without fear (hell you can be Daredevil, the man without fear or Dan Dragon as that comic book is called in Spain), bottom line test your scripts.

Finally, I want to add that I can't make better JS code for you, you will always have to sit in that chair and code it yourself, good night.

Thursday, August 6, 2009

Google Docs will kill Microsoft Office...

Lately that's something I have heard everywhere I go, people come and run their mouth about how Google Docs is the future and Microsoft Office is older than the T-Rex. Lately Google launched a new campaign offering their Google Apps for workplaces, so you can all imagine how much some people have been commenting about it in the blogosphere.

As always I tend to go in the opposite direction of everything, so I began doing my own research about how this battle gonna end (of course I'm a simple mortal so I can't possibly predict how this is gonna end but I can give my opinion). I found out that, after reusing, Google Docs that it lacked many features and the speed that Microsoft Office has, of course that comparison is unfair one being on the desktop and the other on the web, but many people uses the accessibility that Google Docs possesses as a strong point when arguing about this topic, so why can't I use office speed as a strong point?

Google Docs is what we now days call a SaaS (Software as a Service) and is what many people calls "the way of the future" and that makes Google Docs a bleeding edge application, but is that enough to migrate from Office? In my honest opinion no, Google Docs lacks a lot of features, not a suite the size of Office and Google Docs lack ,what is in my opinion the most refreshing and interesting feature Office have, VBA (of course as a programmer I have a natural impulse to run away from anything VB but Microsoft in theory could add any .NET language and use the same subset of functionalities making a dream come true, a Microsoft Visio extension written in IronRuby).

This week I got reminded a very important lesson, programmers are suppose to write code that solves problems, be it some companies, users or personal problems. So we programmers now days tend to answer right away to every problem with "let's make a web application", but a web app is not the most efficient solution to all the world's problems, sometimes desktop apps can do the trick, let me express myself more clearly with the situation a close friend had recently. His father owns a small clinic, he is a cardiologist and he along with others doctors that work there needed a way to save their receipts and how much money each doctor made daily (yeah they pay daily over there), so my friend offered himself for the task, but there was a problem he isn't a programmer, all he knows is a little VB.NET (I'm teaching him programming but it is a slow process).

His approach was to extend Microsoft Excel's capabilities using VBA (Visual Basic for Applications) and store everything in the spreadsheet, of course when he came to me with the idea my suggestion was "let's make a web app", he then said to me that in his fathers clinic there was no Internet, making my initial approach totally worthless, I then offered to code (as I taught him) a desktop app, he said this people weren't very tech-savvy so we needed a new approach, finally I suggested to use Microsoft Access, yes I unleashed the horror unto the world again (we programmers usually hate Access as the DB for our projects) but my approach was a tricky one, this people were familiar with Excel and Word and I intended to leverage Access' power and usability based on the fact that almost all of the Office suite uses the "Ribbon interface". A few days later my friend came by to play a little hand of Cashflow and showed me the results of his work, I was amazed by how he learned to use Access and how much he had done using VBA, I taught him a few of SQL's commands and probably after he finish with some details about the application, he will have done a complete and functional application on Microsoft Access which real people are using to solve their problems, that is the true power hidden in Microsoft Office (average people only knows how to use a tenth of all of Office capabilities, far less knows how much VBA can help), a power Google Docs currently doesn't have (if I'm wrong please respond with a link) but on the IT industry nothing stays the same for too long, probably Google could add this kind of functionality offering some sort of JavaScript idiom, the point is, this is a great feature of Office today but tomorrow it might just be some standard all office suites offer.

At the end of the day the lack of features and applications (the suite is a lot bigger in Microsoft Office than the suite Google Docs offers) on the Google Docs suite makes it a no brainer for me to go with Microsoft Office as my preferred tool. The accessibility of Google Docs, as being a SaaS application, is not enough for me to migrate from Microsoft Office.

Saturday, August 1, 2009

Comet a.k.a. Reverse Ajax

OK, before we start with this post we need to explain what is Ajax to those "web developer" who have been living under a rock since the CGI-Perl scripts days.

The http protocol model includes the so called "Request-Response" cycle, so many years later each response included a full page reload, then came JavaScript and yada yada Ajax was born, so Ajax stands for Asynchronous JavaScript and XML. Ajax consist of updating certain parts of a web page asynchronously, always started by the client , without reloading the whole page so it doesn't interfere with the user experience, no awkward reloads. So, yeah Tim O'Reilly coined this with the awesome name Web 2.0, but you maybe asking what the hell is Comet?

Comet is a neologism to describe a process very similar to Ajax but in which the server starts the connection. Actually, Comet is an umbrella term for multiples techniques used to achieve this functionality, now you probably understand why some people decided to call Comet, Reverse Ajax. But why do we need Comet? why do we need something that turns the http cycle upside down? what benefits could we gain from using Comet?

This very same questions were asked by friend of mine one day when I told him what Comet was, so I came with a good example and decided to make a post about it.

The example includes making a chat online in your website, something like gtalk inside gmail, so how would you implement it? has to be real life chat with near instant responses or the users gonna complain a lot and probably never use it.

So one idea would be to use Ajax to achieve this:

So putting it simple, make a lot of Ajax calls to the server and when there is something in the queue, update the chat component in the client, does anyone else see the problem with this approach? Making calls every second will create unnecessary traffic and if we make our web app to make calls every 5 seconds what happens if a response from the other user comes right after a couple milliseconds after our call was made, the client will wait 5 seconds waiting for a response that's already on the server. Obviously we need a new approach to achieve our goal.

Second idea, use Comet:












So how about using Comet and make the server talk to us when he receives the response from the other user? We won't need all those Ajax calls, instead we would only need one call to keep the chat cycle going, the server's.

But Comet, can't be all roses, we need a way to implement it. In this example I'm not gonna code it but I'm gonna use the theory behind Ajax long polling to detect new information on the server. It consists in simply making Ajax calls wait longer than usual for a response from the server, in our example it uses a lot less Ajax calls to achieve our goal and it doesn't produce too much traffic.

Well, hope this post was of some interest to some of you, I hope you can leave your comments about where to use Comet and how much resources would that save.

This was Darryl Almonte, thanks for reading, Namaste.

Coder Girl...

Following some links in the Heroku site, I found a link to the Erlang Factory and Kings of Code conferences, so after watching a little videos of my personal interests, I came into a very interesting video.

All I can say is enjoy.