J
jacob navia
We had another thread discussing the criticisms to C in a
wikipedia article. No one from this group really addressed
those criticisms besides the usual "nonsense" and similar
contributions.
With this post I want to go a bit deeper into those, at least
address them individually.
-------------------------------------------------------------------
The mentioned wiki article mentions following criticism to the C
language:
1: No assignment of arrays or strings (copying can be done via standard
functions; assignment of objects having struct or union type is supported)
This is a justified criticism. The basic problem is the C handling of
arrays, that makes very difficult to work with those arrays in a
rational manner.
Suggested solution:
Within the context of lcc-win, I have proposed to overload operators,
what makes it possible to use arrays with automatic bounds checking,
supporting assignment and many other normal features.
The solution is the same for strings since strings are just special
cases of arrays.
From a language point of view (consistency) there is absolutely no
reason to make this distinction between arrays and structures. The
standard answer is:
"If you want to assign an array to another put it into a structure"
typedef struct tag S{ int array[512]; } MyArray;
Then you can do
My array a,b;
....//
a = b;
Why must be done that way? There is no justification to that.
-----
-----
2: No requirement for bounds checking of arrays
See above. The same solution (operator overloading of the indexing
operator) is proposed for arrays and strings.
The proposed solution allows also a normal handling of arrays as
first class objects without any "decay" nonsense.
-----
-----
3: No syntax for ranges, such as the A..B notation used in several
languages
This is not justified. Many languages exist where ranges aren't
supported. This is, in any case, a minor problem if at all.
-----
-----
4: No separate Boolean type: zero/nonzero is used instead.
This has been fixed with the C99 standard. The article complains that
it hasn't been "retrofitted" but that is quite impossible IMHO.
-----
-----
5: No nested function definitions.
I do not see why this is a problem. Even if some C dialects support this
feature (the GNU compiler) it doesn't solve any existing problem.
-----
-----
6: No formal closures or functions as parameters (only function and
variable pointers)
Closures would complexify the language. If needed, it can be
simulated with a structure containing the state variables you want to
capture from the environment, and a function pointer.
-----
-----
7: No generators or coroutines; intra-thread control flow consists of
nested function calls, except for the use of the longjmp or setcontext
library functions
This is not needed. Coroutines can be programmed in C, but there is no
language support
-----
-----
8: No exception handling; standard library functions signify error
conditions with the global errno variable and/or special return values
This is a correct critique. Structured exception handling is necessary
in most environments.
Lcc-win supports __try/__except in the same manner as the Microsofts
constructs. Maybe there will be standard support for a form of
exception handling since the committee started studying the Microsoft
extensions.
-----
-----
9: Only rudimentary support for modular programming
This is too harsh. The support in the form of file delimited modules is
enough. Other solutions (line namespaces) complexify the language
and have conceptual problems
-----
-----
10: No compile-time polymorphism in the form of function or operator
overloading
This is a justified criticism, that lcc-win addresses by providing
overloaded (polymorphic) functions and operator overloading.
-----
-----
11: Only rudimentary support for generic programming
Lcc-win tries to address this with overloaded functions and operator
overloading. See above.
-----
-----
12:No direct support for object-oriented programming with regard to
polymorphism or inheritance, although a limited form of these may be
achieved with type punning.
C is not object oriented. There is NO NEED for yet another OO
language, but THERE IS A NEED for a NON OO language.
-----
-----
13: Limited support for encapsulation.
The support is enough. Module separation is one, and the abstract data
type ( struct foo
is another. Both are sufficient.
-----
-----
14: No native support for multithreading and networking
This is ridiculous. Most networking libraries are in C! Multithreading
support would be a mistake, since threads are a mistake.
-----
-----
15: No standard libraries for graphics and several other application
programming needs.
This is ridiculous. Who needs "standard graphics libraries" ?
There are many standards, and all are accessible by C programs.
wikipedia article. No one from this group really addressed
those criticisms besides the usual "nonsense" and similar
contributions.
With this post I want to go a bit deeper into those, at least
address them individually.
-------------------------------------------------------------------
The mentioned wiki article mentions following criticism to the C
language:
1: No assignment of arrays or strings (copying can be done via standard
functions; assignment of objects having struct or union type is supported)
This is a justified criticism. The basic problem is the C handling of
arrays, that makes very difficult to work with those arrays in a
rational manner.
Suggested solution:
Within the context of lcc-win, I have proposed to overload operators,
what makes it possible to use arrays with automatic bounds checking,
supporting assignment and many other normal features.
The solution is the same for strings since strings are just special
cases of arrays.
From a language point of view (consistency) there is absolutely no
reason to make this distinction between arrays and structures. The
standard answer is:
"If you want to assign an array to another put it into a structure"
typedef struct tag S{ int array[512]; } MyArray;
Then you can do
My array a,b;
....//
a = b;
Why must be done that way? There is no justification to that.
-----
-----
2: No requirement for bounds checking of arrays
See above. The same solution (operator overloading of the indexing
operator) is proposed for arrays and strings.
The proposed solution allows also a normal handling of arrays as
first class objects without any "decay" nonsense.
-----
-----
3: No syntax for ranges, such as the A..B notation used in several
languages
This is not justified. Many languages exist where ranges aren't
supported. This is, in any case, a minor problem if at all.
-----
-----
4: No separate Boolean type: zero/nonzero is used instead.
This has been fixed with the C99 standard. The article complains that
it hasn't been "retrofitted" but that is quite impossible IMHO.
-----
-----
5: No nested function definitions.
I do not see why this is a problem. Even if some C dialects support this
feature (the GNU compiler) it doesn't solve any existing problem.
-----
-----
6: No formal closures or functions as parameters (only function and
variable pointers)
Closures would complexify the language. If needed, it can be
simulated with a structure containing the state variables you want to
capture from the environment, and a function pointer.
-----
-----
7: No generators or coroutines; intra-thread control flow consists of
nested function calls, except for the use of the longjmp or setcontext
library functions
This is not needed. Coroutines can be programmed in C, but there is no
language support
-----
-----
8: No exception handling; standard library functions signify error
conditions with the global errno variable and/or special return values
This is a correct critique. Structured exception handling is necessary
in most environments.
Lcc-win supports __try/__except in the same manner as the Microsofts
constructs. Maybe there will be standard support for a form of
exception handling since the committee started studying the Microsoft
extensions.
-----
-----
9: Only rudimentary support for modular programming
This is too harsh. The support in the form of file delimited modules is
enough. Other solutions (line namespaces) complexify the language
and have conceptual problems
-----
-----
10: No compile-time polymorphism in the form of function or operator
overloading
This is a justified criticism, that lcc-win addresses by providing
overloaded (polymorphic) functions and operator overloading.
-----
-----
11: Only rudimentary support for generic programming
Lcc-win tries to address this with overloaded functions and operator
overloading. See above.
-----
-----
12:No direct support for object-oriented programming with regard to
polymorphism or inheritance, although a limited form of these may be
achieved with type punning.
C is not object oriented. There is NO NEED for yet another OO
language, but THERE IS A NEED for a NON OO language.
-----
-----
13: Limited support for encapsulation.
The support is enough. Module separation is one, and the abstract data
type ( struct foo
-----
-----
14: No native support for multithreading and networking
This is ridiculous. Most networking libraries are in C! Multithreading
support would be a mistake, since threads are a mistake.
-----
-----
15: No standard libraries for graphics and several other application
programming needs.
This is ridiculous. Who needs "standard graphics libraries" ?
There are many standards, and all are accessible by C programs.