5 ms·
> Could articles[5] be used to do things like pass variables or instantiate objects? I wrote about something similar to this (called "type-named objects") in a
by carussell 9y ago
> Could articles[5] be used to do things like pass variables or instantiate objects?
I wrote about something similar to this (called "type-named objects") in a post last year[1]. The idea is that for small utility methods, you shouldn't have to interrupt your main flow of thought to come up with names for your formal parameters; in fact, you shouldn't even have to name your locals. If you're working in a language with a (perhaps already verbose) static type system, you can just leverage that.
So, for example, instead of this:
appendNode(node: Node): void {
this.tail.next = node;
this.tail = node;
}
... you can do:
appendNode(Node): void {
this.tail.next = the Node;
this.tail = the Node;
}
This does introduce some precedence/binding gotchas that I go more into. But that hints towards further improvements. From the aforementioned post, you could end up with a language that allows:
the ControlMessage's id := defocus
Or, if you add support for "passive voice" to your language:
id from the ControlMessage := defocus
Completely unrelated, but related to the use of "the", Carmack wrote a tweet[2] that I've got embedded in the comments of a project of mine.
> I have moved to naming global singletons with a The* prefix -- ThePacketServer, TheMasterServer, TheVoip, etc. Feels pretty good.
Since then, I stopped creating "proper" singletons altogether. Instead, it'd be a quasi-singleton, where I write a `MasterServer` class, and then bless an instance as `TheMasterServer`. Application code will always import, refer to, and otherwise operate on the latter, but tests are free to instantiate their own. This is especially useful if you have implemented some sort of developer switch in the UI that allows you to launch an embedded test harness within a live, running instance of the app. In that case, you don't exactly want your tests to be fiddling with your "real" singleton.
1. https://www.colbyrussell.com/2017/02/16/novel-ideas-for-programming.html https://www.colbyrussell.com/2017/02/16/novel-ideas-for-prog...
2. https://twitter.com/ID_AA_Carmack/status/575788622554628096 https://twitter.com/ID_AA_Carmack/status/575788622554628096
- bobthepanda 9y agoI feel like this would be a great argument for an args keyword, in the same way that this is a keyword. args would just be a JSON object with some additional syntactic sugar for adding/removing parameters. So if you have an overloaded method, say print(String) print(String, Int) you could just do print(args.extend(Int))
- russellsprouts 9y agoI can't remember the name, but there is a language with type-named parameters. It's an object-oriented language inspired by Java. It doesn't use "the" -- it's clear from context whether something is a type name or reference, so you just use "Node". To handle multiple variables of the same type, you can use Node, Node', Node'', etc. It also supports phrasal methods, where arguments can appear in the middle of the method name. For example, what would be divide(x, y) could be defined as divide(x)By(y) instead.
- vorg 9y agoI believe Swift (I think) uses this idea, where the 2nd and subsequent parameters are often named prepositions: divideInto(x, by:y, mod:z)
- akvadrako 9y agoSeems like Applescript.