6 ms·
> You even introduce a class of bugs doesn’t exist for statically typed languages. Conversely, you're also able to write equivalent functionality with less cod
by gnaritas 9y ago
> You even introduce a class of bugs doesn’t exist for statically typed languages.
Conversely, you're also able to write equivalent functionality with less code and with idioms you can't use in statically typed languages. It's an engineering trade off, the static typed handcuffs prevent you from making a certain kind of mistake but they also prevent you from writing certain kinds of code that are extremely powerful; many prefer the power over the handcuffs. Type bugs just aren't that painful.
- sjwright 9y ago> you're also able to write equivalent functionality with less code The amount of code one writes says more about the language than whether or not it's statically typed. To me, adding "bigint" or "bool" to the occasional variable and function declaration isn't "more code", it's an extremely terse way of avoiding different code (e.g. type assertions).
- gnaritas 9y agoThat's not what I mean by more code, by taking advantage of dynamic typing you can write more generic code than is even possible with generics in a statically typed language; code that works for any type, whereas a static language either forbids you or forces you to write multiple versions of the function. You can't write a single Max function in C# that works for any type supporting >=, it simply can't be done. This is typical of static languages, they forbid perfectly good code because it "might" be used inappropriately or because the type system can't guarantee it won't.
- sjwright 9y agoNothing is stopping languages from allowing both. For example, it could have some form of compound type declaration. Meanwhile, how often is code made worse because you have to write multiple Max implementations? And I doubt that there's many instances where such repetition is necessary, or can't be mitigated with wrapper functions.
- gnaritas 9y ago> Nothing is stopping languages from allowing both Nothing stops pigs from flying either... hypothetically, but they don't, and languages don't, so debating what they could do is rather pointless, they don't. > how often is code made worse because you have to write multiple Max implementations Similar situations occur quite often. > I doubt that there's many instances where such repetition is necessary, or can't be mitigated with wrapper functions. That they have to be mitigated is the point, I don't have to do stuff like this at all in a dynamic language, things just work.
- sjwright 9y agoCongratulations, you have worked out that there are no perfect languages. I don't understand what point you're trying to make, other than you prefer one set of trade-offs to another.
- gnaritas 9y ago> other than you prefer one set of trade-offs to another. reply So you can understand the point being made, congratulations, it's what engineering is all about.
- dragonwriter 9y ago> by taking advantage of dynamic typing you can write more generic code than is even possible with generics in a statically typed language; code that works for any type, whereas a static language either forbids you or forces you to write multiple versions of the function. If you can write code that works for some combination of types, it's because those types present a common interface that could be specified in a sufficiently-expressive static type system, either via something like OOP interfaces or something like Haskell typeclasses. > You can't write a single Max function in C# that works for any type supporting >=, it simply can't be done. You can, in fact, do so for any type supporting the IComparable<T> interface. That the operators are defined independently is a C# type-system quirk, not a fundamental limitation of static type systems.
- gnaritas 9y ago> that could be specified in a sufficiently-expressive static type system Ah the mythical sufficiently-expressive static type system, I'm concerned with type systems that are in use in real jobs, not vaporware ones that could exist if only. Dynamic language support it now. > You can, in fact, do so for any type supporting the IComparable<T> interface. Which requires forethought on the designers of said library, I'd rather have duck typing which works without requiring correct future planning with interfaces.
- tome 9y agoI've had professional jobs writing both Python and Haskell. My Python code has to be far more verbose and complex than my Haskell, and the Python's harder to maintain too! > Type bugs just aren't that painful. You haven't learned the true power of a decent type system then.
- bayesian_horse 9y agoFew seem to have learned the "true" power of a "decent type system". Which seems to be only Haskell... And yes, Haskell is terse. Other popular statically typed languages (Go, Kotlin, TypeScript, Dart) are not.
- tome 9y ago> "decent type system". Which seems to be only Haskell... Haskell, OCaml, Elm, Purescript, arguably Scala although I don't like it personalyl.
- dllthomas 9y agoWhile certainly Haskell lets you do more, you can get some interesting help from even the C type system. For instance, I was able to enforce "this can only be called from the main thread" with no runtime overhead.
- gnaritas 9y ago> You haven't learned the true power of a decent type system then. Conversely you haven't learned the true power of dynamic types or like coding with handcuffs to keep you safe. What static types offer me is not as useful to me as what they forbid me from doing, so no it isn't an issue what what I don't know, but rather of what I do. And Haskell, no thanks, I'm not a masochist. > and the Python's harder to maintain too! That's an issue with Python, not with dynamic types. My Smalltalk code is a joy to maintain.
- cutler 9y agoThe biggest advantage of dynamically typed languages is the ease of using deeply nested data structures with mixed data types. This is just a pain in languages like Java and Scala where the Any type is often reverted to.
- andreasgonewild 9y agoAs long as the number of mixed types is finite, unions/variants give you the same ease of use with static guarantees.