Friday, March 20, 2009

A Quick Introduction to C++

Update: Please refer to Crackpot wiki documentation for an updated version of this piece.

This article was copied from Crackpot wiki on Mar 21, 2009, as the sourceforge wiki is not public, and due to bugs in sourceforge, the wiki links are broken (atleast for private wikis).

Introduction to C++

C++ is a large language, supports a large variety of programming paradigms and a large number of libraries have been written in C++. The language is designed to make programming more enjoyable for the serious programmer. There are hundreds of caveats that a C++ programmer has to understand. Most of the caveats arise from backward compatibility and practical issues in standardization.

Wikipedia entry at http://en.wikipedia.org/wiki/Cplusplus is a good place to start for people who have never programmed in C++. A note for C programmers – although C++ has almost all features of C, programming in C++ involves a completely different way of thinking. Compared to Java, C++ is more powerful and much more complex.

C++ has evolved a lot in the last 5-10 years. For example compiler implementations of certain parts of STL were known to be buggy 5 years ago, but most of such issues have been fixed in the latest versions of the compilers. The date of any reference is important to judge its relevance with the current C++ version. In deed the way of designing in C++ has been evolving with confirmation of new features – for example what was done using inheritance five years back may be done using template traits today with tradeoffs.
Here is a partial list of software domains primarily running on C++: databases, operating systems, web browsers, computer games. C++ is most useful for evolving domains and can form the base for a higher level language like Java, Ruby or Python. At the same time, it is possible to efficiently implement systems without getting too low level.

Some Quick Lists Related to C++

Compilers: Microsoft's Visual Studio cl.exe (most popular), GNU GCC g++ (most popular), Intel C++ compiler.

People
: Bjarne Stroustrup (primary author of C++), Herb Sutter (C++ guru, concurrency), Doug Lea (co-writer of GNU C++ library, middleware, Java Concurrency), Scott Meyers (C++ guru), Andrei Alexandrescu (C++ guru), Doug Schmidt (middleware, patterns), Andrew Koenig (C++ standards committee, C++ guru).

Some illustrative C++ libraries
: STL (standard template library – has several implementations), Boost (has many libraries that are candidates to be included into language standard), Blitz++ (fast numeric library), ACE (middleware, concurrency patterns), STL port (a portable implementation of STL), Loki (design based on modern C++ features like templates), OpenMPI & Intel Thread Building Blocks (parallel programming)

C++ Resources

There are several books and you have to choose the ones that fit your taste.

To start
, "Thinking in C++" by Bruce Eckel is a good resource available both online and in print. "Accelerated C++" by Andrew Koenig and Barbara Moo has a top-down approach to teaching the language. "The C++ Programming Language" by Bjarne Stroustrup is a comprehensive book but slightly advanced for the beginner. Also interesting is his FAQs at http://www.research.att.com/ ~bs/bs_faq2.html. Check out Doug Schmidt's take on an Overview of C++ at http://www.cs.wustl.edu/ ~schmidt/PDF/C++-overview4.pdf, the "practical" tutorial at http://www.ge.infn.it/geant4/training/ornl_2008/c++_oop.pdf, and the "practical programming methodology" course at http://www.cs.ualberta.ca/~mburo/courses/201.w2006/ (just some links I found, you can find other better ones).

Once you have made a start and are raring to get to the next level, check out C++ FAQ Lite at http://www.parashift.com/c++ -faq-lite/. It discusses several caveats of the language. "Effective C++" and "More Effective C++" by Scott Meyers discuss ways to write good code and bad code. "Effective STL" also by Meyers discusses the same for the standard library. "C++ Guru of the Week (GoTW)" is an online list of interesting questions and answers by Herb Sutter. This list was printed into books "Exceptional C++" and "More Exceptional C++". "C++ Coding Standards" by Sutter and Alexandrescu is a summarization of many of the caveats of C++ contained in the previous references, and is highly recommended. "Design Patterns" book by "Gang of Four" is the bible for design patterns used in industry and contains many examples in C++.

Getting to the next, advanced level definitely needs an in-depth understanding of C++ Templates. Some good resources for this are "C++ Templates" by David Vandevoorde and Nicolai M. Josuttis, "Modern C++ Design" by Andrei Alexandrescu and "C++ Template Metaprogramming" by David Abrahams and Aleksey Gurtovoy.

Future Developments

C++ is working towards a new standard named C++0x. It has several new and powerful features. See http://stackoverflow.com/questions/226061/c0x-when#229072. Current versions under discussion by Standardizing Committee are called Tr1, Tr2; see http://www.open-std.org/JTC1 /SC22/WG21/

After I wrote this article, I found this excellent site by Comeau Computing which cover the topic well. Another exhaustive resource list is here.

Please let me know if you find useful resources. I will then link to them.

3 comments:

  1. Thank you for sharing.

    I'd like to suggest "Overload" journal by ACCU: http://accu.org/index.php/journals/c78/

    ReplyDelete
  2. Btw, TR1 is rather complete, only TR2 is being drafted. Microsoft is the first vendor to ship full implementation of TR1 along with its C++ 2008 compiler and toolchain. Liberal developers can use TR1 in Boost library before such a move by Microsoft.

    ReplyDelete