6 ms·
As a non native english speaker I have a recurring problem with this: > getInstances(); // ok, returns an array of instances > getInstanceId(); // ok, returns
by johnchristopher 6y ago
As a non native english speaker I have a recurring problem with this:
> getInstances(); // ok, returns an array of instances
> getInstanceId(); // ok, returns an id
> getInstancesId(); // ??, returns an array of id
> get InstancesIds(); // ?? returns an array of id
> getIdsOfInstances(); // ?? returns an array of id
> getAllInstancesId(); // ?? returns an array of id
> getAllInstancesIds(); // ?? returns an array of id
How do I conjugate that ? And what about the possessive `s` ?
- halfmatthalfcat 6y agogetInstanceIds
- resonantjacket5 6y agogetInstancesId() would usually mean a singular id corresponding to the group of instances. Only ones with an "s" at the end of the id should return an array if you have the existing "getInstanceId" either that or invert that function to be getIdOfInstance and subsequently getAllIdsOfInstance for the array version. Generally speaking don't use the possessive "s" it is implied by being next to it. Also I usually use "instance" in this case more like an adjective Edit: usually I think of it as (current subject) verb adjective object. So server get instance IDs becomes getInstanceIds() or zoo clean active dogs becomes cleanActiveDogs()
- crazygringo 6y agoAs a native English speaker (and former English teacher), hope this helps: > getInstances(); // ok, returns an array of instances Correct. > getInstanceId(); // ok, returns an id Correct. > getInstancesId(); // ??, returns an array of id Unusual, but would return a single ID referring to a collection of instances. > get InstancesIds(); // ?? returns an array of id Correct. Though more common would be getInstanceIds() since you don't need to pluralize twice. E.g. we don't say "blues shoes", we say "blue shoes", so these aren't "instances ID's" but "instance ID's". However, in naming functions or variables you'll sometimes see plurals repeated for clarity. E.g. getInstanceIds() is ambiguous because it could refer to the ID's of multiple instances, or multiple ID's of the same instance. While getInstancesIds() makes it clearer that it's the ID's of multiple instances, even though it's not actually grammatically correct. > getIdsOfInstances(); // ?? returns an array of id Same as getInstanceIds(). Both are correct, though getInstanceIds() would probably be more common -- most people wouldn't put in the extra word "of" simply because it's an extra word, but sometimes it might be clearer for consistency with other function names. > getAllInstancesId(); // ?? returns an array of id It would mean the ID for the collection of all instances, though that would seem very unusual. Perhaps if there were a global account ID for a service or API you used. > getAllInstancesIds(); // ?? returns an array of id Sams as getInstanceIds(), but "All" presumably means it doesn't include a parameter to filter -- so I'd assume this implied the existence of another function such as getCollectionInstanceIds() or similar that it was contrasted against. > How do I conjugate that ? And what about the possessive `s`? Obviously you can't or shouldn't use apostrophes in variable names, so people generally try to avoid the possessive s. That's why we generally change nouns to noun adjectives -- instead of "computer's ID" (computer = noun) we use "computer ID" (computer = noun adjective).
- pcthrowaway 6y ago> Though more common would be getInstanceIds() since you don't need to pluralize twice. E.g. we don't say "blues shoes", we say "blue shoes", so these aren't "instances ID's" but "instance ID's". Completely agree with all your points (as a native English speaker who also minored in English) However, for the sake of clarity (since we're trying to disambiguate between places the 's' could indicated possession vs. plurality) "instance IDs" should not have an apostrophe. The only time an apostrophe goes in a non-possessive plural is in a contraction. E.g. "the '90s" Then we also have fun words that probably should never be used which get an apostrophe on both ends (contraction at beginning + possessive plural) e.g. " ... the '60s' countercultural attitudes ..." But for clarity it might be better to go with "... the countercultural attitudes of the '60s ..."
- crazygringo 6y agoThat's a hotly debated issue that different style guides give different answers to. Some style guides insist plural all-capital abbreviations should never have an apostrophe ("IDs"), other insist they should ("ID's"). Your personal usage is absolutely valid, but it should be recognized as opinion and not fact. "ID's" is equally valid in modern usage. Edit: You can read an extensive discussion of it here: https://en.wikipedia.org/wiki/Acronym#Representing_plurals_and_possessives https://en.wikipedia.org/wiki/Acronym#Representing_plurals_a...
- pcthrowaway 6y agoInteresting. I've seen the apostrophe for acronyms which involve periods: e.g. "C.D.'s" (NYT has an article about this being their preferred style) I've seen it for one-letter words where you don't want to switch case: e.g. "dot your i's and cross your t's" But I haven't seen it in upper-cased abbreviations followed by a lower case plural 's'. Or if I have, I've assumed it's wrong. Would love it if you can refer me to a modern style guide which doesn't recommend dropping the `'` in this usage, as my own background has drilled into me that "IDs" is preferred for clarity.
- 6y ago
- johnchristopher 6y agoThanks everyone, much appreciated :).
- augustk 6y agoI have never understood the practice of using a verb phrase ("get") for functions with no side-effects. To me it makes more sense to name the function after the result, i.e. Instances, InstanceIds, AllInstanceIds etc.
- halfmatthalfcat 6y agoPreforming I/O is a side effect. Accessing an external database is a side effect. Using a verb to imply external access to "get" some resource is appropriate in this instance.
- codr7 6y agoThe advice I once got and since internalized is to reserve 'getX' to give a hint that something happens besides returning 'X', lazy initialization is a common use case.
- 8note 6y agoI think of ensureX as getting x whilst initializing it if needed
- wvenable 6y agoLike other's have said, I might use "Get" to signify that this is a complex operation. Although I prefer more descriptive words like "Fetch" or "Find". So FetchInstances() is expensive (each time it's called) but the property Instances is cheaper or only expensive on the first access.
- augustk 6y agoBut then the name of the function is somewhat tied to its inner workings. What if you change the implementation so that it returns a cached value? To quote Michael Caine, an interface should "Be like a duck. Calm on the surface, but always paddling like the dickens underneath."
- wvenable 6y ago