Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is there a name for this technique/pattern of using an argument's type to figure out which parameter it is, rather than using its position or a keyword? I've just started doing the same recently and it's quite ergonomic.

Are any (currently existing) type systems able to encode this sort of thing such that it can be statically checked? IIUC from here[1] the compiler allows any type to be passed in. Sum types catch the error of passing the wrong type in, but don't do anything about passing the same type in multiple times. It's unclear whether the Upspin solution of last-write-wins is simply an easy default that falls out of how they process the arguments, or whether they actually use that property somewhere. I've made the equivalent case an error in my code since it seems much more likely to be indicative of a logic error, I'd love to hear arguments for doing it the other way.

[1] https://upspin.googlesource.com/upspin/+/master/errors/error...



So if it is a string and contains "/", it is categorized as a path?

https://upspin.googlesource.com/upspin/+/master/errors/error...

User names can contain slashes apparently:

https://godoc.org/upspin.io/user#Parse


Yeah, that part seems fragile. Which is why I'm against magic do-what-I-mean logic unless there's only one reasonable way to make semantic sense of it. And preferably only one way to do so, reasonable or unreasonable.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: