Vijay Krishna's Notes http://vijaykrishna.posterous.com Most of my notes as a student of computer software and everything around it. posterous.com Fri, 15 Apr 2011 17:20:29 -0700 An SQL puzzle http://vijaykrishna.posterous.com/an-sql-puzzle http://vijaykrishna.posterous.com/an-sql-puzzle Check out this little snippet of SQL: [sourcecode language="sql"] SELECT PRAMvtID, PRAMvtRALoadDteTme, PRAMvtRAStatus, PRAMvtRAType, PRAMvtRAApprvlStatus, PRAMvtCompany, PRAMvtDeliveryNetwrk, PRAMvtMeasurePoint, PRAMvtSalesMonth, PRAMvtTicketNo INTO #complete_tkts FROM PAPRAMovement d WHERE PRAMvtID IN (SELECT PRAMvtID FROM PAPRAMovement dd WHERE dd.PRAMvtCompany = d.PRAMvtCompany AND dd.PRAMvtDeliveryNetwrk = d.PRAMvtDeliveryNetwrk AND dd.PRAMvtMeasurePoint = d.PRAMvtMeasurePoint AND dd.PRAMvtSalesMonth = d.PRAMvtSalesMonth AND dd.PRAMvtTicketNo = d.PRAMvtTicketNo AND dd.PRAMvtRAStatus = 'C' ) [/sourcecode] When my friend showed me this snippet, i was a little amused. I asked why was the extra nesting required when he was using the same table to compare? He could have might as well gone with this: [sourcecode language="sql" highlight="13"] SELECT PRAMvtID, PRAMvtRALoadDteTme, PRAMvtRAStatus, PRAMvtRAType, PRAMvtRAApprvlStatus, PRAMvtCompany, PRAMvtDeliveryNetwrk, PRAMvtMeasurePoint, PRAMvtSalesMonth, PRAMvtTicketNo INTO #complete_tkts FROM PAPRAMovement WHERE PRAMvtRAStatus = 'C' [/sourcecode] But thats when he told me that, the query was designed in that manner for a reason and he was not able to figure it out. Thats when i actually sat up and started to pay attention. After 5 mins of close inspection of the snippet, i realized that this was a brilliantly  designed query to perform grouping of the PRAMvtIDs in the following group order of the table coloumns:
  • PRAMvtCompany
  • PRAMvtDeliveryNetwrk
  • PRAMvtMeasurePoint
  • PRAMvtSalesMonth
  • PRAMvtTicketNo
Now one might ask, why not use a simple GroupBy instead. This argument grows stronger when u realise that the grouping with this query will not be a perfect cascade. The grouping will take place in a random fashion based on the way the above 5 values are encountered in the table row by row. What i am getting at is that the data will not be ordered, but it will be grouped.
So the question remains... why not the group? For one, if this query was to be used in Linq, then it would return a List. But if one were to use the Groupby, then what you would get is a Dictionary. So, i guess it is a pure matter of choice. It was an interesting query. It taught me yet again that most things in life should have a purpose, for their existence.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1369599/pic.jpeg http://posterous.com/users/hcGXxsTkwP6SS Vijay Krishna Palepu vpalepu Vijay Krishna Palepu
Tue, 05 Apr 2011 06:46:48 -0700 Coding (vs) Logic 1 http://vijaykrishna.posterous.com/coding-vs-logic-1 http://vijaykrishna.posterous.com/coding-vs-logic-1 Yes sir!! it is a battle of clans! Today all thoughts all ideas are going to come down here. And i am holding nothing back. It is a great war this. In the world of software development there are those believe that it is the Coding that matters more than the logic! startling claims indeed. And maybe that is the reason why they have been loosing as well. Logic undeniably is ultra important when it comes to developing software. Those who somehow claim that coding skills can outshine logical abilities, obviously have issues with their logic. But then i sat down thinking all these years and more so in the past few months, thinking if there was/is any logic in what they said. Can coding truly be as important as the logic, where it is built upon that very logic? That was the question going through my head. And that is when i realise that, i was asking the wrong questions. While the theme was the same all through... code vs logic, the concept or the understanding behind their relation was wrong. The real question is this: Can coding truly be as important as the logic which are nothing but mechanical transformations of each other? And with great thought and pondering, i think yes! In fact, Logic and Code are equally important in the whole process of software dev, and this is irrefutable. You see, like i mentioned above, code is nothing but the mechanical transformation of logic. While logic addresses the solution to a problem, coding addresses the solution to the problem of rendering that logic. Logic is devoid of syntax. It is concerned with the mechanics of how a given issue or problem can be resolved. And hence, it is a more universal phenomena. Be it programmer, a manager or an army General, all use logic. They all render it in their own manners. The General does it with Battle Formations, a Manager with Resource Allocation Charts and a Programmer/Coder does it with Code. So, Code like a Battle Formation or a Resource Allocation Chart, is a tool to render the logic used to win a battle or solve a problem. If this use itself is not logical, then there will be issues. If the troops are not commanded properly by their battalion commanders then the army will loose. If the junior managers do not follow the charts properly to allocate resources, then there will be surplus at one place and scarcity at another. If the code is not used correctly then exceptions and bugs will occur. Its that simple. Now do you get the point? Let me put it in a single statement:
Logic renders the solution to a problem, while code renders that logic.
Thus, without the code, you cannot go out to kill the problem. Logic alone is not the answer. So its time that the two clans ack this and greet each other with open arms and paramount respect. Then i thought about how one should go about dealing with logic and coding. I guess that there will always be infighting between the thinkers and coders in any team. Of course the successful bunch are both: coders and thinkers. But coming back to the point, to avoid the natural conflict between logic and code, it is best to isolate the processes. Yes, there is no innovation in this age old idea, i agree. But i am talking blunt firmness. Isolate the two process completely. Do not even think about one when u are busy working on the other. My manager and mentor in my firm has been telling me this right from day 1:
When you are working on the logic/design for a problem, do not think of how it will look in code."
I guess he forgot with the second part to such an apt statement. Never think of the problem and its logic or its design when you are coding. Even though you know that something is wrong, trust it blindly. Get the bugs right. Resolve the issues. Once the code is running and is rendering the given logic then get back to the logic development and enhancement. There is no point shuttling between the code and logic design. Imagine if a General were to do that in a battle: 1. Come up with a Battle Formation. 2. Send the troops in to battle in that formation and the associated orders. 3. "OOOPS!!!" Realise that the Formation and Orders were wrong. 4. Call the troops back, which is half way through the battle. Here we are assuming that a lot of loss has already taken place. 5. Goto step 1, if you have not already lost the battle or if all your soldiers are not already dead. See the issue with the toggle approach if it were employed in a battle. Treat everyday software development as a battle. You are bound to make more profits by making and selling better software than you are making and/or selling right now.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1369599/pic.jpeg http://posterous.com/users/hcGXxsTkwP6SS Vijay Krishna Palepu vpalepu Vijay Krishna Palepu
Sat, 02 Apr 2011 12:44:14 -0700 Musings over originality... http://vijaykrishna.posterous.com/musings-over-originality http://vijaykrishna.posterous.com/musings-over-originality "Originality does not mean thinking something that was never thought before; it means putting old ideas together in new ways." The word Originality has a wealth of meaning behind it. It refers to something which is original i.e. new, different or unusual. Something that has never been seen or heard off before. At the same time it also refers to something that is a result of independent thinking. Thus originality of thought or work is two fold. It can be a completely new idea, theory, machine, system, etc. It can also be a new inference or interpretation of the existing idea or theory. It can be the combination of 2 or more systems/machines to give a new system which helps us solve problems related to the previous systems or those which are completely different. Thus, originality is both: the thinking of new ideas as well as putting together existing ideas to get something different.
At the same time one must note that putting together old ideas may or may not give things that are new. For example there is no point in putting together all the theories in the world in the world in order to prove "two times two gives four" or "the world is round". Originality is when, we get new ideas or inferences from existing ideas and thoughts.

Nearly everything thing in this world is derived from some existing conclusions and facts. Without those facts one cannot come up with something new. At the same time coming up with something new, independent of any previous knowledge or idea is originality as well. Think back for instance the originality of the early man who discovered fire with out the help of any previous knowledge or idea. It might have been a simple accident, but it was original for him, as he had never seen it before. There have have been so many instances when two different scientists came up with the same theories and ideas at the same time but were worlds apart. In such cases both their works have to be considered original as they did it independently.

Nothing in this world is new. Everything is present and waiting to be discovered or invented. It can be done by digging a hole or rearranging a machine. What spells originality though is that which the masses have never seen before. What is original for us Humans may not be so for another species. This is the crux of the matter. Charles Babbage's originality lied in coming up with the difference engine, arguably the world's first computer. Intel's originality lies in coming up with a computer architecture which out performs other architectures. The difference engine was an idea waiting to be thought up by someone. As it was finally a chain of thought which led to the idea of the difference engine. But, at the same time it was something new and original. It was extremely different than any other machine of those times. That is what gives it the tag of originality. Intel however will come up with a new and improved architecture by studying the present architectures and not by coming out with a totally new concept all together. It will still receive a tag of originality as it will come out with the fastest running architecture of its time.

Thus originality of an idea can be decided only if it is different or unheard of before. It does not matter if the idea was independent of any previous knowledge or if it was derived from old ideas or thoughts.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1369599/pic.jpeg http://posterous.com/users/hcGXxsTkwP6SS Vijay Krishna Palepu vpalepu Vijay Krishna Palepu
Fri, 28 Jan 2011 17:31:57 -0800 The Curious Case of Artificial Intelligence http://vijaykrishna.posterous.com/the-curious-case-of-artificial-intelligence http://vijaykrishna.posterous.com/the-curious-case-of-artificial-intelligence
Did you know that the first Matrix was designed to be a perfect human world? Where no one suffered, where everyone would be happy. It was a disaster. No one would accept the program, entire crops were lost. Some belived that we lacked the programming language to describe your perfect world...But I belive, that as a species, human beings define their reality though misery and suffering. - Agent Smith, The Matrix
This is probably the best way to define the human case. Infact, it is the best way to define the case of any sentient species. It is not our advances that define us, but our failures and imperfections. Today, my friend and i were having a very animated discussion on Artificial Intelligence at office. He spoke of AI agents and fuzzy logic and i was going on and on about the powers and shortcomings of the Artificial Neural Networks. All that talk led us to how technology and science has advanced to some very brilliant leads in this vast and illusive field, which encompasses Computational Theory, Biology, The study of the Brain, Psychology and Mathematics. However, very soon we started talking about what is yet to be done and we soon came to a common conclusion: there is no point in understanding and studying artificial intelligence, if the final aim of the subject is to emulate human/animal thinking. Why? Simply because of the fact that human thinking is about how we make mistakes and recover from them, not how brilliant we are at coming up with the best algorithms and solutions. You ought to study Natural Stupidity instead of Artificial Intelligence to really get a grasp of how human beings think. But then, is that really the true purpose of the subject. I think not. I think the crux of Artificial Intelligence is to develop some very superior methods of evaluating tough and computationally difficult problems. It is more about taking the efficiency and speed of a machine, and the computational agility of a natural brain i.e. the best of both worlds. While we have already understood and mastered the way of the machine and its efficiency and speed, we are yet to tackle the more complex issue of the brain. It is due to this exact situation, that the study or probably the exploration of the brain has been associated very vehemently with the study of AI. Many do not realize that it is not the central focus of the subject. For had it been that way, then every AI course would require a minor prerequisite course in Biology. Computer Scientists have always first tried to see if they could introduce the agility of a natural brain into their algorithms. They probably never wanted to even look at the brain beyond a point. It so happens that boolean algebra has its limitations. Or atleast we do in getting a complete grasp of the matter. Let me assure you this, the day the scientists have found a means to do what i just mentioned, a significant population of the world will loose interest in understanding the brain. I have always believed, that the day we can define a "smile" in terms of mathematical equations, we have shut the case of AI. Maybe that day, the difference between our brain and the best known algorithm would be close to nothing. But then the question remains, who will have to shift to bridge the gap? Will we finally unlock the secret to the brain and emotions as they exist today? Or will we have changed so much, in our quest for the answers, that our own thinking and emotions would become more machine like? Here is a random thought: if we were to unlock the secrets of the brain, would we not have developed mentally in doing so, and thus there would be so much more to learn about our newly developed aspects of our brain? So isn't it really a chase? One which we cannot win? And thus, does it not make sense to just come out with the superior algorithms instead of going whole hog on the mysteries of the mind? Food for thought.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1369599/pic.jpeg http://posterous.com/users/hcGXxsTkwP6SS Vijay Krishna Palepu vpalepu Vijay Krishna Palepu
Thu, 20 Jan 2011 18:25:09 -0800 The Single most Important thing for a Coder http://vijaykrishna.posterous.com/the-single-most-important-thing-for-a-coder http://vijaykrishna.posterous.com/the-single-most-important-thing-for-a-coder I was having this discussion with a friend of mine today as to what the most important thing for a coder is. Is it good coding ability or good coding standards? Is it about writing basic code which everyone can read or is it about writing brilliant code which no one can fathom, leave alone understand? Is it about knowing one technology/API/framework to a point from where you can rebuild its competitor technology/API/framework, or is it better to have a decent working knowledge of most known technologies around you? I keep having this talk with a lot of my friends and fellow coders. There are many attributes to this ever debated and talked of topic. However, there is this one standard denominator which puts all those talks and debates in unison. Everyone agrees that it is the core concepts of the subject, the very first principles that matter more than anything else. Furthermore, it is ones ideas, creativity and acumen that start mattering beyond a certain point in every coder's life. And no one can escape that simple test of strength. Yes, it is true that one needs to know the technology, and the ways and means to get his ideas and work out there. But, all the is secondary. There are a lot of people in the world who will tell you that. What no one can tell you or teach you is how to be creative. No, there is no recipe for that and maybe thats why it becomes so very important. People can still teach you the 1st principles over and over again, to a point mind you. But there is no one in the world that can tell you the secret of the coming up with the next best idea. That is one place where every coder, woman and man alike, are on their own. With all this talk, I can not help but remember a chapter in 12 standard English. It gave out a simple message:

All the morals and virtues in the world have no or little meaning, over an empty stomach.

Pretty straight forward. We can afford to talk of good coding standards and practices, like morals, only after the good (and working) logic and design has been developed and we are ready to start coding over such a comfort. There will be those who will try and instill good naming conventions and output formats in your code. There will be those who will make you look lousy when you can't write nested for loops without proper indentation. But remember, those people cannot write good effective letters with the same so-called presentation as required. Writing good code and writing good arguments are the same thing with a difference in the medium of language. You miss one, you are likely to miss the other. You find one, you are likely to find the other. So when anyone asks me what is the Single most important thing for a Coder, I will say: sound, rock solid logic. And there is no substitute for that.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/1369599/pic.jpeg http://posterous.com/users/hcGXxsTkwP6SS Vijay Krishna Palepu vpalepu Vijay Krishna Palepu