Archive for 'Concepts'

Revisiting Algorithms: Fibonacci Sequence

I am starting new posts that visit many of the familiar algorithms that we have already learnt in the past. I will use C# as the primary language to represent these algorithms. To start, let us start with a very simple example, Fibonacci Series. 0,1,1,2,3,5,8,13,21,..etc are typically called Fibonacci numbers. These numbers were well known in ancient India. In short, each number is a sum of the previous two numbers with the seed values being 0, 1. The following is the C# code that outputs a series of Fibonacci numbers with input being the number of Fibonacci numbers to generate.

   1:  public static int[] GenerateFibonacciNumbers(int n)
   2:  {
   3:      int[] arr = new int[n];
   4:      arr[0] = 0;
   5:      arr[1] = 1;
   6:      for (int i = 2; i < n; i++)
   7:      {
   8:          arr[i] = arr[i - 1] + arr[i - 2];
   9:      }
  10:      return arr;
  11:  }

5 must have books for programmers

Every programmer should have these books on his or her shelf.  The authors of these books cover a wide range of material in the form of design patterns, real-life experiences, code samples,  and software construction. They present the material really well in a platform agnostic way. If you are serious about your career in computer programming, these books can help you build great reliable software. These books are not ranked and are in no particular order. I linked each of these books to Amazon but you can find them at other stores as well.

 

Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, John M. Vlissides
Code Complete by Steve McConnell
Pragmatic Programmer by Andrew Hunt, David Thomas
Refactoring: Improving the Design of Existing Code by Martin Fowler
The Art of Computer Programming: Fundamental Algorithms by Donald E. Knuth

ASP.NET MVC Round up

ASP.NET MVC enables developers to easily build web applications using a model-view-controller pattern.  It enables full control over HTML markup and URL structure, and facilitates unit testing and a test driven development workflow. It is free and fully supported by Microsoft.  Below are some links that I feel provide a great roundup for tracking ASP.NET MVC.

Rob Connery is building a storefront using ASP.NET MVC. He has over 26 webcasts and blog posts, documenting the building of an e-commerce storefront using ASP.NET MVC. He uses Domain-Driven-Design and other design patterns to build his storefront. I recommend his entire series for anyone starting out on ASP.NET MVC.

Scott Guthrie on ASP.NET MVC. I don’t think ScottGu needs any introduction.

Phil Haack is the Project Manager on the ASP.NET MVC project. He gave a great presentation at MIX’09 called Microsoft ASP.NET Model View Controller (MVC): Ninja on Fire Black Belt Tips. He followed it up with a blog article on his site where he uses JQuery Grid with ASP.NET MVC.

Scott Hanselman gave a great presentation at MIX’09 demonstrating his nerd-dinner application built on ASP.NET MVC.

Stephen Walther has a series dedicated to ASP.NET MVC. He provides some great tips, sample code and much more on his blog.

Related Links

Silverlight: 4 ways to dominate the RIA world

Almost every conference or meeting that I attend these days has people talking about Microsoft’s Silverlight and Adobe’s Flash. Both technologies are great and have their strengths and weaknesses. Having worked with both Flex/Flash platform and the Silverlight/JavaScript/C#,  I personally like the Silverlight runtime and the great development tools that come with it. There are several blogs that draw out comparisons between the two, but I would not attempt to do that in this article. Instead, I will outline some key points that can help Silverlight beat its competition in the coming years.

Performance: This will be the single most important metric and Silverlight should get this right soon. Currently there are several tests available (bubblemark, guimark), that showcase differences in performance between Silverlight and other RIA platforms. Regardless of who fares better in these tests, Silverlight should rapidly evolve and come up with the best performance stats on both Windows and MAC.

Mobility: This will be the ground zero for RIA technologies. I do not foresee myself using a computer or a laptop in the future, instead, I am hoping that we will be using extremely savvy ultra-thin mobile devices that can be used to surf the web, listen to music, etc., Silverlight should focus on building a great story around various mobile platforms.

Silverlight Promise: Microsoft should come up with a ‘Silverlight promise’ akin to the Ubuntu promise, stating that it will always remain a cross-browser, cross-platform browser plug-in. There is a general sense in the MAC community that Microsoft may pull the plug on Silverlight support for MAC OS in the future. It is already doing this by making all its tools available on MAC platform. Having this kind of promise will help them win over their hearts and minds forever.

Reach: Flash Player has a reach of more than 80% with the general population. In spite of a similar market share of Windows and IE,  Silverlight is struggling to find a large user base. Of course Flash had the advantage of the video that made all of us install it on our machines, it is time for Silverlight to come up with a strategy for achieving a greater market share. It should partner up with Mozilla, Ubuntu, and everyone else who can help it reach that level.

I can go on with several more points, but that these are the most essential for guaranteeing Silverlight’s success.

Solid Architecture: S.O.L.I.D Principles

Domain Driven Design (DDD) and Service Oriented Architecture (SOA) can basically be defined as aggregate functions of principles, patterns, and most importantly Object-oriented concepts. In order to build a highly scalable and reliable architecture, it is very important for us to follow these important design patterns, and when they are coupled with a set of good principles, results in a great software. One such set of rules that should not be overlooked are S.O.L.I.D principles, first coined by Robert C. Martin.

Single Responsibility Principle (SRP) A class should have only one reason to change.
Open/Closed Principle (OCP) Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification
Liskov Substitution Principle (LSP) Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T.
Interface Segregation Principle (ISP) The dependency of one class to another one should depend on the smallest possible interface.
Dependency Inversion Principle (DIP) Depend upon abstractions (interfaces), not upon concrete classes.

There are plenty of resources available on the Internet on these principles. So far, I really liked Steven Bohlen’s video presentations on dimecasts.net.

Also, I recommend the following books to get a good picture on building overall good software.

codecomplete agilerobert

Rules Engines

Rules Engine can be defined as a framework that is used to manage and automate business rules. It is very useful to have such a framework in place specially when these business rules need to be modified frequently. Often, we as software architects need to design our applications to handle such frequent change in business rules. There are several rules engines available in the market. Some of the rules engines  available are;

.Net

  • Biztalk Server
  • ILog Rules for .Net

Java

  • Jess
  • Jboss Rules
  • ILog JRules

Ruby

  • Ruleby
  • Ruby Rools

Most of these engines, or frameworks use Dr. Charles Forgy’s Rete Algorithm. Rete is Latin for Net or network. It is a pattern matching algorithm comprising of rule compilation and rule execution. Before adopting this in your enterprise, every Architect must understand this algorithm to know the various architectural implications that it can have on the overall system like performance, scalability, etc., Also, just because you implement a rules engine, it does not mean that you can put all your business requirements and rules inside it, as some of the business rules cannot be expressed. Most often, these business rules cannot be expressed by the business users, and have to be coded by programmers.