Sponsored Links
-->

Wednesday, July 25, 2018

To Avoid Criticism Say Nothing - Ancient Greek Philosopher ...
src: previews.123rf.com

C++ is a general-purpose programming language with imperative, object-oriented and generic programming features. Many criticisms have been leveled at the programming language from, among others, prominent software developers like Linus Torvalds, Richard Stallman, Joshua Bloch, Ken Thompson, and Donald Knuth.

C++ is a multiparadigm programming language with extensive but not complete backward compatibility with the programming language C. This article focuses not on C features like pointer arithmetic, operator precedence or preprocessor macros, but on pure C++ features that are often criticized.


Video Criticism of C++



Slow compile times

The natural interface between source files in C/C++ are header files. Each time a header file is modified, all source files that include the header file should recompile their code. Header files are slow because they are textual and context-dependent as a consequence of the preprocessor. C only has limited amounts of information in header files, the most important being struct declarations and function prototypes. C++ stores its classes in header files and they are not only exposing their public variables and public functions (like C with its structs and function prototypes) but also their private functions. This forces unnecessary recompiles of all source files that include the header file, each time when changing these private functions. This problem is magnified where the classes are written as templates, forcing all of their code into the slow header files, which is the case with the whole C++ standard library. Large C++ projects can therefore be relatively slow to compile. The problem is largely solved by precompiled header in modern compilers.

One solution for this is to use the Pimpl idiom. By using pointers on the stack to the implementation object on the heap there is a higher chance all object sizes on the stack become equal. This of course comes with the cost of an unnecessary heap allocation for each object. Additionally precompiled headers can be used for header files that are fairly static.

One suggested solution is to use a module system.


Maps Criticism of C++



Global format state of <iostream>

C++ <iostream> unlike C <stdio.h> relies on a global format state. This fits very poorly together with exceptions, when a function must interrupt the control flow, after an error, but before resetting the global format state. One fix for this is to use Resource Acquisition Is Initialization (RAII) which is implemented in Boost but is not a part of the C++ Standard Library.

The global state of <iostream> uses static constructors which causes overhead. Another source of bad performance is the use of std::endl instead of '\n' when doing output, because of it calling flush as a side effect. C++ <iostream> is by default synchronized with <stdio.h> which can cause performance problems. Shutting it off can improve performance but forces giving up thread safety.

Here follows an example where an exception interrupts the function before std::cout can be restored from hexadecimal to decimal. The error number in the catch statement will be written out in hexadecimal which probably isn't what one wants:

It is acknowledged even by some members of the C++ standards body that the iostreams interface is an aging interface that needs to be replaced eventually. This design forces the library implementers to adopt solutions that impact performance greatly.


Robert C. Evans, Annotated Critical Edition of
src: www.ambrosebierce.org


Heap allocations in containers

After the inclusion of the STL in C++, its templated containers were promoted while the traditional C arrays were strongly discouraged. One important feature of containers like std::string and std::vector is them having their memory on the heap instead of on the stack like C arrays. To stop them from allocating on the heap, one would be forced to write a custom allocator, which isn't standard. Heap allocation is slower than stack allocation which makes claims about the classical C++ containers being "just as fast" as C arrays somewhat untrue. They are just as fast to use, but not to construct. One way to solve this problem was to introduce stack allocated containers like boost::array or std::array.

As for strings there is the possibility to use SSO (short string optimization) where only strings exceeding a certain size are allocated on the heap. There is however no standard way in C++ for the user to decide this SSO limit and it remains hard coded and implementation specific.


CRITICAL OPS - MELHOR HACKER DO MUNDO MULTI-HACK C-OPS 😱 - YouTube
src: i.ytimg.com


Iterators

The philosophy of the Standard Template Library (STL) embedded in the C++ Standard Library is to use generic algorithms in the form of templates using iterators. Early compilers optimized small objects such as iterators poorly, which Alexander Stepanov characterized as the "abstraction penalty", although modern compilers optimize away such small abstractions well. The interface using pairs of iterators to denote ranges of elements has also been criticized, and ranges have been proposed for the C++ standard library.

One big problem is that iterators often deal with heap allocated data in the C++ containers and become invalid if the data is independently moved by the containers. Functions that change the size of the container often invalidate all iterators pointing to it, creating dangerous cases of undefined behavior. Here is an example where the iterators in the for loop get invalidated because of the std::string container changing its size on the heap:


Robert C. Evans, Annotated Critical Edition of
src: www.ambrosebierce.org


Uniform initialization syntax

The C++11 uniform initialization syntax and std::initializer_list share the same syntax which are triggered differently depending on the internal workings of the classes. If there is a std::initializer_list constructor then this is called. Otherwise the normal constructors are called with the uniform initialization syntax. This can be confusing for beginners and experts alike


No Concept (Prod. By Sadik Beats) | Critical C
src: f4.bcbits.com


Exceptions

There have been concerns that the zero-overhead principle isn't compatible with exceptions. Most modern implementations have a zero performance overhead when exceptions are enabled but not used, but do have an overhead during exception handling and in binary size due to the need to unroll tables. Many compilers support disabling exceptions from the language to save the binary overhead. Exceptions have also been criticized for being unsafe for state-handling, this safety issue has led to the invention of the RAII idiom, which has proven useful beyond making C++ exceptions safe.


Virginia C. Andrews Quote: “Maybe thats because we take criticism ...
src: quotefancy.com


Strings without Unicode

The C++ Standard Library offers no real support for Unicode. std::basic_string::length will only return the underlying array length which is acceptable when using ASCII or UTF-32 but not when using variable length encodings like UTF-8 or UTF-16. In these encodings, array length is neither a correct measure of the number of code points, number of characters or width. There is no support for advanced Unicode concepts like normalization, surrogate pairs, bidi or conversion between encodings, although unicode libraries exist to handle these issues, such as iconv and ICU.

The example below prints the lengths of two equally long strings. The strings are equally long in characters, but the program takes their lengths in bytes. If the program's source code is saved in a constant width character set like ISO-8859-1, both strings come out as 18 bytes, but in UTF-8, the first string becomes either 22 or 26 bytes depending on unicode normalization.


To Avoid Criticism Say Nothing - Ancient Greek Philosopher ...
src: previews.123rf.com


Code bloat

Some older implementations of C++ have been accused of generating code bloat.


marxist criticism essay robert c evans annotated critical edition ...
src: www.ambrosebierce.org


See also


Virginia C. Andrews Quote: “Maybe thats because we take criticism ...
src: quotefancy.com


References

Works cited

  • Stroustrup, Bjarne (1994). The Design and Evolution of C++. Addison-Wesley. ISBN 0-201-54330-3. 

Robert C. Evans, Annotated Critical Edition of
src: www.ambrosebierce.org


Further reading


Robert C. Evans, Annotated Critical Edition of
src: www.ambrosebierce.org


External links

  • C++ FQA Lite by Yossi Kreinin
  • C++ The COBOL of the 90s
  • C++ in Coders at Work Excerpts from the book Coders at Work, by Peter Seibel
  • DConf 2014: The Last Thing D Needs A video of a talk by Scott Meyers

Source of article : Wikipedia