-1

I want to discuss with my boss a part of this code - so I need a name for it.

items = array.map(function(item){
    return item.item;
});

I want to say "This usage of the same identifier twice is _______________ and confusing."

They might respond "No this is _________ which is fine".

Is tautology an accurate word to use there?

the saying of the same thing twice over in different words, generally considered to be a fault of style

The use of item in the function call e.g., function(item) could be named anything you want, so instead you could have:

items = array.map(function(data){
    return data.item;
});

What is this called if not tautology?

Edit:

A non-programming example, would be naming a street Road Street, or worse naming an area in London, London (perhaps New York New York would also work).

  • 7
    I'm voting to close this question as off-topic because it's about the syntax of some programming languages, not English – FumbleFingers Aug 10 '16 at 10:56
  • @FumbleFingers this is not about the structure of statements, but a name for a specific naming pattern of thing.thing or foo.foo. – AncientSwordRage Aug 10 '16 at 10:58
  • 2
    @FumbleFingers With regard to your close vote, would you accept a different example that carries the same idea, such as "My aunt's aunt"? – Lawrence Aug 10 '16 at 11:05
  • 3
    The fact that the syntax of some programming languages allows you to use the same identifier for both a class name and a member of that class doesn't imply it's meaningful to ask what one might call such usage in terms of natural language features. You might as well ask whether two variable names are "synonyms" if they differ only in capitalisation. – FumbleFingers Aug 10 '16 at 11:06
  • 1
    @Lawrence: No more than I would accept a question asking whether there's a name for repeating *at* in, for example I'll be at* the station at nine o'clock.* – FumbleFingers Aug 10 '16 at 11:08
  • 1
    @FumbleFingers There's something about recursive references that tends to draw attention, though. There's more to aunt's aunt than at the station at nine. Aunt's aunt takes a concept (aunt) and applies it to itself, whereas at ... at has no self-reference. – Lawrence Aug 10 '16 at 11:15
  • 1
    @Lawrence: Perhaps I should have closevoted as a duplicate of "Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo." :) My advice to OP here would be to avoid using identifiers like item, thing, element, entry (particularly as class names, but they're pretty unimaginitive names for data elements and functions too). – FumbleFingers Aug 10 '16 at 11:26
  • @FumbleFingers I'm not here for programming advice. I'm mainly interested from the point of view of telling people not to do that. – AncientSwordRage Aug 10 '16 at 12:49
  • 1
    @Lawrence perhaps a better example is naming your son/daughter after yourself? – AncientSwordRage Aug 10 '16 at 12:49
  • 1
    @Pureferret You mean, like "Pureferret the Second", or "Pureferret Jr", or "Pureferret III"? I'd consider that a different sort of repetition, not a recursive reference. – Lawrence Aug 10 '16 at 13:03
  • @Lawrence No just "Pureferret" or maybe calling someone Face, then having to say "Face's Face".... – AncientSwordRage Aug 10 '16 at 13:04
  • 3
    @Pureferret- Although you won't be able to get a name for the thing, you might get better responses to how to explain the issue at Programmers.SE. You'll need to rephrase the question a bit, but I think it would be okay over there. – cobaltduck Aug 10 '16 at 13:07
  • 1
    @Pureferret "Face's face" can be called a recursive reference. Your other examples are more generic, though, and FumbleFingers's comment about the problems of naming data data should also be considered. Now that we've explored this to some depth, I invite you to reconsider your question, editing it to more clearly present the essence of what you want to ask. If you need some help with this, head over to the EL&U chat room. – Lawrence Aug 10 '16 at 13:36
  • @Lawrence is my latest edit not sufficient? – AncientSwordRage Aug 10 '16 at 13:50
  • 2
    @Pureferret I'd suggest adding a second example that isn't programming-related, and make explicit what it is about the repetition that you're after. (Does FumbleFingers's at ... at suggestion qualify? Why or why not?) If the quesiton is about programming style, then I defer to cobaltduck's recommendation. – Lawrence Aug 10 '16 at 13:57
  • Gorilla gorilla is not the same species as Gorilla beringei. – Edwin Ashworth Aug 10 '16 at 16:26

2 Answers2

7

It's not a tautology, it's saying that the item has an item, or at least has a function called "item".

The rules of grammar and semantics don't really apply to programming languages in any role other than merely as a guide.

You could criticise it for being confusing but I think it's a waste of time to try to get any more complicated than that.

Max Williams
  • 23,081
-1

It’s not a tautology. A tautology gives redundant information. For example, RAM memory is a tautology because memory is redundant. RAM is already understood to be memory. The usage is not confusing. It is merely redundant.¹

Your example is confusing because it is ambiguous. To say a statement is ambiguous means a person can take more than one meaning from it. For example, “The horse was found by the cow” is ambiguous. (Did the cow find the horse, or was the horse found near the cow?) Your example uses one identifier, item, to refer to more than one structure. It is ambiguous to the human reader, but not, of course, ambiguous to the compiler.²

MetaEd
  • 28,488
  • 2
    But it's not ambiguous to the human what item means. It can only mean one thing. There is only one variable in the scope with a name like item. It's just a coincidence that item has a property named item. – Mr. Shiny and New 安宇 Aug 10 '16 at 15:09
  • @Mr.ShinyandNew安宇 I'd argue that this practice creates ambiguity of the "garden-path" variety. It's easy to get confused about which item the code is talking about. Not so much in this example, which is trivial, but in any substantial piece of code. This is especially true when combined with unqualified naming (such as the "with" operator in JavaScript). – MetaEd Aug 10 '16 at 15:12
  • 1
    I will fully agree that it can lead to confusion. But I don't think ambiguous is the right label for the cause of the confusion. As you say, it's not at all ambiguous to the compiler. If the code is correct, nothing is ambiguous. If the code is flawed, then its intended functionality may be ambiguous. But the ambiguity in the flawed code arises from the problem of confusingly-similar names. – Mr. Shiny and New 安宇 Aug 10 '16 at 15:15
  • @Mr.ShinyandNew安宇 Exactly. That's exactly what my answer says. The similar names lead to ambiguity in the mind of the reader. – MetaEd Aug 10 '16 at 15:18
  • 1
    Is it really ambiguity in the mind of the reader if they're simply mistaken about the only, correct, unambiguous reading of the code? – Mr. Shiny and New 安宇 Aug 10 '16 at 15:21
  • @Mr.ShinyandNew安宇 Yes. Machine interpretation isn't what's being asked about here. Human interpretation is not mechanically precise. Our minds use heuristics. Our language processing "software" makes guesses and jumps to conclusions as we read. Often we have to backtrack when we run into a contradiction between what we've assumed and what happens later in the text. For more information, google garden path ambiguity. – MetaEd Aug 10 '16 at 15:25
  • 1
    A garden path ambiguity is ambiguous until you reach the end of the sentence, then (usually) the ambiguity is resolved. That isn't what's happening here, IMHO. Here, there are multiple things that the user can't keep track of. With a garden path, the sentence structure (and thus word meanings) isn't clear as you read it. – Mr. Shiny and New 安宇 Aug 10 '16 at 15:39