4 ms·
> Putting “here’s the fields I’m borrowing in the body” into the signature, in order to conform with the Golden Rule, looks very odd. I think this would be an
by j-pb 4y ago
> Putting “here’s the fields I’m borrowing in the body” into the signature, in order to conform with the Golden Rule, looks very odd.
I think this would be an amazing feature, but it would require something like typescripts partial types, where essentially every object/struct exists as a sum type of atomic fieldname:field-type types.[1]
Rich hickey[2] has a great talk on how existing type systems break in scenarios where you'd want them to be forwards compatible, e.g. when relaxing what you accept as arguments or similarly increasing the guarantees that you provide on returned values.
Partial types are one piece to that puzzle imho.
1: https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype https://www.typescriptlang.org/docs/handbook/utility-types.h...
2: https://youtu.be/YR5WdGrpoug?t=463 https://youtu.be/YR5WdGrpoug?t=463
- Georgelemental 4y agoSee also: https://smallcultfollowing.com/babysteps/blog/2021/11/05/view-types/ https://smallcultfollowing.com/babysteps/blog/2021/11/05/vie...
- dgb23 4y agoRich Hickey also came to mind, but a different talk[0]. There he talks in part about software stability and how spec (the primary way to encode data and function contracts in Clojure), is about communicating what is required and provided by a function or library (among other things). Rust's decision to make signatures mostly explicit (sans lifetime parameters here and there), is self-documenting and useful, but most importantly it creates an explicit contract that people can rely on. Rust code adheres to semantic versioning so at least it will also adhere to not breaking callers without bumping the major version. Which the further discussion in the talk do not agree with. But the fundamental decision to make signatures explicit at least enables people to write stable software. [0] https://www.youtube.com/watch?v=oyLBGkS5ICk https://www.youtube.com/watch?v=oyLBGkS5ICk