6 ms·
Can’t speak about Object Pascal, but the old Pascal was objectively better than C. You can like or dislike the differences in syntax, but Pascal’s type system w
by whobre 3y ago
Can’t speak about Object Pascal, but the old Pascal was objectively better than C. You can like or dislike the differences in syntax, but Pascal’s type system was pretty solid which can’t be said about C
- bigbillheck 3y agoThe way I remember the pascal type system is arrays of different lengths were different types.
- filmor 3y agoThey are pretty much everywhere when statically allocated.
- zabzonk 3y agowell, not in c.
- Kamq 3y agoI believe they are in C, but arrays degrade to pointers when you look at them wrong, and _those_ don't have length as part of their type. At least I'm seeing: `array type 'int[3]'` in messages when I tried to do something wrong with it quick to get an error message (using llvm), maybe that's a compiler specific thing.
- zabzonk 3y ago> when you look at them wrong no, almost whenever you look at them. it is very hard to carry around the size of an array in C. > At least I'm seeing: `array type 'int[3]'` in messages when I tried to do something wrong with it quick to get an error message (using llvm), maybe that's a compiler specific thing. post some code that illustrates what you are talking about
- Kamq 3y agoI was trying to get clang to throw an error that included type information to double check what it thought the type was. Quickest thing I could think of was trying to assign to an array. The exact error in question was: error: array type 'int[3]' is not assignable Which seems to imply that clang is considering the length to be part of the type. edit: You asked for code (my apologies that it's rather trivial). int x[3] = {1, 2, 3}; int y[3]; y = x;
- filmor 3y agoEven in C, citing the standard (6.2.4, 20): > Array types are characterized by their element type and by the number of elements in the array.
- fuzztester 3y agoThere's more to it than that. You could (from early Pascal days) and can have arrays where the array index range is a previously defined subrange of integers, or maybe even of an enumerated type. Then you have sets as a built-in type, which is big. Some more.
- AnimalMuppet 3y agoIn the original Pascal, that was true. The standard (and, I think, Jensen & Wirth) were that way. And it was a fatal flaw. I had a program that I took over that did a numerical simulation on a 2D grid with user-specified size. The original author simulated that 2D grid with a 1D doubly-linked list. As you might expect, this was both slow and error-prone. But he did it because there was no possible type that you could give to a user-sized array. There was literally no way to talk about such a thing. We eventually "fixed" it by allocating the largest 2D array possible within our memory limitations, and using only the user-specified part of it. Most "real" Pascals (Turbo Pascal, but others that were intended to be used in the real world, not just in the classroom) developed some way to give a type to a variable-length array (and also to do a C-ish cast). Unfortunately they all did it in different ways, so there was no code portability between compilers if your code needed such things. So, yeah, "objectively better than C" is quite a stretch, even just in the type system.
- pmelendez 3y ago> but Pascal’s type system was pretty solid To be honest, this is a matter of styles, coming from a dynamic type background I don’t appreciate strongly typed systems as an advantage.
- Jtsummers 3y agoStrongly typed is orthogonal to dynamic and static typing. Python and Common Lisp are both "strongly" typed and dynamically typed. There's no reason to shun strong typing if you also like dynamic typing.
- pmelendez 3y agoI would be curious to see references that claims that dynamic and static typing are orthogonal with strongly typed systems, as “strongly type” is rather ambiguous and the only reason I used the term was because that was how Pascal was promoted back in the day (or at least how was taught to me) From Wikipedia: In 1974, Liskov and S. Zilles defined a strongly-typed language as one in which "whenever an object is passed from a calling function to a called function, its type must be compatible with the type declared in the called function." Note that the definition refers to type declaration, both being optional in Python and Common Lisp, so I wouldn’t use either as an example of strongly type languages.
- Jtsummers 3y agoYou already found the wikipedia page, try reading it. See where it puts a lot of dynamically typed languages under the category of "strongly typed". You've decided it's a good enough source apparently. But really, I used "strongly" in quotes deliberately. It's a terrible phrase since it means nothing in practice because it can mean too many things (as that same page notes) that often are at odds with each other. > Note that the definition refers to type declaration, both being optional in Python and Common Lisp, so I wouldn’t use either as an example of strongly type languages. Even this definition would potentially exclude SML and OCaml where types are inferred, not declared. So according to you those two languages are weakly typed? I think a lot of people would be surprised to learn that.
- drpixie 3y agoStrong agree. I used the old Turbo Pascal for many years. It was quite routine to produce substantial programs where the compiler (and type system) had caught ALL the bugs. Meaning: you used sensible types (and had sensible libraries) and once the obvious compile-time errors were fixed, there would be zero bugs found in testing or in live! I like the flexibility of python, but I know that every substantial program has untested pathways that will fail when they come to be exercised :(