C Language – The code of God

dna

One could easily say “In the beginning there was C language. All else were variants” and not be far from the truth.  As I headed to work today I was ruminating on the impact C language has had to the computing landscape for the past 4 decades. No other language has had such a significant impact.

C Language was created by Dennis Ritchie & Brian Kernighan in Bell Labs, around 1972. C was the trigger for many seismic shifts in the computing industry. The language is terse and compact. C language strikes a rich balance between brevity and readability.

C language, in my opinion, is the code of God.

We can easily divide the epoch of programming languages as before C and after C. Before C, there was a babel of languages from FORTRAN, COBOL, Pascal, Basic, Prolog, Ada, Lisp and numerous others. When C language, entered the scene, many other languages simply faded away. C set the tone for programming and spawned an entire industry.

Many of the popular constructs like the if-then-else, for, while loops had a crisp simplicity in C. C included in its repertoire the ability to manipulate the bits of registers  all the way to creating complex and rich data structures with the help of structures and pointers. In fact C was probably one of key enablers for the development of the legendary Operating System (OS), UNIX from Bell Labs.

Building the innards of an OS is an undertaking of gigantic proportions and requires the need to be able to manipulate the registers of the numerous input/output devices, the processors and the memory.  C was eminently suited for this the job. Also the complex algorithms of OS for e.g. process scheduling, memory management, IO management, disk management could now be programed simultaneously in a bottom-up fashion by working at the ‘bit’ level and in a top-down fashion allowing for complex data structures and algorithms required for scheduling, memory and IO management. . With a powerful language C, the birth of UNIX was a given.  When AT&T distributed UNIX to the universities in the late 1970 it created serious shock waves in the industry. Since then UNIX has resulted in numerous variants – Solaris, HP-UX, AIX, iOS, Linux and then Android and so on. Well, that’s another story!

C came at an opportune time when the internet was at its infancy. C proceeded to be useful also for protocol of the internet namely TCP/IP. C spawned an army of programmers all keen to take on this new language twiddling bits, bytes and complex data structures of the OS and protocols.

C, UNIX and TCP/IP almost entirely power the internet and the WorldWideWeb.

The beauty and brevity of the language enabled programmers to easily express complex problems as units of C functions. Pointers, and bit manipulation gave it a power that was unparalleled at that time. Soon C became the de facto programming standard. C, in fact, became a way of thinking for problems!

So it was not surprising that languages that came after C used the same or similar constructs. C++ maintained identical constructs of C to maintain backward compatibility as well as to allow the already existing millions of C programmers easily assimilate the OO paradigm. Java, from Sun Micro Systems, followed suit.  Java, a very powerful and popular language, also retained the flavor of C.

Many interpreted and dynamic languages like Perl, Python, and Ruby all have C look-alike constructs,

Even in the languages of the Word Wide Web, C familiarity is extremely useful. JavaScript, PHP look familiar to one who is proficient in C.

The only other language which is entirely different from C from the bottom up, in my opinion is Lisp. Lisp is older than C and requires an entirely different way of thinking. There are possibly others too.

C balances economy of syntax, style and structure in programming exquisitely. It does have a few shortcomings, as its detractors would like to say. For e.g. C in the hands of a novice can spell disaster. It has also been accused of allowing programmers to create impregnable code. But in the hands of an experienced programmer it is possible to create really, robust code. UNIX and its variants are considered to be more resilient than OS’es to hackers.

C is really the soul of programming!

Find me on Google+

The Future of Programming Languages

How will the computing landscape evolve as we move towards the next millennium? Clearly the computer architecture will evolve towards a more parallel architecture with multiple CPUs each handling a part of the problem in parallel. However, programming parallel architectures is no simple task and will challenge the greatest minds.

In the future where the problems and the architectures will be extremely complex, the programming language will itself evolve towards simplicity. The programming language will be based on natural language that we use to define problems. Behinds the scenes of the natural language interface will be complex algorithms of Artificial Intelligence which will perform the difficult task of specifying the definition of problem into a high level programming language like C++, Java etc.

The Artificial Intelligence interface will handle the task of creating variables, forming loops and actually defining classes and handling errors. The code generated by the machine will have far less syntactical errors than those created by human beings. However while a large set of problems can be solved by the AI interface there will be a certain class of problems which will still require human intervention and the need to work in the languages of today.

One of the drivers for this natural language of programming of the future, besides the complexity of the computer architecture is the need to bring a larger section of domain experts to solve the problems in their fields without the need to learn all the complex syntax, and semantics of the current programming languages.

This will allow everybody from astrophysicists, geneticists, historians and statisticians to be able to utilize the computer to solve the difficult problems in their domain.

Find me on Google+

Programming languages in layman’s language

There is such a wide variety of programming languages that there is always confusion as to why there is such a profusion of languages. Different programming languages solve different classes of problems. Programming languages can be classified broadly into the following 4 classes.

Procedural Languages: In these languages one thinks in terms of the sequence of steps to solve the problem. It could be thought of solving the problem in 1st person and then substituting the “I” with “the program”. So for example in procedural language we could think

I will wake up.
I will brush my teeth
I will open fridge
I will take milk
I will warm milk

So in procedural languages actions are performed sequentially to achieve the desired end result.

Examples: FORTRAN, BASIC, Pascal, C

Object Oriented (OO) Languages: When a problem is solved using Object Oriented techniques we look at the world objectively. So we need to first identify the participants and functions performed by each of these participants. So the above situation would be viewed as

I, Fridge, Microwave – Participants

then we need look at what functions the above 3 will perform
I – wake up, brush
Fridge – Open door, close door
Microwave – Warm

Hence in OO languages the problem is solved as the interaction of functions between participating objects.Examples: C++, Java, Smalltalk, C#

Both procedural and OO languages are compiled languages and are also known as “Imperative Languages”. A useful analogy is to view compiled programs as mashed, pre-cooked food that can be easily assimilated by the digestive system or the raw hardware.

Dynamic Languages: Here these languages are either interpreted or converted to byte code. Interpreted languages are similar to raw & uncooked food which must be crunched, munched and digested on the fly. However these languages include in themselves many, many features that are commonly used. While the first two would just specify the method, dynamic languages include several specific features as functionalities. To use an analogy while in the above 2 programming language types one would set the time and the power level for each item to heat in a microwave, dynamic languages come with readymade buttons for those frequently used.

I – wake up, sleep, eat, drink, wash etc
Fridge – Cool, refrigerate, thaw, and freeze
Microwave – Heat popcorn, frozen food, meat etc

Since you get a lot of stuff for free and the program is interpreted on the fly Dynamic Languages take a lot more time

Examples: Perl, Python, Ruby

Functional languages: Here we think in terms of functions that are performed on items. They can be performed on any object.

For example the above problem would be viewed as the following main functions
E.g. Wake, sleep, warm, thaw, heat, cool, freeze.
We then take and apply the function ‘warm’ on the ‘milk’
Heat on ‘vegetables’  etc

In Functional Programming functions invoke other functions to accomplish a task. The problem is solved from the inside-out. In Functional languages like Lisp one starts with some core functions and build layers over it. For e.g. in a functional language we would express calorific energy as

metabolize (assimilate (digest (chew (food))))

Examples: Lisp, Clojure, Haskell, Erlang

Each language is best suited for only certain applications. So just like it is inappropriate to use pliers where an Allen wrench would suffice we need to know which language is most suitable. If we know what the class the problem is and the performance we want we can choose the appropriate language

Find me on Google+