Re: C++0x - a quick and dirty introduction (as of November 2007)
Gabriel Dos Reis wrote:
On Wed, 19 Dec 2007, Walter Bright wrote:
| 2) I very much like to be able to look at initializations and see if they will
| be done at compile time or runtime without having to poke through (potentially
| voluminous) headers.
I understand your like, but that hardly qualifies as an argument to
deam something `an obsolete feature'.
While I phrased it badly, this is a problem with the auditability of C++
code. Auditability is the ability of code reviewers to examine the code
and check it for correctness. Seeing a local static initialization and
knowing if it is thread safe or not is a very difficult task. The
reviewer would probably have to resort to looking at a disassembly of
the code.
There are many aspects of C++ that impair auditability, which is why the
following are growth industries:
1) proliferation of compiler warnings
2) lint
3) coverity
4) coding standards documents
These things are rich sources of inspiration for how to improve the core
language. Here's one example: in one C++ coding standards spec, the use
of the integer literal postfix 'l' was proscribed because in many fonts
101 and 10l are indistinguishable. Therefore, in the D programming
language, 'l' is not a valid suffix (use 'L' instead). A simple change
to the language, and there's no longer an issue - one doesn't have to
put it in a coding standard, yell at your employees to stop using 'l',
hack it into a lint program, etc. The problem is just defined out of
existence.
| 3) Dynamic initialization of local statics introduces multithreading issues.
| This can be dealt with by the compiler always using a mutex, which introduces
| bloat all over the place, or optional mutexes with a compiler switch leading
| to bloat or overlooked bugs, or using a simple static one-shot which suffers
| from race conditions that aren't at all obvious from code inspection.
Is there evidence that letting all programmers systematically dealing
with that task lead to more correct, more maintainable code?
As I understand it, C++ programmers have the choice of using OR not
using dynamic initialization of local statics.
Right, and I never use it. The underlying issue is being able to tell if
it was happening or not, just like the ROMable issue for global statics.
Then, if it is happening, is it thread-safe.
Sure, such can possibly be avoided with coding conventions. But learning
C++ seems to occur in two phases - 1) learn the language, then, 2) learn
all the conventions that have evolved over time to head off disastrous
problems.
----
Walter Bright
http://www.digitalmars.com C, C++, D programming language compilers
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]