4 ms·
Then types in python are not expressive enough. Other languages most of the time you don't even necessarily need to specify the types - the compiler/interpreter
by foxes 6y ago
Then types in python are not expressive enough. Other languages most of the time you don't even necessarily need to specify the types - the compiler/interpreter can figure it out and still type check the program.
- nerdponx 6y agoMaybe, maybe not. Data classes are meant to feel like Scala's case classes, or Haskell's record syntax. The point is to stop passing around dicts/hashmaps/tables and tuples, and to start passing around containers with a known and fixed set of keys/names, and known types for the values/elements. I don't know of any language where the compiler automatically infers field names and types, and I don't know if I would ever want such a thing.
- josteink 6y ago> I don't know of any language where the compiler automatically infers field names and types, and I don't know if I would ever want such a thing. Typescript can do this to unannotated code, and it’s surprisingly useful.
- nerdponx 6y agoI've already started checking out Typescript as a general-purpose scripting language to replace Python, Ruby, Perl, and to some extent Bash/Zsh. Knowing this makes it even more attractive. The only annoyances I've had so far are: difficult-to-search docs, and the `tsc` command-line compiler is slow.
- dragonwriter 6y agoEven in languages where this is possible, it's usually idiomatic to explicitly type the public interface including exposed fields, and often it's common to explicitly type them narrower than the inferred type to avoid implementation details leaking into an unintentionally broad backward compatibility contract restricting future evolution.