Monday, August 31, 2015

Guidelines for using control structures(if/else if/Switch )

Important Note : program readability is most important after working software.

If statements :

  • Write nominal path through the code first ;then write the unusual cases last
  • Put the normal case after the if rather than the else
  • Try to consider the else clause 
If else if Statements :

  • Simplify the complicated condition checking with a function call
  • Keep the most common case first
  • Try to use switch/case statement instead of if else statements
Switch/Case statements :
  • Order cases alphabetically or numerically
  • Put the normal case first
  • Put the most frequently executed case first and the least executed cases last
  • Use default case for detecting legitimate defaults or errors

Guidelines for using and naming variable in C#

Important Note : program readability is most important after working software.

Guidelines in using variables :
  • Declare and define variable close to the where it is being used for the first time
  • Use const wherever possible
  • Keep variable scope as short as possible
  • Try not to use global variables
  • Use variable for one purpose only
  • Avoid variable with hidden messages
Guidelines in naming variables :
  • Code is read far more times than it is written. Favor read-time convenience over write-time convenience 
  • You should not give variable name like how you name your dog
  • Goodness/ Badness are determined by variable`s name
  • A good variable should be readable ,memorable and appreciate
  • Avoid the variables names like temp, x, y (who knows what does that mean ??)
  • Try to give names to problem domain
  • Come up with a standard naming conventions in cases like revenveTotal, totalRevenve.. etc.
  • For naming looping indexes, Try to come up with a more descriptive names than I, j, and k
  • Come with a better name than just using flag for naming status variables
  • Give temporary variables more descriptive names
  • Do not use negative variable names like “NotFound”, Use positive names like “Found”
  • Avoid misspelled word in variable name like cnt(count) ,msg(Message)
  • Do not differentiate variable names solely by capitalization

Monday, August 24, 2015

OOPs as Human Beings

In this small post, I am going to compare Object Oriented Programming with human beings


  1. Classes --> Humans
  2. Objects -- > you are instance of humans 
  3. Inheritances --> you got certain features from you parents by birth
  4. Polymorphism --> your behavior sometime depends/changes on person in front of you 
  5. Function Overriding :you have two hands similar to method name is same and signature is different
  6. Overriding : you have overridden some feature from your parents

How to get (freshers)programmer job

In this post, I will try to give concrete steps to get a programmer jobs and I assume you have already decided to pursue a programming job in IT and have fairly a good idea on which technology to look into.
  1. Get Lets C by Yashavant Kanetkar and do all example and excises in the book.This will give solid foundation for programming concepts
  2. Learn OOPs concepts using C++ (I am not sure which book is good for OOPS)
  3. Brush up your aptitude skills by picking a good book on this topic
  4. Now you can concrete on your chosen technology to study or join a training institute for that purpose
  5. you can brush your programming skills by go through Programming Pearls  
  6. Develop a dummy application 
Some advises while looking for jobs

  • It is going to be tough and staying positive is critical to your job searching
  • You require greater communication skills than you what you think you have
  • Get into a daily routine of studying for at-least 5 hours 
  • Avoid TV watching ( This is biggest time waster of all time!!)
  • Limit your internet browsing
  • Attend interviews as many as possible
  • Do not change technology domain too frequently
  • Always be in your friends network who are also looking for a job
  • Send your resume to everyone in the industry and follow up with them in case it is positive
  • Tailor your resume to every job profile i.e. one resume for all jobs it does not work out
  • Create your LinkedIn profile, Facebook and twitter profile 
  • Create a list of companies you want to work
  • From the list above, Add company and its employees to your Facebook and LinkedIn profile and tell them you are looking for a job (It is not shame and mostly does not work, Still you have to do it)
  • Create you Naukri, Monster profile for every preferred cities i.e create different profile for your every preferred cities  
  • Create google alerts for proper keywords
  • It is important to give correct keywords in resume and  Naukri or Monster profiles
  • Do not hesitate to attend interview for small companies /start up 
Learning Plan Specific to .NET Technology 
  • Lean C#
  • Learn JavaScript
  • Follow the learning plan which i have already explained in the link

Monday, August 17, 2015

Some thoughts on using technology

      This is one of  two formula shared on the bloggers.Still I am not sure whether this post is really helpful to you, I continue to hope/think someone somewhere might find them useful.
      As per studies, Overall humans development happens when you are not at work or not doing productive work for example, 1.Having your food  2. Meeting your friends( of course ,not social media ) 3.Spending time with family 4.Rest Rooms(Yes , It is true) ....etc. The time spend on these are very critical to overall development of humans in general . But the reality is whenever we get time like this ,we hook to smartphones , e-Readers/Books,Social Media, Selfies
      Keeping these things in mind, I came with my way of handling these situations    
1. Social Media :My social media visits are scheduled(Once in a week), I do not care how many likes i got for my update.
2.Emails :I check and reply mails on Pre-scheduled  basis( twice in a week day)
3.Smartphone/Gadgets: I use these things on problem-solution /need specific.If a gadgets( like smartphone) helps me to save time, I`ll use it.
4.Internet/News/Google : This has to be pre determined purpose specific, Suppose I  need some information on specific topic.i use Internet to get it and close the browser,I do not involve myself into the web of links(I am trying hard to follow this suggestion )
       In nutshell, The technology should help us in doing the stuffs faster, saves times, We should not become salves to technology. Go out and enjoy your time with family/friends

My personal formula before buying anything,quite literally anything

     I was not sure whether this post is helpful for anyone  but still published this post thinking someone, somewhere might actually find it helpful .I have been using this 'formula' before buying anything since my childhood ,I do not remember from where i learnt this great 'formula'

     Generally, we buy items based on the wrong assumption such as

  • Many of friends/peers are having it and i should also get it ( i call this as "Peer Pressure")
  • Many of items we bought , we do not need it/ use it ( I call this as "Robbery" , Yes it is, at-least according to MG  )
  • Just for false prestige ( One of most dangerous superstitions in the world) 
  •  Feel to get more importance among your friends /peers
  • And It continues 

My personal 4 step formula for buying anything. In fact you need to ask yourself these 4 questions

  1. you need to decide  that you should actually need that item, I mean to say you should ask yourself whether you really need it ?
  2. Is that item going to change your life after you bought it ?
  3. Are you going to feel really great after your bought it ?
  4. Are you going actually to use it  ?
If you have answered at least 2 as "YES", you should go ahead and buy it.From my experience, It takes hardly a minute to decide and have been seeing  my expenses under my control. you must give a try for a month or two and see how it woks. if it does not not work for you ,Dump this formula in the dustbin

**Statutory Warning** : I did not consider your budget, Because I`m confident you all can afford it whatever you want in your life , Come on, you have EMIs to get them

Monday, August 10, 2015

The C# dynamic Keyword in C# 4.0 and upwards

dynamic keyword a specialized form of System.Object, in that any value can be assigned to a  dynamic data type.
• a data point declared with the dynamic keyword can be assigned any initial value at all, and can be reassigned to any new (and possibly unrelated) value during its lifetime.
• IntelliSense is not possible with dynamic data.
• It is not mandatorily to use dynamic keyword  (With Dynamic keyword, The intention is to reduce verbose, that’s it)
• It is not statically typed it means that validity of dynamic statement is checked at runtime not at compile time
• Invalid dynamic statement is validated at run time using RuntimeBinderException  available in Microsoft.CSharp.dll
• Cannot make use of lambda /anonymous methods
• Cannot understand any extension method
• It is used in cases where your .Net application interacts with COM libraries (like Microsoft Office products) or VSTO application
• Can be used as parameters, return value or a member of class/structure


Extract Method Refactoring in C#

When to use this:
  1. Length of the method is not an issue
  2. To improve clarity of the code
  3. The name of the new method will reveal the intention of the code in a better way. If you can't come up with a more meaningful name, don't extract the code
       Example : Suppose we have method to use this extract method. by selecting console.WriteLine statement as below

        public void Add(int x, int y)
        {
            int z = x + y;
            Console.WriteLine(z);

        }

We can also right-click the selected code, point to Refactor, and then click Extract Method (Short cut  is CTRL+R, M)  to display the Extract Method dialog box.

The final extracted method is as follows

Monday, August 3, 2015

Asynchronous in C#

       The async keyword of C# is used to qualify that a method, lambda expression, or anonymous method should be called in an asynchronous manner automatically. For this, the CLR will create a new thread of execution to handle the task at hand. Furthermore, when you are calling an async method, the await keyword will automatically pause the current thread from any further activity until the task is complete, leaving the calling thread free to continue on its merry way.

1.Methods (as well as lambda expressions or anonymous methods) can be marked with the async keyword to enable the method to do work in a non-blocking manner e.g. in the below figure, The method ProcessSleep() is marked with async
2.Methods (as well as lambda expressions or anonymous methods) marked with the
async keyword will run in a blocking manner until the await keyword is encountered. e.g. in the above figure, The method will run in a blocking manner until the await sleepingClass.DoSleep() statement is encountered
3.A single async method can have multiple await contexts. e.g.  the above method can multiple await calls
4.When the await expression is encountered, the calling thread is suspended until the awaited task is complete. In the meantime, control is returned to the caller of the method. e.g. In the above method ProccessSleep(), When await expression is encountered, The calling thread i.e. The main method thread is suspended  until the awaited task is complete.In meantime, Control is returned to the Main method to continue executing its statements
5.The await keyword will hide the returned Task object from view, appearing to directly return the underlying return value. Methods with no return value simply return void.
6.As a naming convention, methods that are to be called asynchronously should be marked with the “Async” suffix..e.g. In case, they are SleepingClass.DoSleep() and ProcessSleep()

Thoughts on LINQ

1.LINQ queries look similar to SQL queries, the syntax is not identical. In fact consider LINQ queries as unique statements, which just “happen to look” similar to SQL.

2.The LINQ API provides a consistent, symmetrical manner in which programmers can obtain and manipulate “data” (it can be DB ,XML ,collection, Generics.. etc.)

4.System.Array does not directly implement the IEnumerable<T> interface, it indirectly gains the required functionality of this type (as well as many other LINQ-centric members) via the static System.Linq.Enumerable class type.

5.Deferred Execution :LINQ query expressions is that they are not actually evaluated until you iterate over the sequence            

5.Immediate Execution :When you need to evaluate a LINQ expression from outside the confines of foreach logic, you are able to call any number of extension methods defined by the Enumerable type as ToArray<T>(),ToDictionary<TSource,TKey>(), and ToList<T>(). These methods will cause a LINQ query to execute at the exact moment you call them, to obtain a snapshot of the data

6.For Non generic collection, it is still possible to iterate over data using the generic Enumerable.OfType<T>() extension method.

7.Forms of LINQ :
var result = from matchingItem in container select matchingItem;

var result = from item in container where BooleanExpression select item;