Learning C++

Learning C++

Like humans use languages to communicate with each other, programming languages use coding to communicate with the processor. Computer code accomplishes different tasks that involve talking with the processor. Modern programming languages were developed in the late 1940’s.  One of the very first programming languages was the Assembly language, a low-level programming language that simplified the language of machine code. FORTRAN (FORmula TRANslation), which was introduced around 1957, was a language specifically geared for high-level scientific, mathematical, and statistical computations. It is one of the most successful languages, and is still in use today in some of the world’s most advanced supercomputers.

C, the precursor of C++, was developed by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. Today, there is a whole bunch of languages that are used to develop code. Many of them are identified with the flavour of the OS. For example, PHP works best for Linux, VB.NET works with Windows, etc. However, in general, most popular programming languages like C, C++, Python, etc. run on all kinds of OS.

Why C++
While there are many languages available today, C++ still continues to be one of most preferred languages. The reason it is popular is because it is fast, it can be used to develop anything from very simple (say adding two numbers) to highly complex programs that include developing a complete operating system. It has enhanced features that allow it to be more close to hardware than most other languages. It is pertinent to note here that C++ has been derived from C. It has similar syntax as C, is compiled almost the same way, is close to hardware like C, and shares code structure with C. Like C, C++ also has unique concepts like stack, heap, file-scope and static variables that set it apart from some other coding languages. C++ is a language in which new and different features are built on top of an existing syntax. Due to this, C++ is often referred to as a hybrid object-oriented programming language.  Unlike C, however, C++ has added many features, like enabling object oriented programming, templates, memory handling, error handling and more tools for the programmers. Like any human language, C++ provides a way to express concepts. If successful, this medium of expression will be significantly easier and more flexible than the alternatives as problems grow larger and more complex. However, at its heart, what separates C++ from C is the fact that it is an Object Oriented Programming (OOP) language.

Object Oriented Programming (OOP)

So, what exactly is OOP? Before we explore OOP in detail, let us first understand what procedural or structured languages are. Procedure / structure oriented programming basically consists of writing a list of instructions for the computer to follow, and organizing these instructions into groups known as functions. The problem to be solved is viewed as the sequence of things to be done such as reading, calculating and printing. The primary focus is on functions, and everything in procedural languages revolves around invoking these functions. In a multi-function program, many important data items are placed as global so that they may be accessed by all the functions. Each function may have its own local data. Global data are more vulnerable to an inadvertent change by a function. In a large program it is very difficult to identify what data is used by which function. In case we need to revise an external data structure, we also need to revise all functions that access the data. This provides an opportunity for bugs to creep in.

Another serious drawback with the procedural approach is that we do not model real world problems very well. This is because functions are action-oriented and do not really corresponding to the element of the problem. FORTRAN and C are some popular procedural languages.

OOP

Alan Kay, one of the promoters of the object-oriented paradigm and the principal designer of Smalltalk, has said: “As complexity increases, architecture dominates the basic materials”. Before PCs gained popularity, computing was limited only to mainframes. Such mainframes were bulky machines, and required a stack of punch cards to run code. The process was extremely cumbersome, as even a single mistake meant punching the cards again and running the program. PCs facilitated programming, and unleashed the real power of computing. The first mathematical / scientific programs were mostly developed using FORTRAN and then C, which are structured languages. However, as programming proliferated and became more complex, even structured languages began to show some chinks in its armour. As mentioned above, they were not conducive to scaling, and were prone to error, and de-bugging them was a major chore.
OOP is an approach to program organization and development that attempts to eliminate some of the pitfalls of conventional programming methods by incorporating the best of structured programming features with several powerful new concepts. It is a new way of organizing and developing programs and has nothing to do with any particular language. However, not all languages are suitable to implement the OOP concepts easily.
OOP is based on a few major concepts that differentiates it from the structured languages:
  1. Everything Is an object: this is one of the most important concepts of languages based on OOPs. C++ and other OOPs based language. These objects communicate by sending and receiving messages (in terms of objects). They also have their own memory.
  2. Classes: a class describes the contents of the objects that belong to it. In essence, it describes an aggregate of data fields (called instance variables), and defines the operations (called methods). Every object is an instance of a class, and the class holds the shared behaviour for its instances.
  3. Data Abstraction: another important concept in OOPs is data abstraction. Data abstraction hides unnecessary details from the user; enabling them to focus on their task. A simple example is driving a car. The driver need not know about engines, spark plugs, carburetors, etc. in order to drive a car. Hiding these details under the hood (pun intended!), allows the drivers to focus on what they want to do – drive the car. Similarly, by hiding unnecessary details from the user, OOP enables the user to implement more complex logic on top of the provided abstraction without understanding or even thinking about all the hidden complexity.
Software programming has seen a phenomenal growth. Web applications, web development, all have seen a high growth rate. In India, organizations like CDAC have already started computer education, and If you wish to make a career in software field as a C++ programmer, an admission in a reputed institute will be of immense help.