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, 26 Mar 2011 07:22:47 -0700 Code Formatter for Blogger http://vijaykrishna.posterous.com/code-formatter-for-blogger http://vijaykrishna.posterous.com/code-formatter-for-blogger This was something that my friend was asking me the other day, after he got a pang of envy looking at my code formatting in my wordpress blog (this blog). Ofcourse, there is no inbuilt method for formatting code in blogger. There are roundabout manners by which you can do it, but its too much trouble to ask for. So, instead of explaining all the weird methods in the world, i decided to Google for an online solution and hit upon this: http://alexgorbatchev.com/SyntaxHighlighter/ This uses different syntaxfiles (JS files) to support the syntax of different languages. Here is a list of all the languages that it supports: http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/ Also, the whole thing won't work for Blogger by default. You will have to activate the Blogger Mode by setting the configuration. The clear instructions for which are given here: http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/ Now, there are some sites which do some amazing formatting for a few given languages. Here is one for c# (and other related languages): http://www.manoli.net/csharpformat/ . But the issue comes about when you have to take care of all or more popular languages like Ruby or Scala. So, with that in mind i feel that Syntaxhighlighter is not half as bad a solution. Try it. I found it ok. However, if you do have any better suggestions to make, you are most welcome.

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
Wed, 23 Mar 2011 06:07:38 -0700 My Ruby Notes http://vijaykrishna.posterous.com/my-ruby-notes http://vijaykrishna.posterous.com/my-ruby-notes [This post will be my Ruby Notes which i will keep updating. It is more like a personal Ruby manual.] Numbers: [sourcecode language="ruby"] population = 12_000_000_000 # means the same thing as population = 12000000000 [/sourcecode] Variables: begins with a small letter => normal variable begins with a capital letter => Constant begins with a $ => Global Variable begins with a : (colon) e.g. :a => Symbol begins with an @ => Instance Variable begins with an @@ => Class Variable in between two |'s e.g. |x| => Block arguments

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, 22 Mar 2011 13:20:39 -0700 Retrieving all the Methods in a Service http://vijaykrishna.posterous.com/retrieving-all-the-methods-in-a-service http://vijaykrishna.posterous.com/retrieving-all-the-methods-in-a-service Well, today i was in a real fix. I was asked to work out a manner by which i show all the methods of a service in a combo-box. Now, people told me to ideally have a look at the proxy and type out the method names as they were and then create a static list of strings which i could then bind to the combo-box. WOW!! So simple ain't it?!? "And what if the list of methods were to change", i asked. The reply came, well, you can guess what the reply was. Someone then suggested a method involving WSDL. I do not know what that meant, as the idea was instantly trashed and i was never explained the details. Either way i smelled unnecessary  labor there as well. So i put up a brave face and googled it. I refused to believe that the method list of a given class could not be retrieved. After all that was the crux of my project. So after a little bit of googling and a little asking around from a trusted colleague, i found a way: Type. [sourcecode language="csharp"] public List<string> GetMethodNames(){ Type type = client.GetType(); var methods = type.GetMethods(); List<string> methodNames = new List<string>(); methodNames = methods.select(x=>x.Name).ToList<string>(); return methodNames; } [/sourcecode] So i can actually send in the type of service client (for which the method name list is required) to the GetMethodNames function and get different lists for different services. Thus, allowing me to dynamically get the method lists, which will take care of cases when the service changes the methods in terms of names and numbers. Ofcourse, in case of a Silverlight project, we will have to take care of things like the "Async" prefix. So we just have to remove that. Simple enough. So that is that!! :D

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, 18 Mar 2011 18:26:33 -0700 Understanding the "difference" in Ruby http://vijaykrishna.posterous.com/understanding-the-difference-in-ruby http://vijaykrishna.posterous.com/understanding-the-difference-in-ruby Finally got some time to write a little more about Ruby today. Well, in this wonderful time of learning this language, there has been one thing that i have been finding difficult to digest and embed as a part of my thinking. And while it matches the way i perceive programming languages to be, it is still requiring  a little "getting used to". What i am talking about is, treating everything as a Method or a message that takes input and returns a result. Treating Operators, if-elsif-else statements and the likes, as methods is one thing. Coding them in that manner is completely different, and i am talking specifically about the kind of syntax that can come into play here. Eg: [sourcecode language="ruby"] at_hotel = true email = if at_hotel address = "why" address << "@hotelambrose" address << ".com" end [/sourcecode] the if statement here actually returns a value. And it returns the value of address. This is a little different from what you would normally see. [sourcecode language="ruby"] code_words['catapult'] #is actually the shorthand for code_words.[]( 'catapult' ) [/sourcecode] [sourcecode language="ruby"] approaching_guy == false #is the short hand for approaching_guy.==( true ) [/sourcecode] These are some different and unconventional coding syntaxes i have never come across, before  Ruby. So, it is taking some time, but i am getting there. :)

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, 10 Mar 2011 16:45:13 -0800 Hello Ruby http://vijaykrishna.posterous.com/hello-ruby http://vijaykrishna.posterous.com/hello-ruby This is probably my 1st line  of Ruby Code that i am blogging here. Learning Rubys these days. So here it is - [sourcecode language="ruby"] 10.times{ print "Hello Ruby."} [/sourcecode]   I must thank Partiosh Chhibber, my friend for his help with this post.

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, 22 Feb 2011 17:32:32 -0800 Calling Async Service Calls Iteratively in Silverlight http://vijaykrishna.posterous.com/calling-async-service-calls-iteratively-in-si http://vijaykrishna.posterous.com/calling-async-service-calls-iteratively-in-si Well, i was posed with a rather strange situation today when i had to make Async Svc Calls from a Silverlight UI code. The issue was that i had to call a single service method in an iterative fashion, ideally in a loop. But the problem was that i was doing a lot of processing in the completed event handlers and the order of the processing was making a difference to my UI. Ideally, had it been sync calls, i would have finished it off in a for loop. And then i was introduced to the concept of Enumerators. Here is a pseudo code snippet for the same: private void _getData() { List<string>.Enumerator enumerator = ListSource.GetEnumerator(); //create the Enumerator If(enumerator.MoveNext()) { _getData(enumerator);//send the enumerator to the _getData function } }   private void _getData(List<string>.Enumerator enumerator) { ServiceClient client = ServiceHelper.GetServiceClient(); client.GetDataCompleted += new EventHandler(retrieveDataCallBack); client.GetDataAsync(arg1,enumerator); //send the enumerator in the userstate }   void retrieveDataCallBack(object sender, GetDataCompletedEventArgs e) { //perfrom operation on e.Result; Before that do a check on e.Error If((e.Userstate as List<string>.Enumerator).MoveNext()) { _getData(e.Userstate as List<string>.Enumerator); } }   It was good to learn something fresh after an eon. :)

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, 18 Feb 2011 17:08:26 -0800 Google Maps JS API http://vijaykrishna.posterous.com/google-maps-js-api http://vijaykrishna.posterous.com/google-maps-js-api With my involvement in  the ongoing work on my undergrad college website, i was asked to churn out a simple piece of code for a dynamic Google map for the location of AIT. I already did this using Static Maps some time ago and it was recieved well. But, there was a huge demand for a dynamic map and after a quick 30 min revision of the JS API i managed this fragment of rather simple code: [sourcecode language="javascript"] <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0px; padding: 0px } #map_canvas { height: 100% } </style> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script> <script type="text/javascript"> function initialize() { var latlng = new google.maps.LatLng(18.60700,73.87507); var myOptions = { zoom: 14, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; //marker var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions); var marker = new google.maps.Marker({ position: latlng, title:"Army Institute of Technology, Pune, IN"}); marker.setMap(map); //info window var contentString = '<div id="content">'+ '<div id="siteNotice">'+ '</div>'+ '<h1 id="firstHeading" class="firstHeading">Army Institute of Technology</h1>'+ '<div id="bodyContent">'+ '<p style="width:100%"><img src="http://aitpune.com/picture/aitlogo2.gif" style="float:right" hieght="100" width="100" alt="Onward to Glory"/> Dighi Hills,Alandi Road<br /> ' + 'Pune, INDIA-411015<br /><br />Phone: (020)27157534,27157612<br />Fax: 91-20-27157534<br />E-Mail: ait@aitpune.com</p>'+ '</div>'+'</div>'; var infowindow = new google.maps.InfoWindow({content: contentString}); google.maps.event.addListener(marker, 'click', function() {infowindow.open(map,marker);}); } </script> </head> <body onload="initialize()"> <div id="map_canvas" style="width:100%; height:100%"></div> </body> </html> [/sourcecode] Simple enough really. Nothing to it. Go have a look at the Google Maps JS API 3 tutorial (Google it...) and you should be able to figure it out without any issues. As usual Google's documentation is brilliant.

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, 17 Feb 2011 17:37:25 -0800 Code Integration http://vijaykrishna.posterous.com/code-integration http://vijaykrishna.posterous.com/code-integration It has been a week of thorough introspection and rough hours at work. With ever changing requirements and demands of the software world and its clients, i guess any developer goes through this phase early in his career. The phase where he not only has to produce good code but also keep changing it as per those requirements, and fast!! And all the while, you have to produce bug free code. So what is the secret? How do you keep writing good error free code, with the fast paced changes? Well, let me break the bad news to you: No one can write bug free code in its entirety with significant changes in the software model/requirements being made every other day. But here is the good news: You can reduce the number of bugs by being careful about the changes that you incorporate in your software/code. And this whole process of being careful is called Integration testing. For those of you who treated STQA (Software Testing and Quality Assurance) with little or no respect during your engineering/undergrad days, bear this in mind: You will regret it, for that is the final barometer of a good coder. So, if you did not pay enough attention to that aspect of development, you still have the time. And yes, it is an integral part of code development itself. While many may feel that it is the job of the testers to actually test out code, i fundamentally disagree. Until and unless every form of testing, which the testers do at a more sophisticated level, starts at the developers' desks at a very basic and rudimentary level, you can never produce good software. Never! Don't testers have to learn programming languages, in the basics, to start testing the code? Then why can't developers get some basic levels of testing done at their own end? And it really does not have to be a very daunting task. Here are two very basic guidelines anyone can use to get that basic testing done right from the very beginning: Assuming you are a decent coder, most of the mistakes you will make is while integrating features or different code modules with your software. Take care when you do this. Remember integration of code is not a mathematical addition of the number of lines of code in both modules. Rather, it is the multiplication, or the product of the number ways the data streams going in and out of both these modules will start to interact with each other. How these data paths join together gives rise to new scenarios, which you would not have considered before. Try finding those scenarios. There is always something new. And that is where most bugs reside. It is easy to work in a localized context and develop small modules of code. The idea should always be to think of how, what you code will, effect the over all scheme of things. The other equally important way to counter unforeseen issues in such integrations is to write decoupled code as far as possible. Thus, in its pure essence, a lot of trouble can be averted, if one were to write independently functional code, to begin with. There should be a middle ground (fragments of transformers) where the mappings or collaborations between these sets of independent modules of code should be performed. This also localizes the errors as well. If the modules by themselves are working well, (and this can be unit stress tested), then all you really need to look at as a developer/tester is how the transformer code is really doing. Thinking of your code structure in this way will also give you some ideas about how software should be designed. These are two very radical approaches, one which relies on the fundamentals of testing, while the other relies on the foundations of designing principles. While most coders i find crib about not being able to be a part of the designing process, i wonder how many of them design their own small modules of code, in the best manner possible. Coding is least about writing lines of text in a particular computer language which generates fancy outputs. It is about writing good logic, in a readable manner, which can be well managed thus resulting in easy verifications. I think that every piece of code deserves all of these elements to their core. No Exceptions!!

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, 03 Feb 2011 18:16:07 -0800 A Coder's Handwriting http://vijaykrishna.posterous.com/a-coders-handwriting http://vijaykrishna.posterous.com/a-coders-handwriting This is a phrase coined by i-don't-know-who. But this is a phrase used my a colleague of mine at office. When ever there is any issue in the code on the TFS, instead of doing a history check and the past check-ins, this guys identifies the author of that code based on its "handwriting". Interestingly enough more often than not, he is correct. And surprisingly enough, when you think about it for a minute, there seems to be some sense in his method. Any coder, no mater how much he has coded, or whom he codes with, has a basic style of coding. It may change over time. That is because a lot of factors effect how one writes code. The kind of software one uses to write code. The sort of framework/technology/language someone is working with or how much they know about it, the kind of practices one uses while coding, which involve, comments, regions, proper grouping of a particular kind of data variables and methods and the names used for those. Its a sum total of everything. And that is what i think my colleague means. Now every one has their own hand in coding and it keeps changing from time to time, more in the early days of work. But, as you go on, it stabilizes. Or so i guess. You can teach a coder how to use comments, and how to put everything in regions and how to make sure that he uses the same naming conventions everywhere. But there are so many things out there, (hell...even the kinds and number of commenting styles can overwhelm you at times) that it is only human for a coder to pick up a subset of all those standards and notations. Mind you, not all those standards are the best for any and every kind of scenario. But, those such as using comments to write the steps in your code, or place the methods in the probable sequence in which they will be called, or using access modifiers whether required or not, really help in the process of coding well. Many will beg to differ with me at this point, and i do not blame them. For i, myself believe that logic is the most important thing for a coder and everything else comes later. But, having such habits is not a bad thing really. Having comments is good for your own logic building. You really do not have to keep looking at the code and deciphering it, in order to understand what you have done. If you were to write the steps of your logic in comments, then the next time you open your code, you can just pick up from where you left, without dwelling into the code too much. This way you are not wasting time in revising on old stuff but actually moving on to new logic or logic enhancements. And it also makes it easier for someone who has to give you ideas/suggestions/reviews for your code. He can then actually understand what you have written. What is the point of writing good logic with poorly understandable code? Its like writing a new idea on paper with a doctor's handwriting. No one will understand your idea. Not because it was a complex idea, but because your handwriting sucked and your words were difficult to read. Writing neat code also conveys a clarity of thought. I think the reverse psychology also works here. What i mean is that a good coder with a clear mind will in all probability write clean code with proper naming conventions. Similarly, if you were to force yourself to use clear naming conventions you actually begin to have a clear understanding your own code. And that is the first step to good coding with sound logic development. Still not convinced? Look at it this way: You write code for your understanding, not the computer's. The computer will always convert your code to its own language which happens to be the binary, something you cannot not understand anyway. So whom are you writing that code for in a high level language, if not for yourself and your understanding?

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, 01 Feb 2011 18:24:13 -0800 Vertical Scrollbar Visibility http://vijaykrishna.posterous.com/vertical-scrollbar-visibility http://vijaykrishna.posterous.com/vertical-scrollbar-visibility So, this is something very basic i learned today. The scrollbar in silverlight appears only when the length of the container is predefined and not depended on its parent container. For example, if you set the grid row height in which you have placed you textbox to "AUTO", you will never be able to see/activate the scrollbar. Simply because the textbox assumes that you have set the parent grid in a manner that will keep the size in check. Instead of activating the Scrollbar in the container, in this case the text box, it will simply stretch the textbox beyond the parent container boundary. Another instance of this is when you set the Gird.RowSpan or Grid.ColumnSpan for the textbox. Again in can never decide when to activate it, as its height is dependent on its parent grid. And the grid itself will keep expanding as the textbox expands as it keeps getting filled with more and more data. This can be avoided if you set the Grid height to "*", in which case it should be able to activate the scroll, because for some reason, with "*" it can pre-compute the size somehow. Having said that, the star(*) will fail to work in case of the Row and Column Spans. Simply because the issue is not with the height, but with the extent of the textbox which is ultimately decided by the parent grid. The best solution is to try and maintain fixed size textboxes for activating the Scrolls. It only makes sense, right? Otherwise why would you need a scroll, if you do not find it important enough to fix a length?

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
Mon, 31 Jan 2011 18:16:05 -0800 NameValueCollection and Proxies http://vijaykrishna.posterous.com/namevaluecollection-and-proxies http://vijaykrishna.posterous.com/namevaluecollection-and-proxies Today i learnt yet another painful lesson at work. When you generate a service proxy using SvcUtil, the NameValueCollection data type does not get parsed. In my case it parsed it into a ArrayOfXElement object type by creating  a System.Collections.Specialized namespace within the proxy. I Googled around, then asked around, thinking that i missed some basic object type in c# (read ArrayOfXElement). But that was thankfully not the case. I found a lot of workaround for the given issue. Many involved writing a simple parser (as a wrapper, don't get worried). But a simpler and wiser approach was not to use a NameValueCollection in the first place. Use a Dictionary instead. The same issue comes up in the event of a ArrayList it seems. Use a List object for that. After a little bit of googling i found that the NameValueCollection and the Arraylist are Week Types. According to this discussion thread: http://stackoverflow.com/questions/939118/wcf-serialization-problem-using-namevaluecollection Week types and Weekly typed are two different things. How and why are questions which i am still trying to resolve. But the big and small is this: Do not use NameValueCollections, its an unnecessary headache.

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
Sun, 30 Jan 2011 16:59:35 -0800 Requirements http://vijaykrishna.posterous.com/requirements http://vijaykrishna.posterous.com/requirements Every project is a result of a set of requirements. The success and the failure that project depends upon the extent to which those requirements are satisfied with the project. This is not another piece of literature that will tell you the importance of understanding a client's or consumer's requirements because it is important for the consumer. I am a coder, and i will like to, for a change, try and point out the issues a coder has if the requirements are not clearly defined. To be more explicit, i really do not care about how poor requirement analysis usually effects the consumer, i am more concerned about how it effects the coder, who is expected to transform those requirements to a finished product and machine. My point being, if the coder himself is unclear about the specs., then we have bigger concerns, bigger than the client. Live the consumer's World. - When a requirement analysis is being carried out, there should always be a certain degree of clarity between the one who is conveying the requirements, and the one trying to understand them. In an ideal world, the one who is trying to the understanding should also be able to convey those in their precise element, and also be a part of the coding fraternity. Also, there can never be a situation, when you are apprehensive about asking questions about a particular aspect about the requirements. It is always good to try and understand the purpose of what the client is trying to achieve with the final product. There is no point making assumptions based on what the client has told you. Remember, the client lives in that world, where the requirements exist, you do not. Live that world. Only then will you be able to truly see the intricacies of the problems you will face while actually developing the product, even before you get into the whole whirlpool of development. Avoid the Negative Trickle. - Information, like rations in India, suffers from the trickle down effect. When it starts from the source, it is rich and abundant. But, by the time it comes down to the individual who has to make sense out of it, and use it, there is hardly any left. The reason this is normal  is due to one simple thing: a lack of form in the information that is being generated at the source. Because, it is very abstract, and largely based on the consumer's experiences and not on a well thought off scheme of things, the information needs to be organized. And there is the loss of information begins. In the process of organization, we loose of several key elements, which might not seem important at the inception, but becomes important, as the project grows. We negate those elements, in the early phase of our project and thus, loose them for ever. Many come back to haunt us, many revive quietly. The idea should be to preserve everything. Do not loose any thing, even if it may seem to mean nothing to the project. See reason, not instructions. - In any team, there will always be someone telling someone else what to do. And since not everyone in a development team can meet the client, the "telling" will be more while trying to convey the requirements and hence the goals. In this whole process, one tends to take everything as an order or a blatant instruction, to be performed blindly. This is specifically true to coders. Don't do that. Listen to what your mentor has to say. Try and see the reason in the goals and requirements. What might seem right to you may not be so for the consumer. Adjust your thought accordingly. And until you are clear and confident of the fact that your understanding of the requirements are same as that of the client, don't stop asking questions. But the bigger thing is to always find the right reason behind your goals. Don't develop something blindly. Try looking at the Big Picture. The moment you start taking a holistic view to things, you understand the context of your work, which allows natural synchronization with the team that you are working with. When these things are not followed things get tough for a coder. He has no context for his work. His code is a result of an instruction from his superiors. And more often than not, he has little or no understanding of the requirements and ends up coming out with good code for the wrong place.

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, 29 Jan 2011 16:48:35 -0800 Good Tutorial to Javascript http://vijaykrishna.posterous.com/good-tutorial-to-javascript http://vijaykrishna.posterous.com/good-tutorial-to-javascript I was brushing up my concepts in JS today when i bumped into this amazing refresher of its programming elements: http://javascript.infogami.com/Javascript_in_Ten_Minutes Well, i do hope this will be useful. Cheers

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, 27 Jan 2011 18:25:21 -0800 Browser Actions - Chrome Extensions http://vijaykrishna.posterous.com/browser-actions-chrome-extensions http://vijaykrishna.posterous.com/browser-actions-chrome-extensions Today i got some time from work to at a good look at the chrome extensions and its development. I have been doing a lot of reading in order to understand what the whole buzz is about. Another reason as to why i have been procrastinating the development of my 1st Extension is due to a lack of good idea(s). So i have to get my creative juices flowing. May i will over this weekend. But, all that reading has done me some good and i wanted to share as to how simple it is to build these extensions. So this post is about a specific UI concept in Chrome Extensions and it is known as a Browser Action. Well, lets try and understand what the browser action really is. If you are using chrome you should see a small wrench in the top right corner of your Chrome browser right beneath the Close+Maxi/Mini-mize buttons. That in essence is highly advanced and evolved form of a browser action, atleast the way i look at it. A Browser Action is something that is a global action for the browser it self and not for a specific kind/set of websites. It is an add-on to the Browser and should in principle be independent functionally, from the website which is loaded in the browser. It can be a Action to view your mail, make a quick blog post, get a menu for all your tabs that are currently operating in the instance of your browser, a add-on u can use to shoot posts to your facebook or to tweet. Stuff like that is independent of the content/context of your website that is currently loaded in the browser. There are somethings called Page Actions which can be used for Page/Website Content Specific actions, examples of which i have given in my previous post on the Chrome Webstore. So now that you have a good idea of what browser actions should be, let us have a really quick and painless view of how simple it is to create such actions. A Browser Action can have the following 4 basic elements:
  1. Icon
  2. Tooltip
  3. Badge
  4. Popup
  • An Icon is what appears next to the wrench. It can be a static image in the JPG, JPEG, GIF, ICO, PNG and BMP. It can also be a dynamic icon using the Canvas element of the HTML5 standard.
  • The Tooltip is essentially, the title of the Extension, and appears in the tooltip. It is optional to give this in the manifest, as explained below.
  • The Badge is a small fragment of text of not more than 4 characters, overlaid on the icon. It can be used to give out additional information to the user. Such as the count of unread mail for a Mail Extension. The text of the badge itself should be very concise.
  • The Popup is an optional pane containing HTML markup which can be your creation and will open up when you click on the icon of the extension.
Quick Start: The following is what the manifest of your extension should look like.
{

"name": "Test Browser Action",

"version": "0.1",

"broswer": {

"default_icon": "images/testIcon.jpg" //required

"default_title": "Test Action" //optional; tooltip text

"default_popup": "popup.html" //optional

},

}

 
What you really need to do is to put this in a file called manifest.json, along with the popup.html and the testIcon.jpg in a folder. That is it that is you extension ready to be loaded. Then you need to go to Tools(the wrench sign)>Extension, then click on the + sign next to the Text which reads Developer mode, if it is not already a -. Then you should be clicking a button called "Load Unpacked Extension..." and select the folder where your extension from tree view that pops up and your extension is good to go. You should be seeing your extension icon next to the wrench and clicking it will open up a pop -up which will contain what ever mark up you place in your popup.html file. Remember all these files i.e. the manifest, popup.html and icon.jpg should be in the same folder, which you select to load into your browser. Simple enough won't you agree? While this was a real ABC of Bowser Actions, you can dig up more information, you are interested, at http://code.google.com/chrome/extensions/devguide.html. It is the official Google documentation for Chrome Extensions Developers. So happy coding!

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
Tue, 18 Jan 2011 17:43:19 -0800 A Pop-Up Story http://vijaykrishna.posterous.com/a-pop-up-story http://vijaykrishna.posterous.com/a-pop-up-story This is a tale of what i did at work today. It was lousy in a few ways but educating in many others (its all about perspective). Well, i was doing a lot of code refactoring today and it was truly, and no jokes here, truly a good leaning experience. The theme of today's lesson was simple, Encapsulation. In more elaborate terms, i learnt that service calls should not be made from pop ups. Why? Well, no one has given me any clear reason so far. But somehow it makes sense. A pop up is something very intermediate, right? Its primarily used for peripheral functions. All the actions of uploading data, giving out warning and status messages figures in pop ups. So why should you be making service calls from it? Apart from that, there is another reason why you should not be doing something like that: a pop up is essentially a control as well. Any control you ever make has to be under all circumstances independent of anything else. If there is anything that needs to be passed on or from the control, define and use public properties or information hooks off the control or in this case a pop up. This allows you to create controls which can be used in more than one place. A lot of UI developers ask what that perfect design is, and i answer in terms of re-usability of that control or UI element. Today i learnt the nuances behind making reusable controls. And there is no great hard work or intelligence involved what so ever. It is just a matter of being deliberate and particular about a few simple rules:
  • i will not use any UI element of a control directly.
  • i will not pass or extract any information from any UI element inside that UI control directly.
  • if i have to set or get information or make configuration changes, i will do so via publicly defined properties which i will use as my birth right. ;)
  • and i will set all my UI elements as private so that i never get to use them even if my evil mind tries to do otherwise. ;)
Any control is like a class, exposing a few functions and methods. It should only give just about enough access for the controller or user of the control to make it do what it is supposed to. How it does it and how it manages its own configuration should be its own headache. That is how good independent code with the least amount of dependencies can be written. There is nothing more destructive to a coder than to write code which is dependent with its environment. Any and all code and solutions should and have to be as generic and independent as possible. That is how you are able to replace chunks of code easily in case something goes wrong. It also gives you the independence to separate the code out and, develop and test it independently. I learnt it the hard way. I hope you pick it sooner. Cheers!

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
Mon, 17 Jan 2011 18:03:23 -0800 Defensive Coding http://vijaykrishna.posterous.com/defensive-coding http://vijaykrishna.posterous.com/defensive-coding I will keep this short and simple. Today a senior of mine uttered this phrase, when i was talking ab0ut spanning out null checks all over the code. He said that it will be defensive coding and i soon realized why. The moment you have null check for everything in your code it becomes a little difficult to track down the root of the issue. While your code will be all running and may never break down, there will be issues which will look so mysterious to you that you will end up wasting an entire day just trying to debug one of them. So, while i am a proponent of exceptional handling, may i remind of the golden line: "everything in moderation". Let me give an example of how Defensive coding can be counter productive. I was debugging my code today when i started encountering object refs in my mapper functions i wrote to map the service objects to the UI objects. Now, at first glance i cursed myself for not doing the correct exceptional handling at this level. But, then i went about finding the source of the object ref. As it turned out that even after narrowing the possible issue to one function, i realized that i was using that mapper at 3 different places with in that function!! Thus, i had to debug at each place and figure it out. It was not a one glance thing. And it became so difficult simply because i had done a lot of exceptional handling in all these cases and then the odd case of corrupted was plauging me which was showing its true colors due to a missing fragment of a if-condition (4 conditions were already being tested for, and an extra 5th was now necessary). Its easy to say that the code should have handled it. But, why in God's name was such data being provided in the 1st place. Cross checks are good. But, they should not be overdone. With every stage the flows through there should lesser number of null checks required. Checking for null values or doing exceptional handling for a particular scenario or case, at the DB layer, service level and UI is plain waste of time and a level of redundancy you must avoid. Not, more than twice. It is a huge task to keep a thorough track of this, but i think that this is just another and better coding practice. Don't you?

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, 15 Jan 2011 18:21:30 -0800 Haiku http://vijaykrishna.posterous.com/haiku http://vijaykrishna.posterous.com/haiku No, this is not the operating system. Sorry to disappoint. This is actually an interesting question i came across a few days back. The problem is actually quite simple: code generate as many Haikus as the user wants. Now, why this got me interested is because i used to write a couple of Haikus myself. And i was decent at it as well (it was enough to get a couple of them published in my college magazine). So i sat about thinking what the possible methods of generating Japanese 3 line poetry with a 5-7-5 syllable rule via code be possible. Here is one idea that bounced my mind today and i would like to share it. Haiku, for those who do not know is as I mentioned earlier, Japanese 3 line poetry with a simple rule: the 1st and the 3rd lines are to have exactly 5 syllables (like that in English), and the 2nd line is to have 7 syllables. Simple!! But not so simple to implement it, or so i thought. I went around trying to break the problem down and realized that is was all about realizing, or making the code realize what a syllable is in a given word. Once you do that there is very little left to it. (Or so i think.) So to tackle that little issue i went about finding out the definition of what a syllable is. And here is what i found:
a combination or set of one or more units of sound in a language that must consist of a sonorous element (a sonant or vowel) and may or may not contain less sonorous elements (consonants or semivowels) flanking it on either or both sides: for example ``paper'' has two syllables. -http://www.thefreedictionary.com/syllables "Some consonants can be pronounced alone (mmm, zzz), and may or may not be regarded as syllables, but they normally accompany vowels, which tend to occupy the central position in a syllable (the syllabic position), as in pap, pep, pip, pop, pup. Consonants occupy the margins of the syllable, as with p in the examples just given. A vowel in the syllable margin is often referred to as a glide, as in ebb and baySyllabic consonants occur in the second syllables of words like middle or midden, replacing a sequence of schwa plus consonant . . .." - (Gerald Knowles and Tom McArthur, The Oxford Companion to the English Language, edited by Tom McArthur. Oxford Univ. Press, 1992). Reference http://grammar.about.com/od/rs/g/syllableterm.htm
So come to think of it, even this is not all that crazy as i thought it would be. If one can find enough rules to satisfy the basic criteria of finding the Number of Syllables i think the goal is achieved. Because the idea is not to break up the words into syllables. The idea is to count the number of syllables so that it meets the 5-7-5 criteria of the poem. What i mean is this: in the word combine there are two syllables. Now how does it matter if the two of them are com & bine and comb & ine. The final result is two in either case. So, now that this seems tangible, just pick up a set of words, work around a few combinations in code meet the 5-7-5 criteria and viola!!! You have a haiku. Who says that it has to make sense? ;) But there is a simple work around for that as well. Atleast the idea in my head can get more understandable haikus than the ones you would otherwise get with raw code driven combinations. The idea is to take a known, grammatically or even poetically correct source of text. Mix up the sentences if you like. If you are worried about plagiarism use the content of your blog or something. Just any trusted source of text which meet the above two criteria. Now, work up an algorithm to pick up fragments of sentences from this source which meets the 5-7-5 criteria. And, if your code is decent, you will get more than one human understandable haiku in one go. So there you have it. Go along now, make those words rhyme. ;) And when you do, give me a call, because i am too tired to try it out now. May be another day. Till then, good night.

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