6 ms·
I find static typing is extremely useful in the case where you're receiving JSON though - I write the server side and we use Scala. For us we write the type we
by mcintyre1994 8y ago
I find static typing is extremely useful in the case where you're receiving JSON though - I write the server side and we use Scala. For us we write the type we expect, validate the input as soon as it hits the server (in the controller), fail immediately if it doesn't validate and if it does validate then we're dealing with that type in all the rest of the code. Obviously that's not going to handle receiving a shape of data that you don't expect, but you'll error immediately and I find it really robust in practice.
- fulafel 8y agoDynamic languages do this with schema validation. It can be more expressive, checking value ranges or string formats, multi field conditional constraints, and so on. And allows better& customizable diagnostics. Edit: also, versioning, cross language sharing, use in generative testing, api client code generation and other metaprogramming uses. And documentation generation, eg swagger
- guitarbill 8y agoSee e.g. JSON schema, which has a wide language support and tooling (even some IDEs support it for validation while you're writing a compliant document)
- roca 8y agoand once you've validated a value your code immediately forgets what type it is.
- fulafel 8y agoBeware of confusing dynamic typing with weak typing :) If you are using eg Clojure's spec, you can reference the same stuff downstream in the control flow too, for eg fn argument validation.