C faults, etc
bearophile
bearophileHUGS at lycos.com
Mon Jul 20 03:15:00 PDT 2009
There's a long thread on reddit about the faults of C language:
http://www.reddit.com/r/programming/comments/92l8w/in_your_opinions_what_is_wrong_with_the_c/
Some comments derived from it:
D already fixes/pathes several problems of C, but not all of them. One of the problems is the pointer syntax and the problem coming from its operator precedence. Pascal pointer syntax is a bit better. The famous "C++ resyntaxed" shows a quite better pointer syntax. I'd like to see a better and less bug-prone pointer syntax in D, but it's hard to change it and keep almost-source-compatibility with C at the same time.
------------
Lint-like programs like Splint (http://www.splint.org ) help avoid some of the problems of C, but from experience I can see people don't use such programs. So D has to contain some of the things done by a lint. One of the important things is a way to add some more semantics to programs, for example to say if two pointers/slices/arrays are surely distinct, and many other things. (So far I have not understood the D stance regarding pointer aliasing).
------------
D has now two switch, both of them faulty. This looks worse than the C situation. I can't appreciate this situation.
------------
C comma operator is bad. Python shows a WAY better way to use commas, but if D wants to keep its almost-source-compatibility with C then Python syntax may be hard to be added. A partial solution I see is just to turn some usages of the comma operator into a compilation error, just like in D it's an error legal C syntax like:
int *i, j;
------------
Java shows that undefined behaviour can be avoided with an acceptable cost in performance. So D eventually has to remove all situations where it acts in an undefined way. Where it's really needed some non-standard way to do things can be added. Better to have nonportable things than undefiend things.
------------
writefln, writeln and the things of Tango are nice and cute and safe, but if I have to save 250 MB of numbers (or 1 GB of them, or even more) then performance is important, and those cute functions are 2-3-5 times slower than printf. This means printf can save me minutes of running time. So I use printf. But if I use printf in C and I write:
int main() {
float f = 1.2345;
printf("%d\n", f);
return 0;
}
The compiler says me:
warning: format '%d' expects type 'int', but argument 2 has type 'double'
While DMD compiles it silently. Better to quickly add such warning/error to D compilers too.
Bye,
bearophile
More information about the Digitalmars-d
mailing list