3 ms·
Also, the following part isn't necessarily because of dynamic typing vs static > what types all the variables are, what expectations are attached to them, what
by capableweb 7y ago
Also, the following part isn't necessarily because of dynamic typing vs static
> what types all the variables are, what expectations are attached to them, what mutation, if any, each method call performs
But more about what the language offers. Clojure for example, goes beyond types with it's abstractions (like seq, that can be applied to strings, lists, maps and so on) and normally stays away from mutation, but when needed, makes it really explicit and easy to find those mutations.
- pron 7y agoJava's JML contract system [1] allows you to explicitly state which mutations a method performs as part of its contract. [1]: https://www.openjml.org/ https://www.openjml.org/
- yakshaving_jgt 7y ago> Clojure for example, goes beyond types with it's abstractions (like seq, that can be applied to strings, lists, maps and so on) Goes beyond types? Statically-typed languages can have polymorphism.
- roenxi 7y agoSpec is at heart a data modelling system. So for example, (s/def ::integer integer?) is very explicitly not a definition of an "integer" type. It is preparation to model some data x and check that the data will evaluate to true if someone uses the predicate (integer? x). However, this is obviously enough to implement a type system. But you can also do some very loose things with spec that aren't done in a type system (I speak with a cheerful ignorance of type systems). Eg, I can spec a function so that one argument is smaller than the second. This allows my testing system to automatically generate the correct data to test my function. So spec can used to implement a type system but also to implement things that aren't type systems.
- candeira 7y ago> But you can also do some very loose things with spec that aren't done in a type system (I speak with a cheerful ignorance of type systems). Eg, I can spec a function so that one argument is smaller than the second. This allows my testing system to automatically generate the correct data to test my function. Check out dependent type systems. These allow you to define, mindbreakingly enough, types that __depend on the values you assign at runtime__, and functions whose type depends on the values passed as arguments. Don't ask me how it's done; it's all dark magic to me. All I know is that people who use dependent type systems claim they are very good at certain uses involving incoming streams of unknown data, like parsing binary protocols. https://en.wikipedia.org/wiki/Dependent_type https://en.wikipedia.org/wiki/Dependent_type
- fanf2 7y agoWhy is seq “beyond types”? Isn’t it like a Rust Iterator trait?
- hopia 7y agoWhat do you mean with going beyond types? Is it possible to define some unique compile time constraints on Clojure not related to the type system?
- dllthomas 7y agoWhen spec was proposed I remember some talk of compile-time checking of some annotations. I don't know whether anything came of that, but in theory it would allow what you're talking about. That has no relation to seq, though, which is the kind of thing supported by many statically typed languages.
- leshow 7y agoCommented elsewhere here but static languages can do this also via ad hoc polymorphism or bounded polymorphism.