5 ms·
You can mimic this in most languages: createFile(name, contents, /* temporary= */ true). Of course that doesn't guarantee that that's what that parameter is act
by sanderjd 8y ago
You can mimic this in most languages: createFile(name, contents, /* temporary= */ true). Of course that doesn't guarantee that that's what that parameter is actually named, but you can write a lint for that (with quite a bit of effort).
- acdha 8y ago> Of course that doesn't guarantee that that's what that parameter is actually named I’ve found the odds of that happening approach certainty once you have more than one or two parameters. If you’re using a language without named arguments I usually treat adding a third parameter as a cue to reconsider using a more idiomatic interface, whether that’s something like classic Java OOP (.setTemporary(true)) or limiting that knowledge to one place by e.g. creating a subclass, struct, or a specialized function so you call createTemporaryFile() and know that ordering check only needs to be done in one place rather than by every caller.
- lower 8y agoI'm not sure about this, because it's easy to mix up two arguments of the same type. For example, you could mean createFile(name, contents, /* temporary= */ true, /* overwrite= */ true) but write createFile(name, contents, /* overwrite= */ true, /* temporary= */ true) by accident.
- SomeCallMeTim 8y agoNow I want to see something like Prettier (a code formatter that enforces _exact_ whitespace and specific optional syntax) that will parse C code and fill in the correct parameter names, in comments, based on the headers, for any boolean parameters (maybe excluding single boolean parameters?).
- fjsolwmv 8y agoA decent linter checks those Boolean comments for accuracy. Writing documentation that that merely copies existing code is terrible: it's either going to be wrong (because it's not automatically checked and will go sour in a refactoring, or it's right because it's so obvious that no one will guess wrong when looking at it.)