Archive for May 14, 2015

Angular? Nothing new under the sun

May 14, 2015 3 comments

In a previous post I sort of slaughtered Angular.js and Bootstrap. Partly because these libraries represent “a prototypical solution to the lack of classes, inheritance and a VMT”. My point was simply that if you sat down to program Angular in Smart Pascal or Delphi, you would use ordinary inheritance to solve many of the more tricky subjects angular imposes on us.

And in so doing, no one would bat an eyelid – nor would it be hyped to the point where people believe they can cure cancer with it. It would just be another MVC framework, one among thousands. But since Google made it and spontaneously throws a few workshops around it – people go nuts and imagine that it’s just so much better than anything else out there.

Ladies and gentlemen, that is just sad, disappointing and intellectually disturbing. As a result I no longer believe our species will ever reach the stars, quite simply because the wast majority of our human population are indistinguishable from cattle.

Apple made MVC hot again, but it's an old re-hash from yonder days

Apple made MVC hot again, but it’s really a re-hash from ‘yonder days

Now the blogging I do here can only be one or the other: either a short post (like this one) or a long, more detailed post. It depends on how much time I have and how interesting the topic is. But it’s rare that I post a medium-sized article. I mention this because I have gotten feedback like “Oh you have completely misunderstood MVC” — which is simply not true. In fact I work with angular on a daily basis at work.

But that doesn’t mean I will publish a dissertation on the subject just to underline that I do have experience with MVC. Readers of my blog will know that I’m not a proud individual. If I have done wrong, said wrong or coded wrong I have no problem saying I’m sorry. It is after all impossible to go through life without making mistakes. So if I came across as just shooting things because “I don’t like them” mentality, that was not what I meant; What I meant is that I don’t like them because-of a wide range of valid reasons.

That’s why I cut the MVC criticism short because (quite frankly) I thought my issues would be common knowledge. Clearly they are not so I will try to bring more light to the subject in this post.

MVC is hardly new tech

MVC is not new. It’s bloody ancient and it tends to arise and appear towards the height of a platform’s popularity. So if nothing else it’s a clear indicator that right now JavaScript and HTML5 is at its height, and in the years to come we will see a steady decline in the way we use this technology. The timeframe coincides with the emergence of the next level in computing: namely the cloud and it’s potential.

So for those that believe MVC is something new and fresh – compared to Delphi which is termed old and useless, think again. First of all the oldest programming language still alive in the world is C, which is around six years older than pascal (just to kill that misconception if you suffer from it). MVC is not as old as that, but it’s pretty damn vintage! I remember doing MVC coding on the 16-bit Amiga computer some 25 years ago.

A huge selection of the OS can be automated through AREXX

A huge selection of the OS can be automated through AREXX

One of the lesser known aspects of Amiga OS today is the fact that it came with a built-in automation system called AREXX. It was absolutely brilliant. What programmers did was to define and register AREXX ports in their native applications. These ports worked a lot like socket’s do, in that you can send and receive messages on them. Once exported, which was done by calling the OS informing it about the functions you made publicly available, these functions could be automated and called from any AREXX script.

So what people did was to design the view using a MUI editor (magic user interface), write an application controller and essentially create existing OS level controllers and classes to create an application. Whenever you needed something special you would just import the functionality of a commercial program and use those functions to do your work.

  • Write application controller using AREXX
  • Design views using a MUI (magic user interface) designer
  • Create and maintain OS level objects and controllers
  • Maintain a persistent data model, similar to COM’s property-bag
Listing REXX exported controller ports under Amiga OS

Listing REXX exported controller ports under Amiga OS

Even seemingly new techniques like “MVB”, where you bind or link visual elements to a property in the model could be achieved. In fact on the Amiga you could create fully working, complex and advanced applications using nothing but AREXX scripting. So for those of you that believe the MVC pattern is new and fresh of the mint, sorry to burst your bubble but it’s most likely older than you.

Remember that myself and hundreds of thousands of others were using this more than a decade before Microsoft Windows was even conceived of. I remember bursting out in laughter when Apple introduced their “Automator” script system back in the day. Why? Because the Amiga has that 25 years ago! And it get’s better because in january (I think it was) Apple announced that OS X was now the pinnacle of operative systems, because now they supported REXX scripting (!)

You know what? For ages now people have blamed Microsoft for ripping off Apple’s ideas. But guess what, most of them didn’t come from Apple, but from a kick-ass 16 bit operative system and computer, 15 years ahead of the competition back in the early 80’s.

So Apple have (and there is no doubt here, they have even admitted it from time to time) robbed Commodore Amiga blind. And the fact that they are still lifting good ideas from a 30 year old operative system speaks volumes both about the Amiga and those out to duplicate its technology.

The bright side of MVC

We are all adults here and I take for granted that you have enough life experience to recognize that everything has dark side. It doesn’t matter what it is, there is always some side-effect or “potential for error” or risk assessment where an otherwise brilliant technology yields nothing but disaster. This is true for Delphi’s CCV (class, component, view) pattern, model view controller and dot net’s distributed assembly model. Take your pick, there is no universal technique which works everywhere without flaw, side-effect or zero potentiality for error.

Now the bright side of MVC is fairly easy to spot:

  • If architected with care, the same controller can be used on different views
  • Writing plugins or extending a MVC based framework can be fragmented
  • Under HTML/JS an application appears as a single document, but is in fact rendered by a route manager

If we have a look at these you will notice just like me, that the first one sort of comes naturally.  Right? I mean it’s not an “aha” moment you read here for the first time and just go “Oh my god I never thought about that before”.

The second point is likewise an immediate factoid that you locate if you spend 2-3 minutes thinking about how a 3 partite organized framework must look like. And the last point is cool but ultimately easy to achieve no matter what language, technique or pattern you subscribe to.

MVC applications quickly become a mess to work with

MVC applications quickly become a mess to work with, remember to be nazi at organizing

If I was to point out something positive about MVC, it would have to be the first point on the list, namely that if you carefully architect your controller – it can be used on multiple layout views. So a typical example of something “neat” is exactly that: when you have a website that supports both desktop and mobile devices.

The mobile layout will in the best of cases have the same elements but organized differently. Worst case scenario is when mobile and desktop views use different model fields, forcing your response controller to include logic which MVC was designed to avoid. But in general angular.js is brilliant at bringing this to the world of JavaScript, because it does make things easier for JavaScript developers.

Again, angular is just fantastic for programmers with no knowledge of true object-oriented programming. If all you know is JavaScript then odds are you wont be able to recognize “real” stuff. Your mind would simply exclude it as un-important because it’s alien to you.

Do a quick google on javascript 10kb demos and you will find hundreds of superb graphically demonstrations written in JavaScript. But I can tell you right now that nearly none of those demos are written by a programmer that only know and work with JavaScript. These are old coders like myself with a background in hacker groups, demo and intro programming – and they have been doing this for 30+ years.

The dark side of MVC

The downside of MVC, is that your views can (depending on the framework you use) have something like 30 to 100 controllers running at any given time. Apple is positively criminal when it comes to this. It’s common that a single form design, although a complex one, spawn’s as many as 100 controllers when pushed onto the display.

Why? Because a controller is not the same as “the form resize code”. Oh no, a controller can be anything from watching that you prefix text with a $ character, a routine which keeps track of an application state – to making sure a control horizontally stretch to match its neighbors. A controller is just a piece of code responsible for a single behavior; or better yet – a method which ensures a distinct type of behavior. It all depends on subject, object and toolkit.

Incidentally, this is why Java and C# programmers are so hopelessly dependent on garbage collection. Can you imagine working on a huge MVC iPad project where every single view has between 30 to 100 controllers? This means that every element has controllers taking care of scaling, rotation, movement, fading, projection, touch, routes and cross-view event delegation (phew!). And it’s recursive to you know, hosted user-controls are likewise MVC based! Not exactly an eco friendly, resource moderate technology is it? Not to mention the waste of CPU power just because of a damn coding practice.

Now apply that mess to a single threaded event based runtime engine and try catching an exception induced through an anonymous timer. That’s when the regret of chosing angular over object pascal hit’s you like a ton of bricks and you whole heartedly regret ditching a rock solid language and it’s super effective CCV pattern.

The human factor

By now you probably get that my problem with angular, jquery, bootstrap and it’s likes is not superficial. It’s not based on a whim or defined by something stupid like fanboy-ism. Quite the opposite. In my line of work you have to know several programming languages if you expect to survive. My favorite language is object pascal, everyone knows that, but all languages and techniques, patterns and practices have strength and weaknesses. And it’s your profession to pick the right tool for a job.

So for me personally as well as professionally, a programming language is just a vehicle for my experience. You can’t expect to use the same tool to fix every single problem. Although I must admit that Delphi and Smart Mobile Studio combined is akin to a proverbial swiss army sword.

Bigger the projects, wider the toolbox

Bigger the projects, wider the toolbox

So angular is fantastic if all you know is javascript. But if you come from a more classical background, like Delphi or C++ then angular will soon get on your nerves. Because after a little while you realize that most of the blubber posing as high-tech stocking fillers – exists primarily due to the lack of OOP. It represents the author’s means to overcome, bypass and make up for the fact that javascript is prototypical, not object oriented.

MVC delivers no true benefit over ordinary object pascal’s CCV (or C++ builder, or even C# for that matter). In Delphi everything angular represents (and jquery + bootstrap) would be solved far more elegantly using nothing but vanilla inheritance.

Take something simple, like using the same controller on two different views:


TMyView = Class(TCustomForm)
  procedure SomeControlOperation;virtual;abstract;
  procedure SomeOtherControlOperation;virtual;abstract;

// Our mobile "view" takes care of the mobile displays
TMyViewMobile = Class(TMyView)
  //Layout and operations for mobile views
  procedure SomeControlOperation;override;
  procedure SomeOtherControlOperation;override;

// Our desktop "view" takes care of larger displays
TMyViewDesktop = class(TMyView)
  //Layout and operations implemented for desktop displays
  procedure SomeControlOperation;override;
  procedure SomeOtherControlOperation;override;

In the above example we isolate our API, which essentially act as our controller, as purely abstract methods in our ancestor class. We then derive and derive two separate variations, one for mobile and one for desktop. Each of these implement their kind of layout according to the rules we impose in our API (the public procedures).
Since this example only have two elements to support (desktop and mobile) it would be better to implement the desktop behavior directly in the root-ancestor (TMyView) and have TMyViewMobile override that for mobile devices. If nothing else than to keep our code tidy and neat.

Not a controller in sight, but easy to use, deploy and debug

Not a controller in sight, but easy to use, deploy and debug

What I have objected to about angular (et al) is this popular but certainly false notion that MVC produces better, faster, easier or cleaner results than the above. In fact the result would be exactly the same. I would also go so far as to say that using inheritance is cleaner and provides a human bonus: namely better organization. We don’t have to use X number of folders to organize views, controllers and model schemas – because they all make up 3 parts of a common whole. Why write 3 times as much code for absolutely no reason other than pretending to be cool?

So this popular notion that object pascal is old, ancient or past it’s expiration date (comparing to MVC) is simply not true. The entire misconception is based on ignorance and laziness, plain and simple. And how can I propose that? Because there is no technical benefit of choosing MVC over a traditional CCV object orientation. People chose the hyped re-hash because it’s easy, not because it’s technically excellent, faster, yields better results or any of those superlatives.

Just remember: with great simplicity emerges an even greater lack of diversity!