bob wrote:
Remember that C was never intended to be a tightly-defined idiot-proof language. It was designed to let you write portable code, while getting as "close" to the hardware as you wanted to get to obtain max performance and flexibility. No one would begin to claim that assembly language has any useful type-checking or constraints, and C was designed to eliminate the assembly language itself, without hurting the performance you could expect. The older "register" declaration is a good example of how close to assembly it would let you get.
I know that and I agree with most of that.
I do take exception that they couldn't have added a little safety. Even asm macro languages can have some safety to keep you from making mistakes. Like trying to transfer a FPU register to a cpu register. Or trying to treat an address register like an ALU register. Or...
I also have to take exception about it being designed for portability. The original C was nearly antithetic for portability. It went out of its way to be very PDP'ish. It wasn't designed 'on' the PDP, but *for* the PDP.
It took a lot of effort in the K&R era to reach tolerable portability levels. In both the language and the library. And it took 10 years for the first C standard to work out enough of the flaws in k&r to make it into a somewhat portable language. Even function prototypes was a radical idea!
C was designed to let the user do nearly anything they wanted with no concern for whether it was *right*. That's a very poor design goal.
Over the years, C has added some safety, but very little. And along with that, they've even abstracted some stuff, in the name of portability. It's permissible for the compiler writer to actually hide some of the CPU stuff. (Think NULL is always zero. Nope. It can be anything. But it has to behave *exactly* as if it was, including transparent conversion when you use it or try to check its real value.)
I hated Pascal. I know what I want to do when programming, and I don't want the compiler to get in the way and make me jump through hoop after hoop. Writing a compiler in Pascal was a syntactical challenge. Writing one in even Fortran was much more pleasant, and in C it was a wonderful project for students.
I agree the classic versions of Pascal (like you used) are a PITA to use.
That Pascal should never have been developed.
Years ago I tried using an ISO version of Pascal. (shudder!) That was even worse than the original.
(Just look at all the hoops that Larry Atkin had to jump through to write Chess 0.5 That's an excellent example of how bad the Pascal language used to be.)
Fortunately, modern versions (started with TurboPascal) have left much of that idioticy behind. Not all, but much of it.
There are still types and you can't blindly (or accidently) confuse a char and an integer unless you choose to. If you want a small integer, then you *say* you want a small integer and not a text character.
If you say a var is going to represent a color, you aren't going to be able to accidently put a piece type in there.
You can still do what you want, with the compiler catching mistakes. Like this C code:
#define WHITE 1
#define PAWN 1
int SideBasedVar[...]; /* White / Black */
func() { if (SideBasedVar[PAWN]) .... }
Pascal, then and now, does require you to think a bit differently.
That's part of the point and the problem. After years of C programming, it is *hard* to think logically and properly and not like C's "Everything is an int" attitude.
You can write proper code in C, but it doesn't encourage it and it wont notice if you don't. It even encourages you to not write properly.
That's why I said I've been brain damaged by C.
In the old days, I could write Pascal code pretty well. It all made sense and I thought that way and writing was easy. I didn't have to jump through hoops or struggle with the compiler to let me do something. (My first Pascal compiler was slightly more advanced than the classic ones. It had relaxed type checking like what is common these days.)
After 20+ years of C programming though, Pascal is no longer easy for me. I've been brain damaged.