Tuesday, December 8, 2015

Re-looking at Design Patterns

     A design pattern identifies a common software development problem and provides a strategy
for dealing with it. It is just like a cooking recipe, Following a cooking recipe thoroughly does not serve food , you have to decide on quantities, number of people to serve and many other factors. Similarly, a design pattern does not provide ready made solution, you need to customize according to your own project specific requirements
     Design patterns are insurance policies for software development. Insurance policies work by trading a little cost now to avoid the possibility of a lot of cost later. The premium you pay to insure a car against theft, for example, costs a few percent of the value of the car, but when the car is stolen,  your overall costs are minimized. You still have to go through the inconvenience of having your car stolen, but at least you don’t have to bear the financial loss as well.
      In software development, design patterns are insurance against the time taken to solve problems. The premium is the time it takes to add extra flexibility to your code now, and the payout is avoiding a painful and protracted rewrite to change the way the application works later. Like real insurance policies, you may not benefit from paying the premium because the problem you anticipate might never happen, but software development rarely goes smoothly and problems often arise, so that additional flexibility is usually a good investment.

Courtesy :Adam Freeman (Pro Design Patterns in Swift) 

Monday, November 30, 2015

Few great points from the book "the principles of object oriented javascript by nicholas c zakas"

 I have summary of few great points from the book "the principles of object oriented javascript by nicholas c zakas" as below.
  • Primitive values are stored directly on the variable object, while reference values are placed as a pointer in the variable object, which serves as a reference to a location in memory where the object is stored
  • JavaScript is a garbage-collected language, so you don’t really need to worry about memory allocations when you use reference types. However, it’s best to dereference objects that you no longer need so that the garbage collector can free up that memory. The best way to do this is to set the object variable to null.
  • To identify reference types more easily, you can use JavaScript’s instance of operator
  • The arguments object is not an instance of Array and therefore doesn’t have the same methods as an array; Array.isArray(arguments) always returns false.
  • The number of arguments a function expects is stored on the function’s length property. Remember, a function is actually just an object, so it can have properties
  • In practice, checking the named parameter against undefined is more common than relying on arguments.length 
  • Because all instances of a particular type reference a shared prototype, you can augment all of those objects together at any time. Remember, the [[Prototype]] property just contains a pointer to the prototype, and any changes to the prototype are immediately available on any instance referencing it. That means you can literally add new members to a prototype at any point and have those changes reflected on existing instances 
Nichalas has great ability to explain complex concepts in simple ways and this book is easily rated one of great books on JavaScript along with The Good Parts 

Monday, November 9, 2015

Good parts of the book "JavaScript: The Good Parts"

Below is a summary of this excellent book "JavaScript: The Good Parts" by Douglas Crockford .
  • Logical Condition : the falsy values are false ,null ,undefined ,empty string , the number 0 and number NaN and other values true,the string 'false' and all objects are all truthy
  • Use the operator || can be used to fill in default values
  • One way to minimize the use of global variables is to create a single global variablefor your application: var MYAPP = {};
  • The functions are objects, they can be used like any other value. Functions can be stored in variables, objects, and arrays. Functions can be passed as arguments to functions, and functions can be returned from functions. Also, since functions are objects, functions can have methods.
  • There is no type checking on the argument values: any type of value can be passed to any parameter
  • A function always returns a value. If the return value is not specified, then undefined is returned. If the function was invoked with the new prefix and the return value is not an object,then this (the new object) is returned instead.
  • JavaScript does have function scope. That means that the parameters and variables defined in a function are not visible outside of the function, and that a variable defined anywhere within a function is visible everywhere within the function.
  • In many modern languages, it is recommended that variables be declared as late as possible, at the first point of use. That turns out to be bad advice for JavaScript because it lacks block scope. So instead, it is best to declare all of the variables used in a function at the top of the function body.
  • Functions as first class objects :Functions in Simplified JavaScript are lambdas with lexical scoping 
  • Dynamic objects with prototypal inheritance :Objects are class-free. We can add a new member to any object by ordinary assignment. An object can inherit members from another object.
  • Object literals and array literals This is a very convenient notation for creating new objects and arrays.
  • It is adviced to never use the evil twins. Instead, always use === and !==. All of the comparisons just shown produce false with the === operator.
  • The with statement should be avoided
  • Don’t use new Boolean or new Number or new String. Also avoid new Object and new Array. Use {} and [] instead.
  • Its better not to use new at all
  • Avoid Void 

Monday, November 2, 2015

How to use Pomodoro Technique at work/home

According to wiki,the following are  the steps to use pomodoro technique
  1. Decide on the task to be done
  2. Set the pomodoro timer to n minutes (traditionally 25)
  3. Work on the task until the timer rings; record with an x
  4. Take a short break (3–5 minutes)
  5. After four pomodoros, take a longer break (15–30 minutes)
Note :
       Before Starting pomodors for a day
  1. Estimate number of pomodors a task takes to finish
  2. Estimate number of tasks that can be finished in a day
  3. Estimate number of pomodors that is possible in a day
       During pomodoros
  1. Make note of internal( from you) and external (from others) interruptions in a notepad
  2. Attend/ Resolve these interruption after your pomodoro in the day 
  3. go out of your place during break 

Monday, October 19, 2015

How patterns/principles relates to AngularJS

     When i was unlearning and relearning AngularJS  few days back, Some already known patterns/ principles were all reflecting in my mind ( This is a kind of things that happens when you learn a technology.) Below is a list of those things in AngularJS

AngularJS Features
Patterns/principles related
Directives
Separation of Concerns
Declaring  dependencies at module creations/ member creation of module
Dependency injection
Services( service ,factory ,provider ,filter ) in AngularJS
single responsibility principle
Angular Objects like $window, $document, $http, $resource
Object Adapter Pattern
Promises object
Event/publisher patterns

Monday, October 5, 2015

Non Technical Books for Programmers

        "In technical lines as engineering, about 15 percent of one's financial success is due to one’s technical knowledge and about 85 percent is due to skill in human engineering-to personality and the ability to lead people." -Dale Carnegie
          I agree completely with Dale about above statements (Although, 15 % of technical knowledge is critical) Hence, I am providing a list of not technical books for programmers.
  1. How to Win Friends and Influence People
  2. Soft Skills: The Software Developer's Life Manual
  3. The 7 Habits of Highly Effective People
  4. The Passionate Programmer: Creating a Remarkable Career in Software Development
Note : For a complete list of technical and non-technical books for programmers, you can visit my goodreads books shelf here 

Sunday, September 27, 2015

Some Thoughts on code tunings


  • Performance is loosely related to code speed
  • Efficient code is not necessarily "better" code
  • Reducing the lines of code is not necessarily related to performance
  • Sometimes, performance depends on environment
  • Sometimes, a hardware upgrade is a way to increase performance
  • Avoid pre-optimization of code
  • Readable,clean code and a correct program is more important than faster programs
Steps to improve performance of a program
1. Develop the software using well-designed code that’s easy to understand and modify.
2. If performance is poor,
        a. Save a working version of the code so that you can get back to the “last known good state.”
        b. Measure the system to find hot spots.
        c. Determine whether the weak performance comes from inadequate design, data types, or          algorithms and whether code tuning is appropriate. If code tuning isn’t appropriate, go back to
 step 1.
        d. Tune the bottleneck identified in step (c).
        e. Measure each improvement one at a time.
        f. If an improvement doesn’t improve the code, revert to the code saved in step (a). (Typically, more than half the attempted tunings will produce only a negligible improvement in performance or degrade performance.)
 3. Repeat from step 2.

Courtesy : steve 

Monday, September 14, 2015

Learning Ways for Programmers

The way how you learn a topic/subject//anything in IT is largely impacted by internet, I`ll list out a new ways of learning for programmers in specific as below


  1. Books (Joy of reading books can not be replaced)
  2. Blogs
  3. PDFs
  4. Audio books
  5. Online courses(Microsoft Virtual Academy , EDX. ... etc)
  6. Smart phone(not recommended ways )
  7. E Readers such kindle, kobo
  8.  Of course, doing real practices of programs 

Monday, September 7, 2015

Testing Terminologies For Programmers

          Unit testing is the execution of a complete class, routine, or small program that has been written by a single programmer or team of programmers, which is tested in isolation from the more complete system.
          Component testing is the execution of a class, package, small program, or other program element that involves the work of multiple programmers or programming teams, which is tested in isolation from the more complete system.
          Integration testing is the combined execution of two or more classes, packages,components, subsystems that have been created by multiple programmers programming teams. This kind of testing typically starts as soon as there are two classes to test and continues until the entire system is complete.
          Regression testing is the repetition of previously executed test cases for the purpose of finding defects in software that previously passed the same set of tests.
          System testing is the execution of the software in its final configuration,including integration with other software and hardware systems. It tests for  security, performance, resource loss, timing problems, and other issues that can not be tested at lower levels of integration

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;

Monday, July 27, 2015

Delagtes and Events concept in OOPs

You will get many example on how to use delegates and events.In this post,I`ll try to explain about delegates  and event concept in C#                                                                                                     
    In the above example The client code(any application) consumes service code(it can be any code/application which provide some kind of processing/service to the client) by object construction or any other means.
   The client code can call methods from the service code based on the domain context but how does service code can call methods from the client code .Essentially,They are Callback requirements.In C#, We have "Delegate" and "event"  concept to implement this kinds of callbacks
  With Delegate, The client code will get full flexibility of invoking itself and Event provide  a limited flexibility to the client code.

Key Points:

  1. This client code is called subscriber to this service code
  2. There can be many subscribers
  3. The methods(in client code)  which are to be called from service code are called Callbacks/Event Handler
  4. It is common practice to use private delegate or instead use Events
  5. There can  be many callbacks withing same client code or different client code
  6. In C# , delegates are all type safe , It means that, All subscriber should provide callbacks which has same signatures with that of delegate defined on the service side

Workaround for the syntax error in C#:ref and out are not valid in this context

Recently I was  trying  to implement the interface Microsoft.Office.Interop.Word.Styles.
public Style this[ref object Index]
        {
          
        }

Visual Studio through  this error ":ref and out are not valid in this context"

Workaround :
//public Style this[ref object Index] // error CS0631: ref and out are not valid in this context
public Style get_Item(ref object Index)
{
    . . .
}

Monday, July 20, 2015

Great thoughts from Great Programmers

Kent Beck`s Two Hats : there are two hats namely refactoring hat and adding new function hat when you wear the adding new function hat, don`t change existing code and think of refactoring. you are just adding new capabilities. You can measure your progress by adding tests and getting the tests to work
    When you wear refactor hat, you make a point of not adding function; you only restructure the code. You don't add any tests (unless you find a case you missed earlier), you only change tests when you absolutely need to in order to cope with a change in an interface.
   As you develop software, you probably find yourself swapping hats frequently. You start by trying to add a new function, and you realize this would be much easier if the code were structured differently. So you swap hats and refactor for a while. Once the code is better structured, you swap hats and add the new function. Once you get the new function working, you realize you coded it in a way that's awkward to understand, so you swap hats again and refactor. All this might take only ten minutes, but during this time you should always be aware of which hat you're wearing.
Bottom line is that don`t wear the these two hats at the same time

Martin Fowler :Any fool can write code that a computer can understand. Good programmers write
code that humans can understand. :Programming is in many ways a conversation with a computer. You write code that tells the computer what to do, and it responds by doing exactly what you tell it. In time you close the gap between what you want it to do and what you tell it to do. Programming in this mode is all about saying exactly what you want. But there is another user of your source code. Someone will try to read your code in a few months'time to make some changes. We easily forget that extra user of the code, yet that user is actually the most important. Who cares if the computer takes a few more cycles to compile something? It does matter if it takes a programmer a week to make a change that would have taken only an hour if she had understood your code.

Refactoring a software application

Refactoring : a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.

The rhythm of refactoring: test, small change, test,small change, test, small change ...

Why you need to refactor :
  1. Improves the Design of Software :Any software decays over a period of time as requirements changes ,Refactoring helps in  preventing the software decay  
  2. Makes Software Easier to Understand:
  3. Helps You Find Bugs
  4. Helps You Program Faster
When you need to Refactor?:
  1. Before adding new function/capability/feature
  2. Before fixing a bug
  3. While reviewing code
  4. To understand legacy application
When you need not refactor ?:
  1. The application is not working
  2. The application is full of bugs
  3. The code base is not stabilized 

Monday, July 13, 2015

Technology Stack for modern web development

                When we start for developing a web application, We tend to follow the latest/current trend in technology world without understanding the requirements or context. I suggest not to follow the trend but to follow the project specific requirements( There is no silver bullet for all projects )

                In this blog, I`m going to lay out a technology stack for Single Page Application.
Technology
Description
ASP.NET MVC 5
 A server MVC platform which provides us modules, handler ,state management ,authentication/authorization  and boot strapping of initial requirements
Web API(as REST services)
Services for processing data from /to client application and can work with any client type application
Angular JS
Client side (web ) MVC processing
Entity Framework
ORM for data access
Bootstrap
CSS framework
JSON
Data exchange  format
ASP.NET Identity
Authentication /Authorization
SQL Server
Database
Open Web Interface for .NET (OWIN)
Hosting the application that runs outside IIS environments
Unit of work/Repository  Patterns
Data Access Patterns
JQuery
DOM Manipulation


The above technology stack provides solid foundation for building the web application

Learning Plan for Single Page application Development

                 Generally When we start to learn a technology, we start searching through google to get some good resources for learning and google through up large and misleading information even for small query as well.To address this issue and make learning in a consistent way, Microsoft came with MSDN and Microsoft Virtual Academy. But the books can not be replaced with online material for sheer enjoyment of learning.
                 In this blog, I`ll lay out a learning plan for Single Page Application which help you understanding of this technology.Indeed , This plan is for programmer who has already worked on the Asp.net and C#/JavaScript and want to get hands on the SPA.

1. Pro Asp.net MVC 5 by Adam Freeman :
             This is a fantastic book to really start your journey of MVC and provides good foundation of MVC way
2.Pro AngularJS by Adam Freeman  :
            This is a tough book and is kind of reference book to get understanding of Client side MVC way and
3.Pro Single Page Application :
            This is also tough book and provides you overall understanding of SPA architecture right from beginning till end of your SPA Development
4.Expert ASP.NET Web API 2 for MVC Developers :
             Once we got understanding of how SPA works,You can start to understand asp.net as a server side platform for SPA and this is easy reference book for web api for deeper understanding of asp.net server side platform.
5.Pro Asp.NET MVC 5 Platform :
            This is a reference book to harness you knowledge of asp.net as sever side platforms and this book provide you information on the modules,handler, state management and authentication for SPA development

             By following these books above, you get great confidence to work on SPA Development and i strongly suggest you to follow validated learning technique for learning any technology or depending on your requirements
 
 

Monday, July 6, 2015

Ways to understand an software application

Generally , When we are given a legacy application for our own understand and later to fix the bugs. We tend to follow the ways as below
  1. Open your application and start go through application UI
  2. Open the source code and go through each files to get an understand of application structure  
  3. Create the classes diagram using Visual Studio/IDE
  4. Open any documents(requirements ,help .. etc) related to the application and try to understand them
  5. Debug the application using IDE.
Issues /Pitfalls with the above approach.
  1. if you follow way 1 merely, It tends to be more of manual testing and helps a little
  2. if you follow way 2 and 3, it is not much of any help
  3. if you follow way 4 , In my view , Writing documents are kind of violation of the principle"Don't repeat yourself " and Generally gives what application is supposed to do and not what application is doing right now(we are interested in knowing this)
  4. if you follow way 5 , It is more of waste of efforts and time
My recommended ways to understand any application.
  1. Open your application,start go through application UI to get sense of how application looks like
  2. make a list of unknown words/terminologies to make sure we get little bit of domain knowledge
  3. Get to know about those words/terminologies by going through the documents/asking someone else/ Google them
  4.  try to understand your technical design documents if you have.
  5. Make a list of most critical functionality based on your present understanding(e.g. CRUD)
  6. Make a list of classes and discover their responsibility corresponding to the listed  in step 5
Follow the below steps for each of classes listed in the step 6
  1. Make a list of the keywords(language specific) which you don`t understand in the class
  2. Understand all keywords
  3. Break dependencies in the class/public methods involved
  4. Write characterizing unit tests (are tests that characterizes the actual behavior of a piece of code) based on your understandings of class/method responsibilities   
  5. Make sure that you have clear intention to get sense of what this does actually not to find any bugs 
  6. debug this unit test by seeing through every line of code and DB activity if any
  7. Stop when you feel that you got a sense of responsibilities the class has 
By following the steps above, We can get more confidence while working with a legacy application

Tuesday, June 23, 2015

Useful Techniques in Visual Studio 2013

Peek Definition :
        Whenever we want to see the definition of a method /class ,we usually hit F12 which will open a new tab and analyze that definition.By doing so, we get distraction easily and need to switch back to original tab to continue.
         Alternatively , we can hit ALT+F12 to see glimpse of the definition in small window within the original tab or even we edit the definition within that small window as below and we can close the window by pressing ESC button.
Note : we can go deeper into a definition, by choosing Peek Definition when we are already within the Peek Definition at the top of the hierarchy. The top Peek Definition will display a dot within the title that represents the depth of the Peek Definition.

Availability : Visual Studio 2013 Professional and upwards.
Navigate To Feature (Edit -> Navigate To, or by pressing Ctrl+, (Ctrl + comma)):
  • we can use the space to create an and between two words. Like writing sea and or emp, this gives results for “SearchEmployee” because it contains the strings “sea” and “emp.” 
  • The character @ can be used to search only class names instead of searching everything, including file names and file paths.
  • Use capital letters to create a camel search for a path, file, and class name. For example, searching for SED can result in a “SearchEmployeeDepwise” class

Availability : Visual Studio 2013 and upwards.

The Enhanced Scrollbars :
    We can enable the enhanced scrollbar mode by right-clicking  the scrollbar and choose Scroll Bar Options à Behavior à use map mode for vertical scroll bar. With this enhances scrollbars, We can preview code within the same file.
Availability : Visual Studio 2013 and upwards.

Thursday, June 18, 2015

Wrap approaches when you are adding new features/ modifing the existing features in a legacy application

Wrap method:

Suppose we have Employee class which does pay the salary to employee  as below.
And all of sudden there is a change requirement to log employee information into the database/file
The same thing can be achieved in a bit different way without changing the pay method and
 introducing the new method as below

Wrap Class :  is nothing but decorator patterns.In this case, the same new requirement can be implemented as below.

Wednesday, June 17, 2015

Sprout approaches when you are adding new features/ modifing the existing features in a legacy application

     The sprout approaches is one of approaches which helps us when we are changing a legacy application and use these approaches with cautious.

Used when:
  1. you do not have much time to get the class under test harness 
  2. these new changes are to be get under test harness
  3. you want to develop these changes/method in test driven development
Types
  1. Sprout Method
  2. Sprout Class
Sprout Method : Steps to implement this type
  1. Identify where you need to make your code change.
  2. If the change can be formulated as a single sequence of statements in one place in a method, write down a call for a new method that will do the work involved and then comment it out.
  3. Determine what local variables you need from the source method, and make them arguments to the call.
  4. Determine whether the sprouted method will need to return values to source method. If so, change the call so that its return value is assigned to a variable.
  5. Develop the sprout method using test-driven development.
  6. Remove the comment in the source method to enable the call.
 Tips to get a new method under test harness
  • If the constructor is having bad dependencies, then try to pass the null values 
  • If passing null values to the constructor does not work, make that method as static.
Sprout Class : This type should be used  when the you can not get the new method under test harness even after the passing null values to the constructor and you can not make the new method as static.
Steps to implement this type as follows.
  1. Identify where you need to make your code change.
  2. If the change can be formulated as a single sequence of statements in one place in a method, think of a good name for a class that could do that work. Afterward, write code that would create an object of that class in that place, and call a method in it that will do the work that you need to do then comment those lines out.
  3. Determine what local variables you need from the source method, and make them arguments to the classes' constructor.
  4. Determine whether the sprouted class will need to return values to the source method. If so,provide a method in the class that will supply those values, and add a call in the source method to receive those values.
  5. Develop the sprout class test first.
  6. Remove the comment in the source method to enable the object creation and calls. 

Seams in C#


Seams : it is place where you can alter behavior in a program without editing in that place

Seam Enabling points :It is place where you can make the decision to use one behavior or another

In the above snippet, suppose we do not want to save any thing to data base or alter the save behavior. this place is called the seam

Seams types :
  1. Pre-processing seams (enabling point is Pre-processors)
  2. Link seams(enabling point is the classpath where you can change the assembly )
  3. Object seams(enabling point is the class constructor)




Changing Software

Legacy code :Code without the test.
Refactoring :The act of improving design without changing its behavior.
Optimization : It deals with resources (usually time or memory) Optimization.

Summary of reasons for changing software and its impact :
The below table should be read as e.g. if Refactoring (as a reason for changing software) is to be done ,Its impact are changes in structure




Impact On
Reasons for changing software
Adding Feature
Fixing a Bug
Change Requirements
Refactoring
Optimizing
Structure
Changes
Changes
--
Changes
--
New Functionality
Changes
--
--
--
--
Existing functionality
--
Changes
Changes
--
--
Resource Usage
--
--
--
--
Changes

Tuesday, June 16, 2015

Interface Segregation

Interface Segregation
It states that interfaces should be small and At their simplest, interfaces contain single methods that serve a single purpose.

The reasons for segregating (splitting ) large interface into smaller interfaces  :
  1. Self-documentation for other developers to follow
  2.  Decorating interfaces : we may have to decorate implementations using decorate pattern/adapter pattern  in the cases  where cross-cutting concerns such as logging transaction management ,caching are required
  3. Architectural Need :The interfaces are segregated based on the architectural need  e.g. the Data access technology  is different for the same data
  4. Client Need :When a set of certain set of operation is only available to a certain clients, the large interfaces are segregated into smaller interface
Examples of client needs  :
  1. Client A is having requirement to get read only a particular data from service and Client B is to get write only to the same data
  2. A set of certain set of operation is only available to a certain clients when the application is in specific state For example, the operations that a user can perform are typically different depending on whether that user is logged in or not.                       
Client construction :
          Client can construct segregated interfaces in 2 ways  as below.
  1. Single implementation, single instance : all of the segregated interfaces are implemented in a     single class, a single instance is sufficient for all of the related  dependencies on the client.
  2. Multiple implementations, multiple instances : If each segregated interface is given its own       implementation, each of those implementations needs to be constructed and supplied to the       client.
The Interface Soup anti-pattern    :
A common mistake is to take the segregated interfaces and reunify them in an aggregate as below.
In the above fig, the segregated interfaces are reunified in a single interface forming “interface soup”, resulting in providing implementations of all operations and so there is no scope for targeted decoration

The open/closed principle


It defined as “Open for extension and closed for modification ”

Exception to “Closed for modification” rule :
  •  Client awareness :Any change in source code is allowed to existing code as long as it does     not also require a change to any client of that code.
  • Bug Fixes :Steps for fixing bugs (follows “Arrange, Act, Assert” and  “Red, green, refactor”  patterns)    
                            1. Write a failing unit test and/or integration test 
                   that specifically targets the bug
                        2. The source code is modified so that the unit test 
                   passes
  • At this juncture ,It is necessary to modify the source code which is exception to OCP rules

Extension Points : Classes that honor the OCP should be open to extension by containing defined extension points where future functionality can hook into the existing code and provide new behaviors and there are 3 extension points as below.
  • Virtual methods : Any class that marks one of its members as virtual is open to extension. This type of extension is via implementation inheritance.
  • Abstract methods : This is an example of the Template Method pattern, in which an algorithm is modeled but its general steps are customizable because of delegation to abstract methods. In effect, the base class delegates the individual steps of  the process to subclasses.
  • Interface inheritance : the client’s dependency on a class is replaced with interfaces

Note : Extension points should carefully be created for cases where requirements are unclear, changeable, or difficult to implement

Protected variation : Identify points of predicted variation and create a stable interface around them and suggests that you identify parts of the requirements that are likely to change or that are particularly troublesome to implement, and factor these out behind extension points
  • Predicted variation : The requirements of an individual class should be linked directly to a business client’s requirement
  • Stable Interfaces : all interfaces chosen to represent an extension point should be stable. The likelihood and frequency of interface changes should be low, otherwise you will need to amend all clients to use the new version.