Skip to main content

Posts

A-Team Library !!!

A short while ago, I had to write a compelling document for a client about a library that I had developed during my tenure, call it A-Team Library or ATL . Having to learn the " eyes-wide-shut " culture to maintain the couples-of-decades old code and simultaneously develop on the top of it was very disheartening. It was time a lot of things were given fresh thoughts. Not the least of all duplication of code and functionality . But not just that. Like in a programming language, when there is more than one way of doing something, when those ways are opposing, it causes nothing but confusion. So was the case. The business seemed to be far from realizing it.Instead of showcasing the issues that were being faced and yet not realized, let me state the alternate - how things in such cases can be better: Business has to realize or let known: When the engineering team accepts the authority of the business in deciding the priority of features, the business has to be prudent enough...

The Secret behind Bjarne and Herb's Papers on Unified Call Syntax !!!

A long time back, in one of my posts here , I had discussed about Extension Methods ... in C++; sorta! It seems that the grand daddy, Bjarne Stroustoup , had read my post, and was impressed. So he has published a paper - Call syntax: x.f(y) vs. f(x,y) . Good thing except I don't like the idea of assuming x.f(y) for f(x, y) while the reverse is the actual idea of extension methods. You will know when you read his paper. It seems the commander,  Herb Sutter , also was impressed with my post. Not only that he too doesn't seem to like the x.f(y) for f(x, y) idea. Great men think alike. LOL! So he published his paper -  Unified Syntax . How is that? Needless to say, I was completely kidding about the Herb and Bjarne about borrowing the idea of extension methods from my post. I wasn't even born when Bjarne invented C++. The papers are detailed and deep in considering various scenarios from a language standard perspective unlike my post where I just spotted the existin...

A Simple Tree List View !!!

Digging up stash is one of the best pass times. You know you never know what you will find. I had an article written quite some time back but had not posted it anywhere. Not sure why. I posted it at CodeProject - A Simple Tree List View .

PHP Savers - PropertyBag !!!

The ubiquitous and the universal data structure in PHP is the array . It is an amalgamation of commonly used data structures - list, map etc. In the recent times, PHP has also adopted object orientation and introduced classes. The syntactic difference in the way a property of an array and object poses an inconvenience in the user code 1  specifically when there is a need to interact with code that is not open for change; legacy or not. JavaScript would allow you to access an object property either obj.propName or obj["propName"] . That does come in handy for sure. Besides, accessing the property by [] tags is the only way if the property name contains characters like hyphen: obj["prop-Name"] . At the user code level, it is fair to see an object as a bag of key-value pairs. Along the same lines, it is not wrong to expect the same in PHP between an object and an array; although there is a fundamental difference 2 . The expectation arises when ...

Cool Regex Testers !!!

Anytime I have to play with regular expressions, I use one of the online regex testing web sites to come up with the regex I need. Last couple of times I had to come up with a regex for most common everyday stuff like dates and such. Oh yeah, last time it was date actually. I had a server response that had a date in the format yyyy-mm-dd , ISO format. I was working with JavaScript, and initially I was naive to use the Date class to parse the date in the response. Turned that there is difference in the way the date is interpreted by Firefox and other browsers. Ok, this is not a rant post about the Date class but actually share some sites that help you with regular expressions, of course at different levels. Here is a list of such sites: http://regexpal.com/ http://regex101.com http://rubular.com/ https://www.debuggex.com/ http://www.freeformatter.com/regex-tester.html In the above list, I like the last but not the least - freeformatter.com . The cool thing about freeformatter ...

Overloading vs Variable Arguments !!!

In a statically typed (object oriented?) language, function overloading offers the facility of organizing your code into two or more functions with different types and/or number of arguments. This is highly useful when the functionality offered by the function can be invoked in different scenarios. For instance, let us consider the function(s) below: // C# code Dictionary<string, object> CreateResponse(string msg) { return CreateResponse(ex.Message, 0, false); } Dictionary<string, object> CreateResponse(string msg, int code) { return CreateResponse(ex.Message, code, false); } Dictionary<string, object> CreateResponse(string msg, bool success) { return CreateResponse(ex.Message, 0, success); } Dictionary<string, object> CreateResponse(Exception ex) { return CreateResponse(ex.Message, ex.HResult, false); } Dictionary<string, object> CreateResponse(string msg, int code, bool success) { var errorInfo = new Dictionary<string, object>(); erro...

Getting reminded of the reminder !!!!

I have been using Android for quite some time now, and only recently I noticed that Android pops up a notification reminding you of a reminder . It says "Upcoming alarm - Buy Milk", where Buy Milk is the reminder I had set. Is it smart enough to help a lazy volatile minded guy like me or is it trying to be my wife who would not rest until I buy milk? Don't know.

jqGrid: Handling array data !!!

This post is primarily a personal reference. I also consider this a tribute to Oleg , who was fundamental in improving my understanding of the jqGrid internals - the way it handles source data types, which if I may say led him in discovering a bug in jqGrid. If you are working with local array data as the source for jqGrid, meaning you will get the data from the server but want the jqGrid not to talk to the server anymore, and want to have custom handling of the edit functionality/form and delete functionality, it is not going to be straightforward - you need to have a decent understanding of how jqGrid works, and you should be aware of the bug Oleg pointed in our discussion. I repeat this is all about using jqGrid to manage array data locally, no posting to server when you edit or delete, which is where the bug is. $('#grid').jqGrid('navGrid', '#pager', { recreateForm: true, add: false, search: false, refresh: false, ...

Clean Code

I received quite a lot of criticism for  Dealing with Bad Code . The criticism was mostly along these lines - "There is no good or bad programmer. The good programmer thing is more of an illusion. When you place a programmer in a domain in which he has little or no experience (like a PHP web programmer writing C++ code), he will soon be seen as a bad programmer. What is branded good or bad is subjective." Although it sounds to make sense, I don't completely agree with that. Maybe the topic of the discussion was ambiguous. It wasn't the programmer but the code. I am not willing to spend my energy to demotivate somebody by branding him a bad programmer. But I will in reviewing anybody's code, not just brand it bad code but ultimately clean it up. I believe programming isn't restricted to language. Although the language used to program has its impact on the way a problem is solved, it doesn't limit the programmer from losing the basics. In other words, a...

The Windows Phone Epic !!!

Dear Reader, Do not be overwhelmed at the length of the article. I have tried my best to keep the length of the article not directly proportional to the time required to read it. Oscar Wilde said, " If you want to tell people the truth, make them laugh, otherwise they’ll kill you ". There are times when truth tends to be subjective, such as this article. However, I have definitely added the fun component to keep up earlier promise. Consider the time you spent reading this article as a break from your work or routine. I am sure you will enjoy it; doesn't matter if you are using a Windows Phone  1 . Perhaps you will read it again. I am programmer  2 , gadget savvy, an avid fan of Microsoft products (especially Visual Studio and associated suite of development tools), and an honest critic of any product I use. I have an Android Phone, an iPhone, and for a few months now, a Windows Phone. And this is my experience with the Windows Phone - good, bad and grey. To be...

Dealing with Bad Code !!!

Read this fine article by Joel Spolsky : Things You Should Never Do It is a great article, one that invokes mixed feelings. The article talks against rewriting (large scale) software.....from scratch. Joel was kind enough to consider all those who write software as true programmers ; people who give enough thought and not just code up something that works. However, it is far different in the real world. That said, I am neither completely in disagreement with Joel nor am I advocating to rewrite large scale software once the code is identified as a mess. Most people who are programmers are just people who write code for a living. Nothing wrong but forget the passion part of it. So the quality of the code that is generated is questionable. True programmers are different. They first build those intangible constructs in mind of how the code should be, and then they write code that reflects to the reader the intent of the task being achieved. Hence such code is readable, modu...

Linked List Quiz - Part II !!!

In the last part , we saw the academic (not general purpose) version of a Linked List used to solve the puzzles, and solved the following puzzles on linked list. Reverse the list recursively Reverse the list iteratively Find if a list is cyclic In this part, I will be solving the remaining two puzzles that I listed in the last part. Finding the cyclic node in a cyclic linked list According to my solution, the node which is actually supposed to be the end of the linked list is the cyclic node. Let us call Cn. Taking node Cn as the cyclic one has an advantage wherein you can break the cycle; assign Cn->next = nullptr; But some people take the node after Cn as the cyclic node. The node after Cn is the node somewhere back in the list. This way it is not possible to break the cycle as we would traversed past Cn. LinkedList::Node* LinkedList::FindCyclicNode() const { int iterCount = 0; auto jmpBy1Ptr = root; auto jmpBy2Ptr = root; while (jmpBy1Ptr !...

Offering __FILE__ and __LINE__ for C# !!!

THIS POST USES SYNTAXHIGHLIGHTER AND HAS ISSUES RENDERING CODE ONLY IN CHROME Not the same way but we could say better. Visual Studio 2012 , another power packed release of Visual Studio, among a lot of other powerful fancy language features, offers the ability to deduce the method caller details at compile time. C++ offered the compiler defined macros __FILE__ and __LINE__ (and __DATE__ and __TIME__ ), which are primarily intended for diagnostic purposes in a program, whereby the caller information is captured and logged. For instance, using __LINE__ would be replaced with the exact line number in the file where this macro has been used. That sometimes beats the purpose and doesn't gives us what we actually expect. Let's see. For instance, suppose you wish to write a verbose Log method with an idea to print rich diagnostic details, it would look something like this. void LogException(const std::string& logText, const std::string& fileName...