header image

Code style and noise


[1] Recently stumbled on the following post by Yan Cui  Seven ineffective coding habits many F# programmers don’t have

[2] His post is inspired by another talk of Kevlin Henney “Seven Ineffective Coding Habits of Many Programmers” . Must see!

[3] What really took my attention was the following blog post: Does the Language You Use Make a Difference (revisited)?
“Now I can base my analysis on two code-bases written in different languages on the same platform implementing the same application.” This is very intriguing not due to the inter-language comparison of the same app approach, similar but comprehensive study is available already online:  http://bit.ly/1Hdst9y
but the fact that’s a real life production app implemented in two conceptually different languages C# OO and F# functional. Considering the code bases of neither the C# and F# are available for further analysis we are only left with some statistics from his blog. It is a pity the projects are closed source though were made for a public institution.

It would be even better if we were to compare equal teams in terms of size and overall exp. Now that is hard ,but with more than 10years exp brought me to a conclusion that I always find hard to explain to any management :) More doesn’t necessarily mean neither better nor faster. In fact it is reversely correlated more often than never that a bigger team will most likely deliver worse code taking them more time to do it.
So here is something I could easily expect, give the same project to yet another C# team of equal size and expertise and evaluate the results systematically too.
From the table we are presented the one thing worth dropping is ‘useful code’ since it fails to be a metric in sharp contrast to the rest. Interestingly enough the data clearly points to the fact that blanks/spaces are not noise but simply background. Note for both cases they linearly correlated to the lines of code LOC.
Nevertheless, hypothesis is clear enough and the evidence points towards the point we have times more efficient implementation in F# than in C#. Still, is this due to function-vs-oo factors or simply due to the fact F# has language mechanics for clean contract based approach towards pure business logic? Questions like those are worth investigating than simply gathering of objective metric helping you make ultimately a subjective conclusion.

Noise in code

1: Code comments :
I agree in general. Code should be easy to follow and straightforward to understand. Have I touched on some tweaking in your code, please DO leave a few comments; some hardware quirk ( e.g. breaks accidentally on ATI cards drv# ). I recall tweeting recently “1 assert is worth 5 comments”.

However, the example given in is a bit off, considering the main reason for large comments blog on top of classes/functions is due to automated documents generation, a la Doxygen. Having docs along the code is something arguably bad since we want to keep it in sync/alive.
Enterprises just love docs and are ‘highly recommended’. It is a relevant part of a bigger picture of devops pipeline and hardly a point to be classified as ‘noise’. Whether and how much docs add to the quality of the code is another topic. No you can’t use unit tests as documentation for that purpose unless you use a lot of comments yet again.

2: Indentation and Spacing
Engineering 101 principle: don’t solve a problem that doesn’t exist while introducing a problem it wasn’t there at the first place. Perfect example: Python !!!
Now the correctness of my formatting namely tab, depends on formatting and ultimately what editor I use. How that is any improvement. So far I have not seen anything better than {} for my likings. Though, cmn! it is just a convention stick to it. spaces and idents? The consequences are either annoying for compile time languages or devastating in production for dynamic ones!

I came to the same conclusion that the most optimal read-wise style for C/C++ indeed is:

void function(

but even otherwise not really reading involves the bulk of code comprehension time in total.
Bottom line: I wished everyone stick with some 1 char explicit start-begin clause be that {}.

Applying the # substitution rule for C code as above seems to be the best layout for ‘zoom out’ overview of the function with quickly catchable header and body structure. Counter intuitive to treat text delimiters as noise and piece of convolution might clearly be useful.

3. Naming versus labeling

Nah, I rather say labeling helps way more for conveying meaning than naming. Names are arbitrary! What does my name say for myself? Absolutely nothing!

To start set/get are quite clear in context, in C# it is all about mutation. Even the redundant symmetric get/set is not a biggy! considering how many more important language design issues it has.

Try adding extra categorization to names doe’s not hurt and helps me instead, e.g. I have a list of classes names used in a large project. I can easily eliminate all class names with Exception in the end since those are not i look for exploring the OO model and logic. All classes now ending with Interface I know in what exact part of the model they gonna be used etc.

All of the places where I have encountered those were in similar semantics too. Not once I got pranked ;) Someone labeling tomatoes for potatoes ;)

Of course labeling goes as far as it goes, not under do it or over do it, common knowledge. For more naming/labeling doesn’t help a bit and you need more formal way of specifying contracts. Lambdas help for small body functions but I don’t see how no-name can be helpful for any sizable one.

4. Under abstraction

Good example with the tags for two projects of their data model namings. But this is design problem not a styling issue again. I also would like to see the tag cloud excluding language keywords. But how about where the most time of the program is spend? Now that something more likely to shed light on the full picture! I bet both will be strings driven in the end :P

5-7. The signal to noise ratio points to abstraction problems
duck typing and accessing internals this.typ1.internalList.add
intensions not to change
incohesive tests (unit test should be testing a single use case)

All those points are well on point and indeed points to broken models and unnecessary bloatware in general. Again, watch the full video. I’ve seen those mark over and over again in different codebases. Here is another one: if you use more than a few ‘if’s in a function/method you might be missing a model altogether. So if statements are also noise and we can continue down this lane.. ahh pure functions you win :)

The argument of left-to-right and top-to-bottom layout versus right-to-left is like arguing left handed road traffic (UK) vs right one (USA). Another infamous one OpenGL vs DirectX ( RHS vs LHS). You think right-to-left is unlikely, go tell it to an Arab. It is just a convention and it doesn’t really matter technically the least, something provable btw. The problem is in its duality nature and as long you stick to it, convention seems more important to me. You don’t want to cross lane like a drunk driver, do you?

If there is one thing to take from Kevlin’s talk is the slide
“When it is not necessary to change, it is necessary not to change ” (by Lucius Cary)
due to “If it ain’t broken don’t fix it” mentality I can testify for the number one reason why code bases got stinking bad in the long run. I can easily extend the topic under question ‘noise’ to the bigger set of ‘code-smells’ and postulate: ‘if it smells it is probably broken’.

Does languages really matter?

Yes, languages do matter and being multi-lingual does help you immensely to being more creative and be able to transfer practices from one to another. But so are many other factors important too, IDEs, tool-chains , library-support, etc.

Here is a perfectly purist functional implementation in LINQ (the functional C#), not sure if F# has the same behavior, but I’m not able to inspect any of the intermediates in the debugger !?!?!? How useful! when on top of that the rule for precedence for logic operators left-to-right is flipped too :S

IEnumerable stores = database.Stores
.Where(store => store.CompanyID == curCompany.ID)
.Select(store => new SelectListItem { Value = store.Name, Text = store.ID });

New languages always bring something to the table but more due to conceptual rather than syntactic & styling reasons.

DevOps Myths : Reinventing The Wheel

“Don’t reinvent the wheel” is one of the most common mantra one can hear around software developers today. It might only come second to “use the right tools for the right job”. While I agree more or less with the formal I’m way more sceptical of the first one. It is not like the statement does not hold any true and it definitely makes sense when put to context. Looking at the origin of the statement and how it came about, as to the best of my knowledge,  we can see the idea of reusable code in the form of general algorithmic routines, e.g. sorting. Such routines are often readily available as software libraries and every now and then a peer will remind you of the compete wasted time of trying to come with your own solution and that you should not try to reinvent the wheel. However, with just a bit of scrutiny on the validity of the statement to be generally true I quickly realized there is a big misconception surrounding it. Indeed when one consider an IT solution to be nothing more than moving data, transforming data, all together crunching numbers it might seem all you need is a wheel. Anyone with more than one shipped software product in the real life will tell that’s not entirely true and the reason being so: missing details. Then it struck me, what we deliver is not wheels but tires! If you agree so far the most natural question I would ask you next is: Why do we have so many different tires today, after all we need is wheel rolling around right?

Well… WRONG, unless you give me one design to fit all three cases in the picture below:


While in the case of the left most image low requirements might fit almost any wheel, the cases for the image in the middle and right you must agree demand for deeper engineering thought and design. We still talking tires here, hardly the highest tech achievement of today! If the mantra in question is hardly holding true for wheels how misleading truly is for IT?

Why this blog is not on GAE SQL PHP

Just before the end of 2013 I decided to give Google App Engine (GAE) for PHP a try. Together with Google GAE SQL instances available, it seemed easy enough to setup. Yes it was. In fact I went further to configure multi-site WordPress feature, quite valuable for multi language support for your sites. This is going to be a short post, so what did backfire? The GAE SQL has no free quota, that is to be free under certain load, so just for the first few hours setup and play time (no data import) a 0.30usd charge. Of course that was not such a deal. What really made me reconsider was the SQL instance spikes per 24h. Every 30min or so by downtime were followed by a 30min load spikes. AND YOU PAY for it. After 48 hours I had accumulated almost 2 USD on my account. Consider it running for a month and comparing to my current hosting plan of about ~6EUR per month and it is a no-brainer.

As it currently stays, GAE SQL seems quite a hefty price to pay for very small sites and casual blogs. Otherwise happy to report it was quite seamless experience.


Windows 9 Blue (PREVIEW)

First Look at Windows 9 (Blue)

Windows Blue

Microsoft has finally released a preview of its highly anticipated yet windows 9, code name Blue. As you can see from the screen-shot above, fully deserving it’s name :D

Yes, this is a joke! All the rumours of Windows 9 were short lived (delayed till late 2014 at best) , now that Microsoft had officially announced Windows 8.1 and 8.2  to be the next breed of the long line of Redmonds’ winsss.


Now seriously how about Windows 8

Is it a flop or is it just a slugger and does it really matter? FI

 First of all, it might be still too soon to claim whether Windows 8 has flopped. So far all numbers, which mostly come from Microsoft themselves, are pointing to very sluggish Desktop adoption of Win8 both on personal and enterprise PCs. On the mobile front, however, it is clear by now to both Nokia&M$ that win8 mobile has failed to gain any traction, regardless of the good hardware review of Nokia Lumia etc.

Still, Microsoft recent history of getting it almost right any other time might repeat itself and all we need is to wait for Windows 9 or 8.1 , 8.2 ???

The Big Elephant In the Room

The Big Elephant in the room hardly anyone talks about, is the fact M$ are closing their ecosystem and apparently shifting from OPEN to CLOSE. What becomes apparent with each passing year is how much really the Redmon’s crew (or at least the higher  management) want to be like Apple, but and that’s a BIG BUT, without any of the innovation. Thats is, they would like to take ~30% royalties off developers… for …. WHAT? Is it for the overhyped, by Microsoft alone, Metro UI. Left alone, whether it is a genuine Microsoft innovation or NOT, it seems not compelling enough reason for most people to consider switching from win7 to win8. Under such circumstances, it stroke me by surprise the lack of FREE available Win8 for DEVELOPERS ONLY.  It seem such copies were exclusively distributed  on MS tech events and only at the very beginning.  Or maybe ,they finally had figured it out, it is about : users, users, users and not developers, developers, developers.


My personal experience so far

It can be briefly summarized as confusing and dull. I consider myself  advanced user, having worked with all major OSs, yet I was struggling big time getting familiar with the band new win UX (Metro UI). Similar to many others, first and foremost frustration was the lack of start menu, with some indication of START button coming back. It took me 2 weeks to find out where exactly is my shutdown button. ‘Settings’, is the last place on Earth I expected it to find. Even more, it took me quite a while to get a hold on how exactly all sliding panels are getting invoked. For one think the lack of sticky edge/area makes sudden abrupt pop-ups a daily annoyance.

Although I wouldn’t go to the extend of the viral Windows 8 Under The Influence video, I must admin to the very EMPTY feel, which WinRT apps give. Ahhh all that waste of UI space.

The one Metro/WinRT app to summarize a lot about my win8 experience is none other but the recently acquired new toy in the arsenal of Microsoft, the infamous Skype.

  • Skype in full screen #@$%????

Here it comes: Hellloooo? Skype in full screen.!? An app that is primarily used as a chat program with contact list for calling! you make that a full screen on 24″+ screen and regardless of how many and big tiles my contacts are showing like, it still remains a huge waste rather than be slick and minimalistic.

  • Running 2 Skype Instances

That’s simply the culmination of retardness you can find in Win8 design. Application live double life. One can easily download in a few clicks a WinRT Skype. In my case, after a few seconds of shock and dismay I jumped on trying to install Skype for Win7. So far so good, it run and install perfect, after all it is just Windows7 in new clothes ;) Only then, did I realize the dual parallel co-existing of 2 Skype Instances running at the same time. The WinRT, which I had little success trying to kill it since it is not visible in standard task manager, was keep ringing while I’ve already picked a call on the classical desktop Skype client! Something, Skype is designed to prevent, being a single instance app.



What Microsoft should have done

It is not in my position to give advice on how … neither I enjoy to do so, but ….. this one comment from a post really stuck with me:

Have win8 and winRT as two distinct brands.

I’m great opponent of 1-fit-all models. What we observe is exactly the type of short sightedness in regard to user experience. The Desktop is not dead! Simply there is too much hype and hysteria around mobiles those days. You know, the cool new kid on the block. However, as far productivity goes, nothing beats a big screen with agronomic set of mouse and keyboard.  It might be because I’m getting old, or simply the lack of killer apps on mobile, but I see no way in hell I can start doing my job on anything but good old PC. Having Windows8 as just the next Windows7 is what many of us expected. On the other side, all hipsters could enjoy WinRT, a whole different experience with touch screen in mind.



If I dig not that deep into my imagination and look into the crystal ball it shows Windows7, becoming the new WinXP. Giving hard times to Microsoft when systematically try to deprecate it and any future support along along with it!

WOW Where my free space at?

… to be Continued … a quest for space and more….

UPDATE (23/10/2013)

I’ve just stumbled on a very recent article discussing Win8 IDLE battery life.  Why does Windows have terrible battery life. It is very relevant to the topic of how really suited Win8 is for mobile and tablet use.



Why XML?


Well… XML has been around for quite a while, since 1998 to be precise. Yet, I still find quite a few folks in the soft. industry to not getting it. Why XML? What really made it such a revolution for the web we still relish till today. One comment I’ve heard recently made it over the top: “Let’s do it XML, because it is easy for the computer to parse”. Now, XML is possibly the single worst format for a computer to parse. FKS comma separated file is even more efficient. In case an efficiency of data format is the most sought for feature, nothing beats the binary. However, it also lacks any structure, and is commonly referred to as BLOB. Usually a description to the data, a.k.a. metadata, is maintained in the form of format header with fixed size and format in the header, or maybe footer, of the file/BLOB. Where the format of the header you can usually find from some documentation.

So far this is all common knowledge, all well known. XML is descriptive language and we can easily format structured data, keeping both data and metadata tight together. However, this alone is only part of what makes XML so great. To summarize, the reasons for a developer to consider XML goes as follow:

  • open standard specification
  • structured data
  • the XML stack (XML, XSD, XSLT)

The real power about XML comes from the third bullet point. That is the XML stack, or more precisely XML and the two other technologies, the schema definition language XSD and the XML transformation language XSLT. Unless, you are planning on using XML with any/both of the other two you might as well be much better using JSON. For being more efficient, less verbose, serving nicely the need of structured data alone.

The XML Stack

The XSD schema language is where one can describe a particular format for an XML file for his/her application. The benefit being that you can validate any XML against the XSD schema usually with one line of code. That feature alone makes classic SOAP Web Services still common today where any consumer of the service can validate its input data. However, combined that with the possibility to transform, that is to change the format of any XML from one to another, using XSLT and you end up with quite powerful stack.

The fact XML is standardized and it’s been around for more than a decade, gone through several revisions, makes it mature and quite well adopted. There are stable libs available for almost any platform you can think of.

Good Intermediate Format

Have you realised the power of the full XML stack, you can easily see that it helps you create CORRECT solutions to a common scenario. The scenario being: data shuffling and mapping. Which often encompass the bulk of most IT solutions out there.

It is easy to derive domain specific dialect. Making it, extremely easy to create open specifications. The most infamous example I can think of is HTML. Surprisingly many people are not aware that HTML is nothing more than specialized XML.

Although, the XML stack helps derive a correct solution, not necessary it is an efficient one.

Optimizing XML

One of the most common drawback of using XML boils down to the following points:

  • too verbose
  • size overhead
  • XSLTs are hard
  • XSDs are limited

I will cover only bullet point 2, size overhead. Since the rest I consider more or less, it is what it is, leave it or live with it. Still, the size overhead mostly has to do with the verbose expressions in XML.

There are plenty of things one can do to keep the size of XML to reasonable size. Starting from least intrusive, switching compression on HTTP transport level, to more intrusive like creating a lookup table of tags. Let me elaborate a bit more on the second option. The idea is to have on both end of communication, the same lookup table which maps verbose to HEX , and vice versa. Most cases will require less than 256 big dictionaries of tags, thus the 1byte size will suffice, in the range 00 – FF.

Keep in mind. I’ve not seen this second approach to mitigate hefty XML sizes, neither I’ve attempted myself doing so. I guess first approach is easy and good enough.

Structured Binary Data

In case performance is not mission critical and interoperability of binary data is of any concern, there is the public BSON binary format. Short for binary JSON. It is lightweight, traversable and efficient. http://bsonspec.org/

Another alternative is Google’s Protocl Buffers, http://code.google.com/p/protobuf/


To wrap it up, here is the moral of the story. Formatting the data is as important, if not even more, as the data itself. I’ve seen over and over again where developers makes the decision quickly on the fly. Often the wrong one!

Skype Virus Swipe Through Eastern Europe

In the past 2 weeks a huge wave of windows infection was observed on the Skype network. Mostly in the eastern Europe, Ukraine, Russia, Romania, … including Bulgaria.

It starts with a friendly message from someone from you contacts list, asking you to check out a photo of his/hers.

Here is a zip file of the file in question. MG0540250-JPG.scr