Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!att!ulysses!andante!alice!bs From: bs@alice.UUCP (Bjarne Stroustrup) Newsgroups: comp.lang.c++ Subject: Re: C++ design Summary: complexity, etc. Keywords: information Message-ID: <9476@alice.UUCP> Date: 13 Jun 89 19:42:07 GMT References: <9474@alice.UUCP> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 103 C++ is designed to cater for a wider range of programming styles, a wider range of applications, running on a wider range of systems, and under a stricter set of efficiency requirements than is most other higher-level languages. The complexity of C++ reflects this range of uses and requirements. Given this, estimates of C++'s complexity is often greatly inflated. Any language/system that tries to cover the ground C++ covers will approximate C++ in complexity. Any that doesn't will leave you to write many programs and large parts of systems in other languages. For example, if there is a problem with efficiency (run-time or space) or if the language require a certain class of machine you will end up writing in C, assembler, Fortran, etc. It seems trivial to improve C++ by reducing its size by 20%, but I have never met two people who could agree on exactly which 20%. It would be trivial to design a syntax for C++ that was noticeably easier to parse, but we would also have a major conversion and education problem on our hands (and I'd probably get tarred and feathered by irate C programmers). I consider the type system of C++ far more important than the grammar (and similarly for any other language). The class specific parts of the C++ syntax is clean and the grammar complexity is primarily a problems for implementors; not users. Much of the complexity in C++ is inherited (sic) from C. I consider it worthwhile to keep this complexity in the language to ease the transition to C++ from traditional languages, to allow re-use of C libraries and tools, and to guarantee that no feature that is essential to get work done in C was left out in C++ due to ignorance or misguided paternalism on my part. Whatever the complexity/simplicity of C++ is, it has been sufficient for tens of thousands of programmers to learn C++ well enough to get their jobs done despite the relative lack of educational material, support, and C++ specific expertise. The first two of these problems have been largely remedied now, the third will remain until C++'s growth rate decreases from exponential. There are several sources of C++ implementations. If you don't trust commercial sources, you can try GNU; if you don't trust GNU, you can try commercial sources; if you don't really trust either you can hope that the many sources will keep each other honest. For libraries, tools, and environments there are additional academic sources. C++ is designed as a traditional programming language in the sense that there is a clear distinction between the language itself, the system in which it runs, and the tools used to create programs. This has the benefit that you get a choice of programming development style, a choice of system interfaces and libraries. In particular, it allows a very low minimum of systems size and run-time support size. The snag is that one cannot expect `one standard system' common to all users. My opinion is that the world is far too large for that to happen anyway (for any successful general-purpose language). We will, however, see national-, regional-, corporate-, industry-, etc. wide standards and we have the beginnings of a C++ tools and libraries industry. C++ as a plain language delivers only a fraction of the benefits of a complete C++ environment and a complete set of libraries. That was clearly understood from the beginning. Even in standard environments such as UNIX, MS/DOS, VMS, etc. C++ provides benefits over more traditional language for a wide range of projects. More specialized and supportive programming environments are now becomming available starting with ParcPlace's Cynergy. An important aspect of C++ is its ability to be used in a mixed language environment. Not only can C++ functions call C, Fortran, etc. functions without overhead; the opposite is also the case. Pointers to C++ object can where necessary be passed to and used directly from functions written in other languages. Similarly, C++ can handle data layouts from other languages in the same way C can. This makes co-existence of C++ and other languages relatively easy, allows C++ to be used to build libraries for other languages, and allows a gradual introduction of C++ into an organization. C++ follows the C tradition in trusting the programmer and in not attempting to force one specific programming style or design method on people. C++ provides much stronger static checking than does C and allowes a far greater range of ideas to be expressed directly in the language - thus making them ameanable to checking and manipulation by tools - than does C (and most other traditional languages for that matter). However, these (user-imposed) rules can always (explicitly) be broken when necessary. The importance of this is an absense of arbitrary and absolute limits. There is a wide variety of programming styles and design approaches that each are valid in particular environments (if not necessarily universally). There are support for several in C++. The freedom for programmers and designers this implies is of course a source of complexity. In my view that complexity is necessary and a sign of maturity. Had the language contained support for only a single style then programmers who (often for good reasons) wanted to use another would have been left without any help from the language and its type system; or worse been left with a set of language features that was explicitly designed to prevent the supposed misuses. I feel that a calm, levelheaded, and often slow approach is needed to get data abstraction, object-oriented programming, etc. and their associated design approaches into widespread use. Requiring an almost religious conversion and a total change of work style of all users is not acceptable to most organizations. C++'s support of a range of style within a single type system and syntax is important for this transition.