What ever makes code beautiful ...

Firmitas, Utilitas, Venustas
"Vitruvius, a famous architect, asserted in his book De architectura that a structure must exhibit the three qualities of firmitas, utilitas, venustas -- it must be strong (or durable), useful, and beautiful. This is true of any good design. It must be durable and not crash. It must provide some utility and commodity. Finally, it must be beautiful and delight the user enough so they'll want to return to use the artifact again.
Similarly, the AIGA describes good experience design as containing the same three necessary criteria: useful (providing a needed function), usable (providing an experience that does not break down), and desirable (providing an interaction that people want to experience)."
(quote taken from  http://www-128.ibm.com/developerworks/ibm/library/i-osource2/)

Useful (Utilitas)
Needed by customer

  • Ramesh Sinha - It because, As soon as this problem was brought to my notice, I realised what the gravity of the problem

  • Gopa - Necessity is the mother of invention 

  • Gopa - Lastly, without this feature we would never have been able to extend Perl (LTT extends Perl with LTT specific C++ callbacks).

Performance - Fast

  • Narasimha Murthy - Relatively near zero mutex lock holding time

  • Mandar - The code can speed up any c++ multithreaded application doing heavy memory allocation/deallocation without any code changes.

  • Mandar -  On multi-core/multi-processor machines this code can speed up the multithreaded application by a factor of 2 in most cases.

  • Narasimha Murthy - Without bending, breaking compatibility achieved exponential performance increase

  • Raghuram Gundimeda - And it is pretty fast in processing.

Previously unaddressed special case

  • Vijay Srinath - This code basically < …>. This was the approach used to selectively < …>.

  • Suresh Gopal - The code depicts pure native COM automation without any wrappers.

  • Srihari -  It basically implements a full-fledged feature for Data Protector

Big bang for buck

  • Narasimha Murthy - Just by reordering one member (REC_MUTEX  lock in struct _dirlock), direct addressing of a node in the linked list was made possible

  • Narasimha Murthy - Exponential performance improvement

Usable (Firmitas)

  • Narasimha Murthy - Simple algorithm greatest benefit

  • Mandar - Depending on the system memory and depending on the memory usage the application can set the size of initial heap memory for each thread specific heap by call to function HeapCreate, at present it is 10MB.

  • Vijay Srinath -  I am not sure if any of the code that I have written qualifies as crafty but it works (most of time atleast :-).

Well structured (Easy to understand/ Easy to use)

  • Srihari - The code is very-well structured with respect to the problem/feature for which it has been written. The problem can be solved using the traditional software engineering "top-down" approach and the code has been structured accordingly

  • Mandar - A heap for a thread is created on-demand, whenever operator new is called for the first time from that thread. This does not put too much pressure on the system and does not fragment the virtual memory.

Alignment between analysis & design

  • Srihari - The data structure design/definitions correspond with the data organization in the problem

  • Suresh Gopal - The modified code for .NET illustrates advanced techniques such as CLR Hosting.

Good housekeeping

  • Srihari - Memory allocation/freeing, exit conditions are addressed

  • Mandar - The code can take care of memory allocated even by a third-party library or a dll, it internally traps the calls made by each thread and routes them to thread specific heap.

  • Gangadhar Singh - Optimized to maximum extent.

  • Gopa - Because this one line of code change is hidden under ~30MB of Perl source , it took me ten, 16 hour days, to read through nearly half that code to make out what to change, and I finally cracked it at around midnight on a Saturday!!

Desirable (Venustas)
Easily understood

  • Srihari - Each function does the task that the name of the function spells out - so the entire code flow can be easily understood.

  • Srihari - Function headers and comments throughout the code make it easy to follow

  • Gangadhar Singh - Readability ( Written is English); Unnecessary header files are not used; Sufficient comments are provided; Sustenance of this code would be easy.

Simple to incorporate

  • Mandar - The application just needs to be recompiled with this code in form of a library or a dll.

  • Narasimha Murthy - Near zero risky change in a patch

  • Stands the test of time

  • Raghuram Gundimeda - the code is still being used without any changes or defects.

  • Shahbaz shaik - The code I have attached is more than 3 years old and the logic is almost the same even today. That makes me feel even more satisfied.

Aha Experience (my first time)

  • Shahbaz shaik - The good thing I feel is the recursion here, which was a little difficult for me to understand when I was a beginner in my career.

  • Raghuram Gundimeda - This is one of the first important functionalities I implemented …

  • Respect from Others - Endorsement

  • Gopa - Novell’s Perl support engineer posted this message in the official Perl support forum: “Gopa built Perl 5.8.4 using CLIB for his custom application  where  he fixed the problem  by replacing  fsetmode instead of setmode() to fix the binmode problem. Gopa!  Have a nice sleep.”

  • Gopa - And this one from Novell’s official support engineer (asking for help in compiling Perl source with a specific compiler!!) “hey man, I'm trying for half a year now compiling the php_perl and the mod_perl modules so that they fit to Novell's Perl 5.8.4 - however regardless what sources I try, what compiler switches, I cant properly include the Perl headers! so I would like to ask you if you can pack your headers + imp which are known to work with CW”

Respect from Others – unstated but Successful comparison

  • Gopa -  Because once I designed and implemented it, I learnt that Internet Explorer has a similar mechanism implemented to maintain session status!

  • Gopa - It took me so long to realize it, and I had to really debug through assembly code to make it out! // It had another architect who struggled for nearly two weeks to get this done. He gave up hope, pinged me and I just had to copy-paste the above code and email him! And I always thought only I would run into this problem…

  • Ramesh Sinha -   No comments and uses sed and grep ( if the reader thinks so!)  but to him it *is* beautiful? (cryptic and therefore for the experts only versus easy readability)

  • Gopa -  And I had another team coming back and asking me whether I could share this blueprint with them because they wanted to implement a similar mechanism!

More about this experiment

  • I sent a message out to my team, asking for examples of what they thought was beautiful code. Not everyone who saw beauty in code responded and not everyone who responded clarified in words on why they thought the code was beautiful. None the less, what you see is a compilation of the comments I received.

  • Think about why YOU find code beautiful. It might tell you why you enjoy your work and how you can set yourself up, to enjoy it even more.