Thursday, March 22, 2012

Why a C++ Developer May Find it Uneasy to Work With C#

Let me put up disclaimer first, since the title of article may contradict with the views of C# developer community. This article is based on my own experience working on both C++ and C# languages for more than 4 years. And this article is intended to developers migrating from any flavors of C++ technology to C#. Also a C# developer may look upon this article to get a picture of how distinct and abstract is C# language design when compared to other programming languages which runs natively on hardware.

This article is highly abstract, which looks only into syntax and semantics of the languages, and doesn't really dig deeper into design considerations of the language.

So, let's quickly get to the point. How C# is highly distinct from C++ ?

  •  Absence of Pointers
    One of the prime goals of C# language design is to get rid of ugly pointers and make coding easy, quick, clean which finally conduces " Rapid Application Development " . But believe me a C++ developer feels at home working with pointers, it's no real fun coding in the absence of pointers. In fact a matured C++ developer finds it really hard to write programs a deprived of pointers .

    Not to be demotivated , Microsoft bequeathed every single responsibly of  'pointers'  in the hands of  " References " which basically alludes pointers. The message is clear Microsoft  doesn't expect or allow developers to mess around by having direct memory access.

    • Memory Management
      The .Net framework further makes developers life easy or rather I say lazy by, completely managing the memory allocations and deallocations in the name of  "Garbage Collection" and branding the resultant code as " Managed Code ". What I really don't understand is that when an experienced developer can write complex algorithms, can design systems involving multilevel difficulties, is it really hard be responsible for memory management.

      By delegating memory management to framework, a developer really loses flexibility on design and functioning of the system. If developer had the luxury of memory management as in C++ he could clearly circumscribe on the target hardware capabilities and limitations on which the program will be run. And could also customize applications to be run on platforms constrained by hardware limitations.

      • Member Value Assignment Inside Class Definition
        The basic principle of Object Oriented Programming conveys that " Class represents a generic blueprint of an instance " and values of data members are specific to an instance, but 'static' is an exemption here. Contrary to this, C# language design allows developers to assign initial value to data members of a class as shown below.

        public class Student
           public string Name = " James Frank " ;
        ANSI standards for Object Oriented language implementation ensures initialization of data members of a class to default values through default constructor. If we already have a default constructor which is clean, and serving the main purpose , C# feature of member value assignment inside class definition is "Redundant" and affects code readability. Any feature of a language unless it serves a signification purpose is redundant or burden.

        • Boxing and Un-Boxing 
        C# developers must be aware of the fact that, it is possible to explicitly convert a value type variable to reference type, and a reference type variable to value type through a feature called Boxing and Unboxing respectively.
        short S = 20 ;
        object ShortObject  = S ;
        short S = (short) ShortObject ;
        C# provided this feature to have a unified type system in place which allows value type to represent the underlying data altogether wrapped in a new representation called " reference " and vice versa. Unless there is a flaw in design, how the polymorphic classes are built this feature is of no worth, and if at all one is using this feature it necessitates the need to trace back derivation hierarchy of polymorphic classes.
        • Static Constructors
        This is an odd feature of C# , it breaks the basic understandings of Object Oriented Programming in being developer friendly. Below is an example of static constructor

        public class employer
              private static string CompanyName ;
              static employer()
                 CompanyName = "Nokia" ;
        Static constructor ensures that, static data members are always assigned to an initial value. And it is called, when an instance of class is created or a static member function is invoked.
        I mentioned this is an odd feature because, this is a work around for C# language design which doesn't allow anything to be defined outside of a class. In the absence of this constraint static data members could have been defined and initialised outside class definition as in C++
        string employer :: CompanyName = "Nokia" ;
        • Redundant Out and Reference Parameters
        C# has introduced couple of enhancements in parameter passing mechanisms, to cut short developer efforts from writing lengthy code. Out of which "Out" and "Ref" are the two parameter decorators. Value for "Out" parameter is assigned by the called member, as shown below.

        public static void Add ( int x, int y, out int ans )
             ans = x + y ;

        Usage :
        public static void calculate()
             int ans ;
             add ( 1, 2, ans ) ;
        The sum is stored in 'ans' variable by callee " Add " .
        Now consider "Ref" decorator, the only difference is "Ref" parameter must be initialized before being sent to callee. So if this is the only constraint we don't really need "Out" parameter at all, all which is required is to use "Ref", ensuring that the variable is assigned to initial value.

        These are the couple of features of C# which I found redundant, ugly,  which leads to confusion, and mystifies clarity of  the language rather assisting a developer. However these are my own views but not conclusions.

        Friday, March 2, 2012

        Nokia Pulse, Your Freedom of Expression

        Privacy, Privacy, and Privacy .. Yes you heard it right, the most concerned, researched, and discussed topic of internet community of all the time is Privacy.  As internet has grown into integral parts of our lives the loquacious couldn't stop themselves from being very expressive on internet. And finally there arose the problem of  " Individual Privacy ".

        Now a days with more and more incidents of breach of individuals' privacy, people are very watchful in what they share on internet. But with the unparalleled excellence of Facebook in social networking and Google+ in bringing the like minded people together individual privacy has again taken a backseat as people are becoming liberal in what they share. But if you observe keenly the breach of individuals' privacy really isn't due to sharing things with others but due to " What you share " and " With whom ".

        So, what is the solution ?
        Social networking giants like Facebook, and Google+ provide features to create closed groups, but people hardly use it due to usability issues, very confusing settings, and credibility measures. Even when a person with technical background finds it difficult to play around with these setting one can't expect a layman to use those.
        This was the time when Nokia pitched into development of a unique social networking product " Nokia Pulse "

        What is Nokia Pulse ?
        Nokia Pulse is a unique product which gives life to your day to day conversations, It is as intuitive as you verbally interact with your loved ones. 
        Wishing your friends good morning, asking about their whereabouts, letting them know where you are, calling them for a coffee at your favorite hangout place, letting them know how to reach the venue, etc.. all these are just a few taps on Nokia Pulse.

        Let me explain how...

        Create your closed user groups
        Segregate your friends, colleagues, relatives, and the people you care most, across different user groups. This is basically the first step of achieving individuals' privacy by deciding who gets to know what. You don't intend to share everything with everyone.

        Tell your friends about how you freaked out at weekend party, Discuss technical things with your office colleagues,  share your trip photos and experience with your family and relatives. And what not, the possibilities are boundless, but at any point of time you have the supreme control of who views what.

        Propose your plans and let your friends comment

        Are you fanatical about going on trips, let your friends know about it, propose your plans with the destination info, some photos and share it with your intended group. Your friends from that group would revert back with their opinions about the plan, discuss on it, prepare a concrete plan and you are ready to drive, and of course Nokia maps will guide you to destination.
        Invite your friends for events, help them with navigation details .
        Would you plan to hangout at a cafe with your friends, or call them for a cricket match. Say it with Nokia pulse, type in your message, add a picture which speaks your mind, add the destination info with Nokia maps and just share it.

        Nokia pulse makes all these possible with the tap of a finger, in epitome pulse assures an Intuitive, highly secured, private, credible, social networking solution that we envision of.