Tuesday, September 13, 2011

The Joy of Clojure - a short book review

I'm currently reading the book "The Joy of Clojure". This is a rare kind of book - the kind you don't want to end. It explains Clojure - but not in a "do this to get that" kind of a way, which is the way most technical books are. It does it differently, by almost telling a story that reveals Clojure layer after layer. It does so while keeping the Clojure motto of "no unneeded overhead" - exactly what's needed, no more no less.

Still, if it was just for that, I wouldn't rush to write this short review - there's something else in the way that this book is written, its style is some sort of a combination between an Arthur Conan Doyle novel in the way that it glues you to the page, and a late night show monologue that provides you fun every 30 seconds.

A must read for every software developer - regardless if you ever plan to write a single line of Clojure code, it would just make you think clearer about code in general and specifically about your code.

Saturday, September 3, 2011

A function, JavaScript engine and the single var pattern to declare variables walk into a pub

Addy Osmani had published a very nice post that summarizes various problems found when doing JavaScript code review. Most of the points there worth paying attention to. However, there is one point there that he got completely wrong. When he discussed the problem of variables declared all over the place within a function scope, he suggested to use the "single var pattern to declare variables", basically write the variables declarations like this:

var someData = "testing",
     otherData = "data1",
     moreData = "data2";

This kind of coding will get you into trouble. Try to find the difference between the code above and the code below:


var someData = "testing"
     otherData = "data1",
     moreData = "data2";

Found?

let's add to the first snippet the scope of each variable:

var someData = "testing", // local within the function
     otherData = "data1", // local within the function
     moreData = "data2"; // local within the function

Now let's do the same for the second snippet:

var someData = "testing" // local within the function
     otherData = "data1", // global
     moreData = "data2"; // global

Big difference, but why?.

Answer: Take a look at the "testing" string. In the first snippet  it is followed by a comma, whereas it is not there in the second snippet. That's all, one comma.

Both snippets are valid JavaScript code, it just happens that even though JavaScript has a C like syntax, it does not require to have a semi-colon at the end of each line, the JavaScript engine will add it if missing.

So the second snippet is actually:


var someData = "testing"; // local within the function
     otherData = "data1", // global
     moreData = "data2"; // global

(note the semi-colon after the "testing").

One more thing to know about JavaScript: when declaring a variable inside a function without the var keyword, it is defined as a global variable.

Now go and find that little comma somewhere in your code, at 1:00 am , a few hours before delivery.

I prefer the simpler approach to define variables, and do the following:


var someData = "testing"; // local within the function
var otherData = "data1"; // local within the function
var moreData = "data2"; // local within the function

You can say that it is less elegant, but it is much less error prone, much more descriptive of what you want, can save hours of looking for a comma and simply put, it is just a simpler code. Just remember that beauty is in the eyes of the beholder, and to me, in code, simplicity is beauty .

Thursday, August 18, 2011

What's next in the mobile arena

Apple has complete control  both on the software and the hardware of their mobile devices. Moreover, they have a huge client base (all the iPXXXX people)
Google  now also has complete control both on the software and the hardware of their mobile device (assuming that the deal with Motorola Mobility is approved). Moreover, they have a huge client base (all the android people)

RIM has complete control both on the software and the hardware of their devices, but nobody buys their products and they are loosing their share in the mobile market.

Microsoft controls its software and wants to increase their share in this market.

When will Microsoft buy RIM?

Saturday, August 13, 2011

The effects of the software patents war

There's a software patents war raging. It is fought between all the players, big and small: Google, Apple, Microsoft, Oracle and IBM are just a few names in the list of the war participants.

It is all over the news now, Google buys more then a 1000 patents from IBM and fails to buy 6000 other patents, of Nortel. These 6000 patents were bought by Apple, Microsoft and Ericsson. The undertaker of silicon valley claims that nowadays, what's left of a company that is closing down is the IP (whereas during the 2000 bubble bust servers were what a dying company could sell).

This leads me to ask about the effect of this war on the recruitment process. I guess that companies in the high-tec industry will start looking for people who know to develop software (transform innovation into code) as well as know how to develop IP (transform innovation into patents).
Would an ad for a software developer include not only the set of technologies / domains that a possible candidate should know, but also how many patents are on the candidate's belt?

Update
The patents war is now going to the next level - Google bought Motorola Mobility and its portfolio of about 17,000 patents. Now Google has a patent arsenal which can be used to really fight the rest of the big players.

Wednesday, July 27, 2011

Programming and softwaring

Programming is creating functional components from code atoms (such as a programming language keywords or library calls). It is structuring a code molecule with defined input and output.

Softwaring is the composition of code units (atoms and molecules), functional components and other software to create an entity that has code organs (such as UI or communication layer), processes and life cycle.

Programming is chemistry.

Softwaring is biology.

Tuesday, June 28, 2011

A different, simpler, approach to visually design business processes

About a year ago, I co-authored a paper called "What You See And Do Is What You Get: A Human-Centric Design Approach to Human-Centric process". It was accepted and presented at the BPD  workshop (BPD here stands for "Business Process Design") which was part of the BPM conference (BPM here stands for "Business Process Management").

The paper describes a new way to design processes. The key idea there was to reuse the WYSIWYG ("what you see is what you get") design approach (which is used usually for user interface design) in process design, where static page design is not sufficient, but there's also a need to design the dynamic nature of the process.

I just noticed that the proceedings are now published, so it is possible to read the paper here.
Section 2 there describes in more details the WYSADIWYG approach.

Sunday, June 26, 2011

Comparing programming languages to boats

See here, a nice comparison of programming languages to types of boats. Very funny, some of it even makes sense (even though I'd say that Java is the Titanic rather then a cargo ship...)





Monday, June 13, 2011

Brain-mapping the Dallas Mavericks

Dallas Mavericks just won the NBA title. Watching them was a true enjoyment due to the diversity of the playing styles that this team showed.
When combining together all these playing styles it is easy to see the resemblance of this team to another remarkable machine - the brain. Here is a short list of the key players and their role / playing style as if they are regions in the brain:

Jason Kidd -  Prefrontal Cortex: This region is responsible for planning and decision making (amongst other things). This is the type of basketball that Jason Kidd is playing - very smart and focused on taking the right decisions while planning two moves in advance.

Dirk Nowitzki - Cerebellum. This region is responsible for repetitive motorical tasks, such as climbing stairs all the way to doing calligraphy. Dirk Nowitzki's game is all about doing several things over and over again, regardless of their complexity - jump backward on one leg, re-balance in mid-air and then throw the ball accurately to the hoop. from the outside it seems complicated, it is if you stop and think about every step. It isn't if done automatically.

Jason Terry - Amygdala. This region's key functionality is handling the limbic system, i.e. emotions. Jason Terry's game is all about emotions - if he feels that he needs to shot, he'll shoot, no fear, no stress, it can be a win or loose shot, if he feels it, he'll do it.

Jose Barea - Brainstem - This region is responsible for the basic bodily functions - breathing, temperature control, etc. Jose Barea's game is just as primal as this region- no, thinking, just doing - you are faced with a higher, stronger defender (or two), run into them and throw the ball.

Sean Marion - thalamus - This region is the communication relay system, just in the middle of so many processes. Sean Marion's game is similar, he is everywhere, does not start anything,  may end plays and glues numerous processes together.

Tyson Chandler - Astrocytes - this is the "skeleton" of the brain - it give structure and holds everything in place. Does not do any calculation, but everything would collapse without it.

Wednesday, June 8, 2011

Alan Kay's view on type systems

In here there's a very interesting correspondence with Alan Kay about OOP and his definition of it. Amongst other things, he wrote a short sentence that describes his view in the ongoing debate of static vs. dynamic typing.

Here's the exact quote:

"I'm not against types, but I don't know of any type systems that aren't a complete pain, so I still like dynamic typing"

I couldn't agree more. I don't recall even once that static typing actually helped me in designing software, I can recall numerous times that it just stood in the way, without anything to gain other then detecting errors in compile time, but only the kind of errors that any developer (junior or experienced) must be able to detect easily.

Monday, May 23, 2011

Did Don Giovanni want to be a lumberjack?

Just noticed it. Monty Python's Lumberjack song is really similar to Là ci darem la mano from Mozart's Don Giovanni.

take a look:
Here's the lumberjack song:




And here's Pavarotti doing Là ci darem la mano

Friday, May 20, 2011

Darwinian evolution of programming languages

In evolutionary biology, when the environment changes, the flora and fauna changes, this is done by adapting to the change and fitting the specie to the new constraints and new opportunities. This is the essence of Darwin's The Origin of Species - the survival of the fittest.

Same thing happened in programming languages.

During the early days, computation power and memory were scarce and expensive, thus programming languages in use were as close to the machine as possible, to exploit everything from these resources - think of LISP's car and cdr, which are based on specific registers...

After some time, memory was still expensive, but computation power become more available, therefore a new specie evolved - a language that allows to describe the computations done in a more "human" way (i.e., imperative), but still close monitoring of the memory is available. Think of C.

Computation power kept growing, and new programming paradigm evolved - OO, but still, memory is costly, and there was C++.

During the 90's memory became cheap, tight monitoring of it became unnecessary and more could be done with it. The stage was ready for the next languages to rule the Earth, and the era of virtual machines started - most notably Java and its JVM, but around that time also Python, Ruby and others appeared.

Computation power kept becoming more available, as well as memory. But times have changed. Multi-core processors are here, and are here to stay. More power now means more processors, not a stronger, single processor. New languages are now coming out of the primal ocean and taking their first breaths of fresh air (or doing parallel computations). These languages are the functional languages. They were around before, but just like the dolphins that returned to the ocean with enhanced brains and lungs to rule that habitat, It is now their turn to gain dominance.
It is not clear who will win this new race. Some of these languages have the advantage of being able to interact and co-exist with already running software and libraries - such as Clojure with the JVM, or F# with .Net.

Days will tell who will inherit the planet - exciting times ahead.

Friday, May 13, 2011

Clojure

I've started to write code in Clojure, which is a LISP dialect created for the JVM.

This means that the code has the aesthetics that can only be achieved when doing functional programming, while maintaining the ability to fully interact with existing Java based libraries and code.

More then that, Clojure comes along with a modern (almost futuristic) approach to concurrency, way different then the one Java has.

This is extremely important for a programming language, let me explain why.

A good way to think of concurrency (and especially data concurrency ) in programming  is to think about it as a mine field, where the locations in which the threads are interleaving and handling the same data are mines. Your code is the field.

Java's approach is "I'll give you the ability to place mines and I'll  also give you these small cocktail umbrellas to mark where the mines are". You just have to hope that you placed these little cute umbrellas in the right places and covered with them all the ways to access the mines. This is tough to do right in small scale software (where there are very few developers). Practically impossible to do right in large scale software (where there are too many developers).

Clojure's approach is different. It says "put as many mines as you want, I'll cover it with so much concrete, that it doesn't matter how many users are travelling in the field". The concrete itself is composed of immutable data, actors/agents model and software transaction memory.

(BTW, JavaScript approach can be summed up as "there shell be no mines")

I will not start to explain why concurrency is important, if you don't know, then probably you didn't read all the way up to here...

This is a delightful language to use (higher order function is by far the most beautiful idea in programming). It is powerful, efficient with a "no fluff just stuff" attitude with a potential to take your code to places that OO just can't go.

I guess that this is the reason why one of the first books written about Clojure is called "The Joy of Clojure", not sure that there are such titles about C or Java (a book with a similar title about C++ is probably aimed at the masochist community).

Try it, you will not regret and will not look back.

Tuesday, April 26, 2011

Stepback and Crossover

Crossover is a basketball maneuver that when done properly, allows the attacker to move pass the defender, but at risk that if the attacker wants to take a shot, the defender may be still close enough to block it. If the attacker needs to take a shot, there's another manouver, called stepback, in which the attacker (very very) quickly gets close to the defender and then steps back.


See here how Kemba Walker does a crossover followed by a stepback with a Baryshnikovian perfection.

Sunday, April 17, 2011

Research, Engineering and Novelty

It is possible to distill the research process into these steps:

  • Immerse yourself in a domain
  • Grok it till you can spot holes in it
  • Find an idea that covers one of these holes 
  • Show the novelty of that idea by the fact that it fills a hole or covers some aspect of the domain that wasn't covered before.
  • Prove the idea either formally using theorems and lemmas or present data that supports the it with some level of certainty
If you need to build a system to prove the idea, it is a disposable, one shot system, that solves the given problem and its set of users is the researcher / research team.

The grand finale of the research process is when it is dumped out as a research paper that is accepted to a journal or presented in a conference.

Engineering is somewhat different.

The engineering process is initiated when there's a need to solve a problem - which is done by constructing and materializing a solution (which does not have to be a novel one).
This usually involves a development process. The solution's novelty can be further protected as a patent.

In this process, a bulletproof and robust solution is the holy grail.
A successful system is one that:
  • Solves the given problem
  • Provides maximal output with minimal resources 
  • Can be used by many users (not just by the solution/system developers) 
The grand finale of an engineering process is a satisfied user (this can be someone crossing a bridge, a pilot flying an aircraft or a gamer playing in a virtual world).

I was, am and will be involved in both of these processes, so all I can say is that the understanding in which process you are is far more important then the kind of process you participate in.

Thursday, March 10, 2011

Beautiful code

I am currently reading the book Beautiful Code, which got me thinking "what is the most beautiful code I've ever written". The answer came up really quickly.
As part of my dissertation I developed an image analysis and statistical data mining and analysis software. In this software, one of the functions was responsible to detect correlation of events between two vectors, where each vector holds the times in which a neuron fired an action potential. This kind of computation is called cross correlation but with the constraint that the correlation is bounded by biological time frame (usually less then 100 ms).

The initial implementation looked as follows, where 'sVec' and 'tVec' are the vectors, and 'before' and 'after' define the biological time frame.


function crossCol = calcCrossCorrelation(sVec, tVec, before, after)
    numOfSourceMaximas = numel(sVec);
    numOfTargetMaximas = numel(tVec);
    crossCol = zeros(before+after+1, 1);
    for i=1:numOfSourceMaximas
        sourceSpikeLocation = sVec(i);
        for j=1:numOfTargetMaximas
            targetSpikeLocation = tVec(j);
            delta = targetSpikeLocation - sourceSpikeLocation;
            if(delta< -before)
                continue;
            end
            if(delta > after)
                continue;
            end
            crossCol(abs(-before - delta )+1) =
                             crossCol(abs(-before - delta )+1) +1;
        end
    end

This code basically runs on every combination of any event in the vectors and checks whether the combination occurred within the given time frame. It ran slow, really slow. To analyze data from one imaging session and to complete all the checks of all the cross correlations of all the cells I needed a few days, so I sat down to optimize this code, the final result looked like this:

function crossCol = calcCrossCorrelation(sVec, tVec, before, after)

distMat = bsxfun(@minus,tVec',sVec);
filteredDist= distMat ((distMat  >= -before) & (distMat  <= after));
crossCol = histc(filteredDist, (-before:after));

Thee lines of code.

The first line creates a distance matrix between the two vectors (using Matlab's utility bsxfun, which is very efficient). 
The second line is filtering out this matrix into a vector that holds all the cells whose value was within the biological time frame.
The third line bins all these values to a set of bins for all the values in the biological time frame (the set of values is defined by the 'before' and 'after' parameters and the sampling rate which affects which values would exist in this range).

This change made the same analysis run in a matter of about 30 seconds, as well as being beautiful code on its  own.

The updated code results from a change in the problem solving approach - thinking of the problem in terms of matrices and what can be done with vectors/matrices and arrays instead of thinking about each event on its own. This thinking paradigm is very powerful, especially when using the right tools (in here - Matlab).

Sunday, February 27, 2011

Equality, transitivity and JavaScript

One of the simplest ways to explain transitivity is using the equality operation, by saying that if A equals B and B equals C then A equals C. This is commonsense stuff, how can it be different.

Well, it can.

In JavaScript, the '==' (double equal) does type coercion, and therefore ends up in non-common-sense situation where equality in not transitive. See in the following example where  A equals B, B equals C, but still, A does NOT equals C :

'0' == 0 // true - the string 0 (zero) equals the number 0
0 == '' // true - the number zero equals empty string
'0' == '' // false - the string 0 (zero) does not equal empty string


seems that common sense is over appreciated...

Wednesday, February 23, 2011

Cause and effect

Got my self and iPad. Seems that now I need to go through a wide-smilectomy procedure.

Tuesday, February 15, 2011

Adding physical notion to user interface

Brilliant - user interface that behaves like it has physical properties like height and weight. More then that, it can be folded or hanged.
Also - note the round menu.

Friday, January 7, 2011

Usability of web applications

The web is rapidly becoming (or is now) the most important platform for new applications. The network bandwidth and the improvements of the browsers solve critical bottlenecks that prevented it from happening.
This results in application developers using lessons learned from desktop applications to improve and solve issues related to web applications.
One of the most crucial aspects of any application is its usability, and in the context of modern web applications, a key issue is understanding what are the main differences between desktop applications and web applications.
Usability, like many other development / engineering fields, revolves around handling constraints, in this case the major constraint is the user. We need to understand what differs the desktop application's user from the web application's user, taking into account that it may be the same user, which implies that the key difference is not be found in the skills / age / tech savvyness of the user, but elsewhere.
A good place to look for the difference is in the user's state of mind. Desktop applications users are basically bound to the application. They either bought it, downloaded it, got it as a present or are  forced to use it. The users of desktop applications are somewhat of a captured audience, they cannot go anywhere and need to put effort into solving problems that prevent them from using the application properly. In web application this is not the case. In this world, another application, that can do the same job, is a few clicks away. Users would't and shouldn't put any effort in "aiding the application" to help them use it. They will not read manuals, help contents and product literature, they would just go to the competitor.
The fact that the competitor is a few clicks away, and the fact that the users know it and does not have any problem in doing these clicks, needs to affect any web application.

Simplicity, smooth learning curve, excellent user experience, great visual design and being an eye candy is not a bonus, it is now the starting point for any web application, failure to do so would result in clients going away.

In my mind this is the key difference between desktop applications and web applications.