The ubiquitous and the universal data structure in PHP is the [array][1]. 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 code1 specifically when there is a need to interact with code that is not open for change; legacy or not. More ...
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.
More ...
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: More ...
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.
More ...This post is primarily a personal reference. I also consider this a tribute to Oleg, who played a big role 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. More ...
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. More ...
Dear Reader,
Do not be overwhelmed by 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.
If you want to tell people the truth, make them laugh, otherwise theyβll kill you - Oscar Wilde
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 programmer1 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 begin with, the Windows Phone landscape (app and feature set) is dry and unpromising. There are a few good things here and there to console ourselves for the money we spent on the phone, and for the love of Microsoft!
More ...
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.
More ...
In the previous post, 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.
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
Cn
. Taking node Cn
as the cyclic one has an advantage wherein you can break the cycle; assign Cn->next = nullptr;
LinkedList::Node* LinkedList::FindCyclicNode() const
{
int iterCount = 0;
auto jmpBy1Ptr = root;
auto jmpBy2Ptr = root;
while (jmpBy1Ptr != nullptr && jmpBy2Ptr != nullptr && jmpBy2Ptr->Next() != nullptr)
{
jmpBy1Ptr = jmpBy1Ptr->Next();
jmpBy2Ptr = jmpBy2Ptr->Next()->Next();
if (jmpBy1Ptr == jmpBy2Ptr)
{
const int noOfNodesInLoop = CountNoOfNodesInLoop(jmpBy1Ptr);
cout << "No of nodes in loop: " << noOfNodesInLoop << std::endl;
auto p1= root;
auto p2 = GetNthNode(noOfNodesInLoop - 1); // zero based index
cout << "Node at index " << noOfNodesInLoop << ": " << p2->Item() << std::endl;
// Pointers meet at eye of the loop (this node is as per point #2 above)
while (p1 != p2)
{
p1 = p1->Next();
p2 = p2->Next();
}
// This piece of code takes you to the loop starting node (this node is as per #1 above)
p2 = p2->Next();
while(p2->Next() != p1)
{
p2 = p2->Next();
}
return p2;
}
++iterCount;
}
return nullptr;
}
int LinkedList::CountNoOfNodesInLoop(Node* stopNode) const
{
int count = 1;
auto p1 = stopNode;
auto p2 = stopNode;
while (p1->Next() != p2)
{
p1 = p1->Next();
++count;
}
return count;
}
The code above is the result of several iterations of discussions with Azhagu. It wasn’t written that way the first time. The first version was much complex and naive. I think it looks better now. What do you say?
More ...
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.
More ...