4 ms·
It seems to me that you could do almost everything you want (except for the immutable thing) in Free Pascal. Pascal doesn't have the kingdom of nouns problem.
by mikewarot 6y ago
It seems to me that you could do almost everything you want (except for the immutable thing) in Free Pascal.
Pascal doesn't have the kingdom of nouns problem. It supports good old fashioned procedures and functions.
Pascal can deal with nulls in strings, because we always know how long they are.
Or perhaps you meant null pointers. Pascal avoids unnecessary pointers, but supports them in a sane manner when you need them.
Pascal can deal with multiple inheritance in a sane manner, by composition. Objects can have other objects as properties, and it just works... no weird restructuring of everything horror stories I've heard about in C++, etc.
Free Pascal has generics there are libraries that let you do dictionaries and lists and trees of your type <T>.
I disagree about exceptions... proper handling of exceptions is a good thing. A function should always return the type you expect, not some weird value you have to test for.
As far as "pattern matching" I assumed you were talking about regex (which can be addressed in a library)... but you're talking about RTTI, or "reflection" where you can get type information at runtime, which is a thing in Pascal and many other languages.
I don't understand the obsession with immutable variables.
[Edit: I think I understand... in Pascal, parameters are passed by value as the default, but can be passed by reference, it depends on how you declare the function or procedure. It has nothing to do with variables that you can't assign new values to, if I'm correct]
Did I miss anything?
- mmazing 6y agoBut it's not a hot sexy * new * silver bullet for all of your problems.
- elteto 6y agoHave to disagree on exceptions. The return type is part of the function signature, it’s part of its contract. If a function can fail I want to see it right there on the return type and be forced to handle it on the spot. Exceptions are an invisible, out-of-band mechanism that will crash your program because you forgot yet another try...catch. Sum types with pattern matching are a much better approach for writing safe and robust code. The “proper handling of exceptions” panacea I keep hearing about sounds a lot like “OOP done right”... it’s supposed to exist, yet no one seems to know what it actually is.
- mikewarot 6y agoSo how do you want to handle something like sqrt(-1.0) for real numbers? A runtime exception seems the sane way to do it for me. Are you suggesting that sqrt(-1.0) or any other invalid value should return a sentinel value like -999, or should return NUL instead of a real? Any way of dealing with errors has to be out of band, we just disagree on the mechanism.
- qsort 6y agosqrt(-1.0) is NaN, it's typically used in numerical code where you can't stop and check for exceptions because performance is key. But just for the sake of argument, the type of 'sqrt' isn't: sqrt : R -> R it is: sqrt : R+ -> R+ So you have two options here. You can have sqrt return "Either Error Double" and force the programmer to deal with the possibility of an error (Rust does this) or you define a "nonnegative real" type that the compiler can guarantee will be an acceptable input for sqrt. The latter is much harder to do. But either way no, you only need an "out of band" mechanism when the type system isn't strong enough or isn't being properly leveraged.
- mikewarot 6y agoI used square root because it is commonly known that negative numbers are a problem for them. What about tangent(x) which periodically blows up? A type system can't fix that. In my opinion it is far better to throw an exception that can be explicitly handled, rather than cause some math error at some random point later because NaN or some infinity snuck by as a number.
- qsort 6y agoI'm not the author, but: > Or perhaps you meant null pointers. A major problem in languages like Java is that objects can always be null. A better solution would be to force strict null checks a la Typescript, where if you want to take or return an optionally null reference, you have to explicitly encode that property in the type of the variable. NullPointerExceptions are frankly a really stupid thing we have to deal with. A proper type system could check for that at compile time. > but you're talking about RTTI, or "reflection" OP is talking about ML-style type destructuring, which is kind of the opposite of this. > I don't understand the obsession with immutable variables. Mutating variables leads to all kinds of invisibile problems and makes the code a lot harder to reason on. When I write Java, most of my variables are final, the author is right that we should be taking the opposite convention a la Rust, variables should be immutable by default with mutability explicitly annotated.
- mikewarot 6y ago>Mutating variables leads to all kinds of invisibile problems and makes the code a lot harder to reason on. Am I correct in interpreting that as when you pass a variable to a function by reference it causes problems? Pascal defaults to passing them by value.
- qsort 6y agoSure, but passing by value isn't always realistic. If you have a hashtable with a million entries, you can't copy it just to update a value. There's also the problem of internal mutation of state, with hashtables/collections being again primary examples. It's not always avoidable to have internal mutation, but it shouldn't be the default, in most cases it's just wrong.
- mikewarot 6y agoThat's a weird corner case... I wouldn't expect the compiler to keep me from shooting myself in the foot like that. I'm surprised that some people do expect it.