A rather simple-ish explanation of Command/Query Separation

I find that several programmers around me are unable to appreciate CQS or CQRS patterns fully. It seems that a simpler discussion might help.

When writing code (in any language or context) consider writing the following pair of functions instead of one:

  1. function ONE modifies an external object or a variable – ensure that this function has a test at the end and returns a BOOL value (for Success/Failure) – This is the command function.
  2. function TWO returns the current value/state of an object/variable – ensure that this function does not modify any variables/entities that are outside it’s scope. Any and all the values that are modified during the execution of this function belong to variables that are local to the function’s scope and must die with the function. This is the query function.
  3. Now ONE or TWO may be called from a third function that is outside the scope of either.

It’s important to ensure that function ONE or TWO do not call each other (which would defeat the purpose).

Keeping these three simple things in mind can demonstrate the benefits of CQS/CQRS at a small scale.

Of course, computer programming like biology is a science of exceptions, so common sense must be used every step of the way.

In most scenarios, it should be fairly simple to put a PMD-like ruleset for automatic code reviews of function ONE/TWO by observing the return type:

  1. If the return type is bool, throw a warning if a method returning any of the objects modified by the current function is called from within the function.
  2. If the return type is not bool, throw a warning if non-local variables are modified.

Lemme know if this helps.

Side note: I am using the word ‘function’ too many times here, I hope the note is still readable.

The pictorial representations of text: QRcodes

Quick Response codes. I think this is a passing fad, but, right now there seems to be some interest in 1D and 2D barcode like pictorial information ciphers. Hence my two pennys.

QRcode applications are one of the more popular uses of Augmented Reality systems. AR provides possibilities for really interesting use cases.

(Go! Google! Explore! :) )

QRcodes (and other 1D/2D barcode-like image formats) are useful in several ways, always as pictorial representations of textual information. ‘Text to Image’ encoding, if you will. The fundamental is that I can take any piece of text and encode it as a picture which can be read using a QRcode reader. Google’s example implementation uses this to encode calendar events, contact info including email and phone number (a very cool use case, I must say – my visiting card can carry my QRcode), URLs and even WiFi network credentials! I have a link to this implementation later in this post.

The most common use, however, is to let a QRcode redirect you to a URL. Here, for the purposes of example and for self-recursive trumpet touting brag boast is the QR code to this blog:

What you’d typically do is switch on the QRcode reader in your mobile device, point it to this image and as soon as the three boxes (see the top, bottom and right) match the QR application’s markers, it will direct your mobile browser to the URL of this blog.

Here’s another:

'twas a dark and stormy blogThis one actually takes you to my fiction/non-tech-rants blog-site. I am shameless.

Okay, you can read more about QRcodes all around the place. Here’s some stuff to give you a head start:

If you are looking for an open source library that does everything QR (and barcodes and more!), look no further than Google’s own ‘Zebra Crossing’ (ZXing) project:

Google ZXing Home

If you are looking for a QR code generator, here’s a simple one (based on ZXing):

createQRcode

and here’s a more comprehensive, more advanced QR code generator from Google (again using ZXing):

ZXing QRcode Generator

…and of-course the token Wikipedia article:

QR Code article on WikipediaThere’s two more links to consider:

1. Denso-Wave’s (the creators of the QRcode format) site on QR codes: http://www.denso-wave.com/qrcode/index-e.html

2. A tutorial that I found useful (there’s bad english in there, so snobs beware!): http://www.swetake.com/qr/qr1_en.html

The Denso-Wave site is recommended reading! tells ya all about versions, the amount of info that can be encoded, levels of error correction etc.

Good Stuff!

Printing:

This is the fundamental interaction that QRcodes empower. I spot a QRcode in real life and can immediately access the digital information that it serves. QR codes work like real life hyperlinks! Neat stuff!

Stands to reason that printing a QR code must be given due consideration. Of the different materials and processes, owing to their hard edges and high contrast, I think these codes lend themselves to screen printing (and digital printing) processes really well.

Typically what works best for printing is a vector image of your QRcode: InkScape and Bee Tagg help (Bee Tagg also has a very interesting alternative pictorial cipher that is based on hexagons. Its called, bee tagg – what else!).  However, both of these are limited to the “re-direct to a URL” usecase, they do not seem to support free-form embedding of text. Sigh!

However, in the bitmap world, what worked best for me was Photoshop. QRcode images are just a lot of boxes, if you resize them in Photoshop things turn out fine, except in some cases there may be slight blurring of edges. To remedy this, I just check “Resample Image” in the Image Size dialog box and select “Nearest Neighbor” as my algorithm of choice. So, you can use Photoshop to increase the size and resolution of the images that any of the generators (above) give you and print them up just fine!

I have not tested the printing of QR codes on curved surfaces. Not tested how well they can be read from various applications that is. You can still decorate your coffee mug or t-shirt with a QR code if you want to, how well these are read by a mobile device is what I am unaware of. Do let me know if you have any test results.

However, I think it is just a matter of time that there is a better image format that suits a wider array of applications, printing on straight and curved surfaces, supports greater error correction and is even more pleasing to the eye! This is why I think QRcodes and such like (as we see them now) are just a fad. There could be, for example, subtle variations of color, tone, edges etc – invisible to the casual observer’s naked eye – encoded into regular images! Now that would pretty-fy things a lot! I can have my URL encoded into my logo, or my contact info encoded into my passport photograph. That is where I think all this should be headed.

But till such a time comes, enjoy looking at zebra images and thinking of all the coolth it serves. :)

By the way, if you are looking for a QRcode reader for your mobile, you are looking in the wrong place (…hahaha!), you should be looking at your mobile’s app market place.

cheers :)

Mouse-overs and hovers are out

At least they are on their way out.
Think about it, Tom Cruise, Minority Report. Given that kind of interface, how would you do a mouse over? How would you work out a hover?

You can’t.

Now comeback to reality.
Think iPad, Think iPhone, Android, Storm, Touch etc. Think more about all the haptic interfaces. Think of all the tactile gestures. Hovers? Nah!

Press and hold might work for now, but really, who are we fooling here. Hovers are on their way out. On their way to not being such a preferred information dissemination medium anyway. Maybe they’d still work on the desktop, but, how many desktops are around these days? How many days before a desktop changes to something new as well?

You’ll have to re-invent yourself, if you want to be ready for what comes next.

A very senior colleague (who is also a client), was discussing products and design, when his words gave me this insight. You can fart about stuff, you can resist a shift. But, either you are out of the game or in for a change.

S.

The anticipated coolth of Adobe AIR 2.0

[update: this post has been in the limbo for way too long, I wanted a way to embed the flash videos from Adobe.tv here, but it looks like there is none. I am publishing this post today, in hopes that the reader may find it interesting enough to actually try the links… BTW this here might relate to the silverlight 4 thingy as well! ]

I am yet to sift through all the Adobe MAX 2009 videos.

I find it really generous of Adobe to put all of these up. Even if most of it is marketing, they still share a few gems of information. Really worthwhile for guys like me, who end up being so busy there’s little hope of attending an actual MAX event unless planned at least six months ahead of time.

I chanced upon the Adobe AIR 2.0 preview video:  http://tv.adobe.com/watch/max-2009-develop/whats-coming-in-adobe-air-2-/

(I wish there was a way to embed flash videos from Adobe.tv into WordPress…)

 

To me the most important ones are the support for USB (mass storage devices) and native apps (so you can now open a word document from within AIR). I am still a bit skep about the performance, but, I am sure this is going to improve over the new version too…

Check these videos out. Kinda nice. Kinda exciting.

 

Cheers.

 

S.

[update:

1. there’s a lot more videos on AIR2 in the complete video list, but I did like this one by Kevin Lynch as well: http://tv.adobe.com/watch/max-2009-develop/kevin-lynch-demos-adobe-air-2-features/

2. I prefer the adobe media player for working out all of it. nicer neater faster AIR based video playing…]

The Silverlight 4 Beta !!!

It’s not been much time since Silverlight 3 and the Silverlight 4 beta is already out!

http://silverlight.net/getstarted/silverlight-4-beta/

One of the coolest aspects for me is the printing support. Today’s RIA space dearly needs good printing support for its applications. As usual, microsoft has packed enough goodies in the bag, to make a non-programming drag’n’drop coder look like a champion developer! Comprehensive set of form controls and the works…

Another very important point with this version might be the networking support. Again, this might prove to be a game changer. I am thinking cloud, stock markets and social networks right now and I am hoping this could prove to be a cool RIA platform for getting stuff done!

For now this needs Visual Studio 2010 beta 2 (or the web dev express 2010 beta 2).

Check out the announcement: http://silverlight.net/getstarted/silverlight-4-beta/ which I am sure will be a lot more instructive than the two second analysis I have for now.

It’s good news that VS2008 and 2010 can live together. I am off to trying the new stuff now!

Cheers

Shaurya.

Adaptive Experience

About a year or so ago, I remember pestering one of the project managers with the nuances of experience design. I had shared 2 links with this guy, the first to a beautiful presentation (on SlideShare) that I promised would change how he looks at web based applications and the second to an equally cool presentation by Adaptive Path (http://www.adaptivepath.com/).

The poor chap had a tough time working it all out with me, but, in the end “something” did get done! There was output, never mind the absence of parameters to say if it was good or bad. At that time I was glad it got over. In the mean time, I kept wanting to go back to the app design situation and try to come up with a framework that could put a map to the chaos. When I checked my bookmarks, I realized, I had lost one of the two links.

What prompted this post was a presentation that Shreyasi shared around a few days ago (a biggie thankyou to her :) ):

 

The elements of User Experience

 

The interesting bit is that it looks like the link I’ve been missing, but, I am not so sure.

 

However, I still have the other link – the adaptive path presentation. It’s got sound and all. Pretty neat! check it out:

(tangent: Big Thank you to the WordPress and SlideShare teams. Embedded slideshare presentations totally rock!)

It looks like I have both the links today, but need a new set of tools to frame the app design situation a bit better. Adaptive Experience…hehe.

 

To trim a long tale a bit, I find the work (or at the very least the ideas) that the guys at Adaptive Path come up with really impressive. Following their blog(http://www.adaptivepath.com/blog/ ) and essays(http://www.adaptivepath.com/ideas/essays/archives/ ) comes highly recommended!

 

cheers!

S.

Optimizing Actionscript 3 performance

Performance optimization has been a challenge I have been facing A LOT in my projects lately. The more I try to research it, the more confusing the answers get. There were a few ground rules that I had found on the actionscriptWiki (http://wiki.joa-ebert.com/index.php/Main_Page) but beyond that…nothing.

It turns out that Grant Skinner was talking about these same issues at the Flash On The Beach 2009 conference. He has the slides from his talk up on the website now, check these out here: http://gskinner.com/talks/quick/#1
Mike Chambers also wrote a nice post, where he dissects the performance issue with a case study: http://www.mikechambers.com/blog/2009/10/13/case-study-actionscript-3-performance-optimization/

Both the articles make for really interesting reading… check them out!

For more of GSkinner talks go to: http://gskinner.com/blog/archives/2004/06/conference_sess.html

Mkie Chamber’s Blog: http://www.mikechambers.com/blog/

now I should be off again… more code to write, after all I need to optimize my performance as well…hehe

S.

Flash CS5, iPhone support, Flex SDK 4 b2, Catalyst b2, Story and Flash Player 10.1

Wow! This morning was very news worthy!

First there was the announcements regarding Flash CS5.
The big thing here was the new support for native iPhone Apps.
Apparently one can, with the Flash Professional CS5, write AS3 code that compiles as native iPhone application.
They announced it at MAX a few hours ago thru this entertaining video:

Nice!

To me there’s other cool stuff in Adobe Flash Professional CS5 that is really interesting, like the xml based FLAs and the Text Layout Framework.

Mike Chambers here has a post that gets into more details of the iPhone support part.

Adobe has also released a few applications that you can try on your iPhone right away! I feel that it’s a good idea to read thru the Developer FAQs and Aditya Bansod’s article here. I did find the LLVM pretty interesting. There’s a paper and a presentation to check out on llvm.org. For an iPhone a developer can actually use RTMP, remote shared objects and AMF APIs of the flash player. Developers will also have access to the file system and SQLite APIs of AIR 2.0. I am sure we will find out eventually that some stuff is not available, but, what the heck! There will be workarounds…hehe

The idea of a native iPhone Flash Player is still not around…I see places where they say “its on the cards…”, but, there is no mention of a date. The Flash Player 10.1 is going to be available soon though! Again it was announced at Adobe MAX today. Check out Kevin Lynch introducing 10.1 in this video:

This kinda excites me more than the iPhone support. Flash Player 10.1 on Android, Net Books and even on set-top boxes for television providing seamless experience is an awesome awesome wow! More reach, more support for my products and services now. :)

Adobe’s even working on Slider – a mobile optimized port of the Flex 4 codebase.

Along with all of this Adobe also announced a host of other betas available! Check out the list below:

  1. The Flex 4 SDK Beta 2 release
  2. The Flash Builder 4 Beta 2 release
  3. The Flash Catalyst Beta 2 release
  4. and then there’s also the Adobe ColdFusion Builder beta 2 release
  5. and the Adobe LiveCycle Data Services 3 beta release

I also found two very interesting project on Adobe labs.

The first is called workflowlab. A tool (AIR) that allows one to create and share workflows and best practices. Project Managers, Designers and developers can collaborate and contribute to a project in a nicer way with this. The big part is that they used the Flash Builder and Flash Catalyst to create this utility!

Finally, the second one is about something that is really close to my heart too. Adobe Story is an application for collaborative script development. I tried a few scenes of a sample movie script with it. Works really well! The code hints like auto-correct/completion features are really neat! What even nicer is that it supports export to a lot of formats including MS Word, Final Draft (Word and FD  are my preferred screen-writing applications) and also to PDF, CSV, XML and plain text! (There’s probably an AIR application available too, but, I have not tried that as yet). The Story beta was out on Sept 10, so I am a little late (and a little out of place) in talking about it here, but, with all the great up coming stuff, I wanted to blog all of it together.

Really cool stuff happening around. Lots to look out for.

:)

Wave’s out. Adobe Wave that is.

I have been curious about this for a long time now. I see a lot of potential of such a service.

Adobe wave (beta) is out.

See: http://labs.adobe.com/technologies/wave/

It looks kinda like RSS, only better. You get alerts on your desktop when ever updates happen. (uh! I always feel weak when I have to explain the difference between email and SMS) RSS is email, this is SMS.

Basically sites would carry a “Get updates with Adobe Wave” badge. You, their audience would click on the badge and each time the site updates, you get a desktop notification.

Kinda neat huh! I see a lot of applications. Esp. for the on-line education applications and services sector. Another feature to add to the potential Web 2.0/Education 2.0 candy store.

Check out the demo videos: http://labs.adobe.com/technologies/wave/videos/
…and those who, like me, like to code may try: http://labs.adobe.com/technologies/wave/developers/

Nice stuff as usual! Let’s see where this goes.

PS:

1. I think I might be totally wrong about this one. So do check out those links above and correct me here.

2. When I received the announcement mail this morning, I realized, I had not wet my hands with code in some time! I loathe being that word running, excel pushing, empty headed ager-man. I kinda lost sight of what I liked in the business in the first place. Being an ager-man is okay, but, it’s not rewarding unless you have a purpose. What you really like doing gives you the purpose. To lead you need a head.

And I got mine back in place now. So, with luck, I’ll make time, get back in my play pen and rumble code a bit more now.
.
.
.
:) :) :)