Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why C++ is called federation of languages?

I was reading a tutorial on C++ and the following line came up. No other details were provided to explain further

C++ is a "federation of languages" and supports multi-paradigm programming, there are many options available to us.

What does it mean when C++ is called federation of language and also what is multi-paradigm programming?

like image 991
Farsan Rashid Avatar asked May 24 '18 05:05

Farsan Rashid


Video Answer


3 Answers

This is the explanation from Effective C++ Third Edition 55 Specific Ways to Improve Your Programs and Designs By Scott Meyers, Item 1: View C++ as a federation of languages.

Today's C++ is a multiparadigm programming language, one supporting a combination of procedural, object-oriented, functional, generic, and metaprogramming features. This power and flexibility make C++ a tool without equal, but can also cause some confusion. All the "proper usage" rules seem to have exceptions. How are we to make sense of such a language?

The easiest way is to view C++ not as a single language but as a federation of related languages. Within a particular sublanguage, the rules tend to be simple, straightforward, and easy to remember. When you move from one sublanguage to another, however, the rules may change. To make sense of C++, you have to recognize its primary sublanguages. Fortunately, there are only four:

  • C. Way down deep, C++ is still based on C. Blocks, statements, the preprocessor, built-in data types, arrays, pointers, etc., all come from C. In many cases, C++ offers approaches to problems that are superior to their C counterparts (e.g., see Items 2 (alternatives to the preprocessor) and 13 (using objects to manage resources)), but when you find yourself working with the C part of C++, the rules for effective programming reflect C's more limited scope: no templates, no exceptions, no overloading, etc.

  • Object-Oriented C++. This part of C++ is what C with Classes was all about: classes (including constructors and destructors), encapsulation, inheritance, polymorphism, virtual functions (dynamic binding), etc. This is the part of C++ to which the classic rules for object-oriented design most directly apply.

  • Template C++. This is the generic programming part of C++, the one that most programmers have the least experience with. Template considerations pervade C++, and it's not uncommon for rules of good programming to include special template-only clauses (e.g., see Item 46 on facilitating type conversions in calls to template functions). In fact, templates are so powerful, they give rise to a completely new programming paradigm, template metaprogramming (TMP). Item 48 provides an overview of TMP, but unless you're a hard-core template junkie, you need not worry about it. The rules for TMP rarely interact with mainstream C++ programming.

  • The STL. The STL is a template library, of course, but it's a very special template library. Its conventions regarding containers, iterators, algorithms, and function objects mesh beautifully, but templates and libraries can be built around other ideas, too. The STL has particular ways of doing things, and when you're working with the STL, you need to be sure to follow its conventions.

like image 149
songyuanyao Avatar answered Oct 11 '22 11:10

songyuanyao


"Federation of languages" means the big breadth of diverse features and ways to apply the C++ language.

Multiparadigmatic languages combined paradigms. Examples are F-Sharp, OCaml and Swift. So it's a group of language-styles.

like image 36
Baum Avatar answered Oct 11 '22 12:10

Baum


Yes this is from Effective C++. The writer is just saying that C++ grammar comes from a series of sub-languages. Read about it here.

As for multi-paradigm programming, it's the ability of a language to support more than one programming style. This allows flexibility for different tasks. A google search should answer this for you.

like image 30
Claire Avatar answered Oct 11 '22 10:10

Claire