Limitations and Evolution
Limitations and Evolution
Posted Apr 4, 2006 9:06 UTC (Tue) by eru (subscriber, #2753)In reply to: Limitations and Evolution by AnswerGuy
Parent article: Coverity: one bug fixed every six minutes
For example C would benefit from much more extensive use of assertions ... and some language features to support static and stochastic simulation tests which incorporate those assertions --- and some features for PBC (programming by contract) --- (ultimately three specific forms of assertions: pre-conditions, invariants and post conditions).
IMHO C would benefit most from some minor language changes that would remove the most commonly recurring idiotic mistakes at the time the code is first compiled! At the top of my list would be:
- Introduce a proper Boolean type distinct from integers, make comparisons return it, and all conditional control structures require it. This gets rid of most "=" vs "==" errors. The rest would go away by making it an error if the return value of operator "==" is unused.
- Enforce separation of pointers from integers better. Don't allow bare 0 as a NULL pointer constant.
- Disallow calling extern functions without the presence of a prototype.
- Introduce separate keywords for breaking loops and breaking from switch branches. (There actually was a widespread phone servide outage in the USA about a decade ago that would not have happened if C had had this feature...)
- Require fall-through in switches to be explicitly indicated by a new keyword (this would naturally apply only to non-empty branches, so "case 1: case 2: case 3: ..." would be unaffected).
- Make it an error if there is a code path through which a non-void function might return without specifying a return value.
These changes would greatly reduce C bugs without affecting efficiency at all, or make programs any more verbose. Of course existing programs would need modifications, but these could be largely automated.
