Introduction to Object Oriented JavaScript - Part 1

JavaScript is a great language that has been taken very seriously in the past couple of years. We can see tons of useful JS libraries on the web for everything, like tweening libraries, MVC frameworks and graphics manipulators. Not to mention the power of Node.js, for real time data exchange and so on.

It's important to understand that nothing changed in the core of the language itself. All the astonishing libs we see in JS today could have been done 5 years ago very well. But at the time there was Flash. ActionScript was the language of choice for many developers when it came to high interactive web apps/websites. Now that the demand is leaving the Flash Player behind, we have to adapt. JavaScript became the answer.

So for those who have been dealing with Object Oriented Programming languages, such as ActionScript 3.0, Java, Python etc. working with a scripting language can be a little effort intense. OOP languages offers us a lot of flexibility and frankly, software development flexibility, is something that started to turn into a need rather than a convenience in the last period.

Well, thankfully, we can exploit the language to give us the flexibility we need when we start thinking about objects, reusability, design patterns – JavaScript as many of you might (and might not) already know, is an almost-entirely object-based language. Its Objects are basically associative arrays augmented with prototypes, nearly just like ActionScript 1.0. If you had the chance to do any AS1 in the past, you should already have a good idea about prototypes, if you didn't, well, just read the rest of the post.

These are some theoretical aspects of the language when it is used to 'simulate' object orientation.

Dynamic Typing:
Types are associated with values rather than variables. It means that a variable bound to a number can be bound to a string later on.

In English:

var x = 5;
var x = "five"; // WTF?
And it's totally fine.

Functions are Objects:
For that, they have properties and methods. They can be assigned to variables, returned by other functions, passed to arguments and so on.

Prototype-based:
Prototypes are used instead of classes and inheritance. Many class-based features can be simulated with the use of prototype in JavaScript.

Functions can be Object Constructors:
Invoking a function with the new keyword, creates a new object and calls that function with its local this keyword bound to that object for that invocation:

var dude = new Dude();
dude.name = "bob";
The name property is bound to the dude object and not to the global scope.

Functions can also be methods:
In JavaScript there is no difference between method definitions and function definitions. Rather, the distinction occurs during function calling; a function can be called as a method. When a function is called as a method of an object, the function's local this keyword is bound to that object for that invocation.

These are the points to keep in mind so far. Stay tuned for the next post, where I'll be covering further practical examples, such as writing classes, public/private/static methods, class properties and so on.

I'm back: more posts to come in the future
I'm Back

It's been a while (a long one actually) since the last time I posted. I've been busy at work, doing preparations for my marriage and beside all this, I'm investing what remains of my time into some "secret" project.

There have been a lot of changes in my career. The most important one is I've switched to Ruby on Rails, beside digging deeper into JavaScript, HTML5 and CSS. Regarding mobile development, I've been studying Objective-C religiously and left other mobile development techs apart, such as AIR and PhoneGap (which I might still use for other mobile platform development).
ActionScript 3.0 is still my language of choice when it comes to high performance interactive apps. But yet, since the web is all going towards the minimal style, I rarely touch it, sadly. (See my last post about the Future of Flash)

I'm not really sure what pushed me to Ruby on Rails. Ruby is a wonderful language, easy, powerful and its community is huge. As for Rails, I needed something robust for Rich Internet Apps and at the same time easy and to the point. Using frameworks has been always an advantage since the old days of ActionScript. I've been using Robotlegs a lot and that made me a huge fan of the MVC architecture/pattern. Rails is an awesome implementation of MVC. That's was the choice then. I was sold since the very first page I read about it. If anyone would ever ask me about the next tool to learn, I'd proudly point them to Ruby on Rails.

Of course, with Rails, there is HTML, CSS and JS. They have a very interesting bond when used together for good. Of course, I'm still pissed off by the fact that there are many inconsistencies among browsers, but if that's the only challenge, I'm okay with it.

Talking about Ruby, I've rebuilt my website from scratch using Jekyll, a neat Ruby Gem, which helps you generate static pages out of HTML templates and files. The output, is a bunch of static pages which gives you the benefit of a faster browsing experience, it's more secure and requires zero setup on your host. There are of course plugins that you can use to add some other stuff, like tagging. I'm also using Disqus to manage comments. Again, life is simple.

To go back to the main purpose of this post, I'm very keen on keeping this blog constantly updated. I know I've been taking too much breaks from writing, but I'm really considering sharing lots of knowledge in the future.

Stay tuned for more.

The Flash Platform. Past, present and future

I was expected to post about this topic some time ago, but I've thought to wait and read other posts and watch other people's opinions closely. I've seen different point of views and there is no doubt, they are all right, someway.
So let me be sincere in this post and let me express the way I see this going.

When Adobe first bought Flash, the community was so excited. I was one of them and watching Adobe turning it into a platform was delightful. Flash had undergone lots of improvements in the past 4 years and the community exploited it to the max. I remember these days when I used to write more ActionScript 3 than any other language for the web – I was making a living out of it. I guess everything was going just fine, smoothly... normally.

Until one day Steve Jobs popped up and said: "HTML5 is the future". Again, the community was so excited about it that they instantly started to take their precautions and work on kick ass projects, not to mention the defensive blog posts, talking about how bad is the lack of support of Flash on iPhones(Pads) and how HTML5 was still inmature. Old story.
I was actually pissed off too, I have to admit it. I thought how would my entire career be in trouble if HTML5 could one day, be under the spots for one reason or another. It actually was, in the past, and it actually isn't, right now. But that's another story.

The release of the iPad was going to change the world and HTML5, along with JavaScript and CSS3, could do the job. The funny thing is the community did the job because having websites that work on iPads turned out to be so essential that developers wouldn't even dare tell their clients that their Flash websites will not be accessible on Apple devices. They had to go for HTML5. And they did.

That was the time when Adobe should have done something about it. Actually they added many features to Flash, unessential features. They started to turn the Flash Platform into a gaming platform, this is how it looks like today. A goddamn casual gaming platform. It's a fact, Adobe doesn't listen to their community. What about concurrency? What about multithreading programming? Yes they have made performance improvements by adding StageVideo and Stage3D (molehill) so what? What about the real power that they could give to the application developers? They were literally wasting their time and in the meanwhile HTML5 became the trend on both mobile and desktop.

Adobe AIR was good before entering the world of mobility. I personally had lots of fun doing apps in both Flex and pure ActionScript. It performs great on desktops but it's a total failure on mobile devices. Adobe promised an entirely new Flex framework optimized for mobile development. Unfortunately that never happened and they just added some fancy "bigger" controls to Spark and some navigation utilities. I remember when I started to play around with Flash Builder "Burrito" and did some scrolling lists. Well, that scrolling thing performed so bad on my Nexus One that I decided to stop doing AIR for mobile. I uninstalled the AIR runtime and studied Native Android development. It was relieving.

Another disappointing fact was they use Eclipse for Flex development. Instead of working on nonsense projects like Flash Catalyst they could at least have done a better IDE for Flex. Well, at least they could work a little harder with Eclipse instead of watching others creating better tools like FDT or Flash Develop. Not to mention its price.

Now, Adobe fires 750 employees and finally admits HTML5 is the winner and started to invest into tools for that. Well, they have trashed Flash and thought about why they would continue in putting efforts in Flash while they can still get the top of the cake by creating tools for HTML5.
They discontinued the Flash Player for mobile browsers and even worse, they have trashed Flex. "But don't worry, we are sticking with AIR for mobile platforms" they said. Of course they would, or who would pay a penny for a new release of Flash Professional in the future? And what did they do to keep AIR on air? They added Native extensions, which basically means the ability to attach "native" code to ActionScript in order to access the lower layers of the hosting operating systems. Wait what? Why on Earth would I develop applications in AIR if I still have to add native code to them? Of course, it isn't worth the effort and going native (Java or Objective-C for iDevices) would be better – at least I won't sacrifice performance. Adobe AIR is going bye bye very soon, as well.

See, the whole point is, Flash survived all this time because of its loyal community and not because of Adobe. It's up to its community whether it will die or not. Why? Because HTML5 will never be as fascinating as Flash when it comes to user experience, interaction or even performance, at least for desktop versions of Flash Player.

So you either stick with Flash doing great stuff with it, or you do yourself a favor and learn a new language tonight.

Keep track of great things with Asana

Some fellow at work shared a great tool that I'm now using nearly everyday when I sit on my computer. Here is the video as I frankly have no better words to describe it. Give it a try, it's free and it's easy, for everyone.

My thoughts on Steve Jobs
Steve Jobs "Stay hungry, stay foolish" - Steve Jobs (1955-2011)

Watching the last Apple Special Event was awkward without Steve on stage. Tim Cook is good, but he is not Steve Jobs. The whole atmosphere for the audience who attended the event was weird. Applauses were not as vigorous as before, even at the moment of the new iPhone revelation. It was not the same.

I was hoping – and I'm sure everyone was – to see him appear on stage just to greet people, with his typical blue jeans, black top and rounded glasses. But he didn't.
A day later I read this tweet, along with a creepy shiver through my body. I realized we will never see him again.

Steve Jobs, for sure changed our lives. He made perfection possible through his inventions. Inventions that could never exist without the passion and love for what he did. He was a visionary, a dreamer, a perfectionist and strong enough to witness his own dreams coming true.

I was one of the people who called him a software dictator time ago for many reasons which I will not mention now. But with time, I realized that all he did was on purpose. He was right and smart.
I re-watched nearly all of his presentations and interviews yesterday. I've never seen someone so sure of his thoughts in my entire life. I remember when he first announced the original iPhone, he held it in his hand while standing on that stage, firm, proud and doubtless. I will never forget the passion and ecstasy he poured out his eyes every time he announced a new revolutionary product.

I wish he could live longer to see a better world, the world the way we all want it to become.

Thank you Steve.