-2

I have an array that holds valuable data related to what I stored in a setup / onboarding process:

$imported_headers = [ 'headers_2', 'headers_3' ];

Given the fact that these elements are from the same category but their [each element's] content varies by a lot at times and each of them only holds references that allow me to go deeper in the history chain for other processes, what best should I call these 2 items?

Twins doesn't work - they're not the same nor do I want people who use my function to retrieve them to think of them this way; Sisters - same, don't want to denote any kind of intended similiarity of the said components structure / values.

Neighbors? $imported_headers will sometimes have upwards of 10 items in it, but this function will precisely only retrieve the latest 2, neighbors would have a kind of finality - supposedly there's no more neighbors if my function is called and it retrieves only these 2 values.

My reasoning for asking a seemingly useless question, besides tormenting SE's purists, is that this function is part of 10+ functions that tie my system together and it'll be widely used both by my system and anyone that wants to use my API, it has to be descriptive and clear. Currently my function name is getSisterComponents. It matters a lot that I can have a conversation-like technical explanation about my code with other developers where I don't have to explain each function even if the said developer might not be aware of its implementation.

An example of exactly how my system works:

enter image description here

If I call myPerfectFunctionName( 'headers' ); it should return the following array: ['demo-3_headers', 'demo-5_headers'], as such, anyone that sees / uses this function will understand immediately that I'm querying the back-end system to look for the installed components from a category and pull the latest 2 installed items from the said category.

I want it to express that the function is a main, important query and that these 2 values are vital to whatever the process that's using the function to retrieve them does. Simply naming it 'getLastTwoInstalledComponentsByCategory` doesn't express usage and is generic.

closed as primarily opinion-based by gnat, Doc Brown, Martin Maat, BobDalgleish, Bart van Ingen Schenau Dec 6 '18 at 14:23

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Honestly, "elements from the same category but are not alike" is a description which is far too vague to give you a sensible answer, that could fit to any array holding elements of the same type. There is IMHO too much missing context for outsiders to do anything else here like playing guessing games. – Doc Brown Dec 3 '18 at 5:52
  • @DocBrown I changed to what I actually meant "from the same category but that don't have the same content". – coolpasta Dec 3 '18 at 5:56
  • Still not clear. What is the (index)numeric relationship between the array elements? Or is this meaningless after all and is it about latest creation times of the referenced objects? – Martin Maat Dec 3 '18 at 6:02
  • 1
    Okay, Naming is hard, which I understand is why you've asked. But for this to work I (and the greater we) need context. A Name is the best representation of that context. With what you have currently stated the best name I can suggest is to just use an indexed array. Literally 0 and 1, because at this level of abstraction they are Sisters and have no bearing on each other. What context I need is the kind of data in the first "sister" vs. the kind of data in the second "sister". Also I couldn't care less about your implementation I trust you have your reasons, but we do need that context. – Kain0_0 Dec 3 '18 at 6:10
  • 1
    If you want "anyone to understand immediately that I'm querying the back-end system to look for the installed components from a category and pull the latest 2 installed items from the said category", why not call your function getLatestTwoHeadersFromCategory? And I would call a data structure for pairs of headers just HeaderPairs. If you use such a structure, your function could also be named getLatestHeaderPairFromCategory – Doc Brown Dec 3 '18 at 6:52
2

I want it to express that the function is a main, important query and that these 2 values are vital to whatever the process that's using the function to retrieve them does

Anything that important should be wrapped in its own class, perhaps called "Context." (In an ideal world, the context would be injected, but that's not relevant to the question at hand).

The Context class could expose two members, for example "PrimaryHeader" and "SecondaryHeader" or whatever name is appropriate for your problem domain. I would discourage the use of terms like "Component," "Brother," or "Sister" because those terms are meaninglessly ambiguous to anyone trying to learn your API, and people really do not want to learn any more terminology than absolutely necessary.

If they are truly logically unrelated, the primary and secondary headers should be obtainable separately, via separate class members. If there is a performance issue that makes you want to retrieve both at the same time, solve that problem with read-ahead caching (e.g. when the caller requests one, get both and save it for later. Or keep it simple and just populate both in Context's constructor). But don't force the caller to deal with what is really an implementation detail. That is called a leaky abstraction.

1

The last and penultimate (the one before) / the two last / trailing children or siblings.

Child and sibling are the conventional notions.

Not the answer you're looking for? Browse other questions tagged or ask your own question.