3 ms·
The article tries to make its point with unnecessarily complex code examples. They seem to be locked in a C way of thinking. But Pascal was created about the sa
by _ph_ 11y ago
The article tries to make its point with unnecessarily complex code examples. They seem to be locked in a C way of thinking. But Pascal was created about the same as C and had proper types.
Strings could be represented as length checked arrays. They could come in two types, short ones, having a length byte at the beginning and are limited to 256 elements, and long ones, having an "int" size marker and corresponding length limits. The type handling could be handled by the compiler, the length() function would always return an int, and the elements addressed by a[i]. Thats it. This would have saved us more than 3 decades of nasty bugs if not security problems.
- cefstat 11y ago> But Pascal was created about the same as C and had proper types. The Pascal I remember (some version of Turbo Pascal in the early 90s) had strings where you had to declare the length as part of the type. Strings of different length had different types and you could not pass a string of length 30 to a procedure that expected a string of length 31. The way to solve this is to declare that all your strings had the same length and hope that it would be enough. It was horrible and at the time I found the C approach much more reasonable. Of course Pascal improved through the years and the C approach turned out to be a huge security problem.
- valarauca1 11y agoPascal strings are weird. The first byte tells you the string's length. If the MSB of the first bit is set, the string's first 4 bytes tell you the length of the string. I mean yes its not a horrible system, but there are better systems. I'll be honest I like Rust's. Just keep the length and the pointer on the stack in a tuple.
- _ph_ 11y agoI didn't meant to say that Pascal hat the perfect solution, but that with that times technology, better solutions than the C one were possible, and more so with any language more modern than ancient Pascal.
- pjmlp 11y agoISO Extended Pascal and other Pascal dialects had open arrays. Algol and Mesa were two other languages that you could generalize over array size. For anyone interested in systems programming it is a good eye opener to delve into the system programming languages from 60 and 70's, before C escaped UNIX.