02 January 2011

Hello World! in 2011

Knowing I needed less than 40 ASCII characters to pronounce Hello World in FORTRAN, I set about to determine what it would take to do the same in Silverlight using Prism and the Model View ViewModel or MVVM pattern.

Back in the summer of '82, huddled in front of a venerable VAX terminal, I tapped out my first computer program.

Hello World! gave me a chill -- particularly remarkable since this happened in a sweltering computer lab at the University of Minnesota. Our pampered VAX was housed in a chilly meat locker of a room - a room much more accommodating than the undergraduate computer lab with its solitary oscillating fan.

Three glorious lines of FORTRAN. And yes, less than 40 characters of code.

PRINT *, 'Hello World!'

Hello Silverlight, Buh-Bye Simplicity

Fast forward to 2011. This New Year weekend, I have been struggling with adapting a navigation framework for Microsoft Silverlight using MVVM. The stated intent of MVVM, and similar patterns like MVC, is separation of concerns; namely,
separating the presentation layer from the logic layer 
to make code easier to test and to have a pattern that's easy to build upon and to maintain.

Most of my agile colleagues, and mentors like Chris Bartling, are passionate about test driven development. I use TDD, and I think I understand where TDD shines. But I admit I am slightly more motivated by something as mundane as separation of purpose (i.e., old-school layers), because I like an approach to programming that makes stuff easy to create, re-produce cookie-cutter style, and, down the road, will make it a cinch to maintain or extend. Clean. Easy. Life's good.
Forget the complaints against complexity; instead, complain about confusion.
~ Don Norman
I cling to clean simplicity like so many Buckyballs. I despise sloppy confusion. I despise deciphering widely varied code formatting. I loath wringing drops of value from the software anti-patterns I encounter as a contract programmer. And I frequently go ape-shit unraveling spaghetti code.
If I put the hyphen in anal-retentive when it comes to consistent formatting of code, why do I need a machete to cut a path to my desk?
Yet I have struggled with adapting a canned MVVM navigation framework for Silverlight. Ostensibly, all that's needed is simple navigation. We need to register and load views on demand from a navigation framework. Sounds straight-forward. It ain't.

I started with the Prism Navigation Framework developed by Slobodan "Roboblob" Pavkov. Without Roboblob, I'm not sure where I would have started. Microsoft tends to release software tools that are half-baked and then backfill the shoddy effort with spotty documentation - Don't get me started on Entity Framework!

After 3 days of incisor gnashing, I have been able to adapt Slobodan's laudable work to something that just might suit our needs. I don't belittle Slobodan's framework as it must have taken a yeoman's effort.

Perhaps by necessity the solution to what should be a straight-forward problem, seems painful. By painful I mean fragile, almost inscrutable, difficult to debug, and downright confusing for slightly above-average programmers like me - particularly considering we only need to provide hyper-links that load different views on demand.

Why does something that ain't rocket science have to seem so much like...rocket science?

Hello World 2011 in Silverlight

Writing Hello World in Silverlight, I needed 2 projects:
  • a Silverlight project for the application that includes both the View and the ViewModel, and
  • a web project to render the Silverlight. This project has an HTML file with a tag that references the Silverlight object created above.

It seems that Hello World in 2011 via Silverlight requires,
  • a 74 line HTML file that has the tag containing the Silverlight object;
  • a 55 line XAML file that contains navigation and a container for the View; and
  • some 23 lines of XAML in the View to say Hello World!

Perhaps I've exaggerated the effort since Microsoft makes Hello World so easy that even an aging bonobo with cataracts could code it with 3 clicks and a cut 'n paste. What happens when I need more than Hello World?

I am beginning to wonder about confusing & seemingly gratuitous complexity; albeit confusing complexity added in the good name of testability, flexibility, and modularity. My questions are two-fold:
What is the cost of confusing complexity (necessitated by an ostensibly clean pattern)?
How much are we blinded by the laudable lights of testability, flexibility, and modularity?