Naming variables is quite important and being a non-native English speaker I wonder what the difference would be for using element, item and entry to name things within data structures or variables/parameters.
2 Answers
Let us start with the plain English meaning of each of these:
- Element: a part or aspect of something
abstract
, especially one that is essential or characteristic.Thus, they can be thought of logically connected atomic parts of a whole. E.g. Elements(Nodes) of a Tree, Elements of a
HTML
code(Opening tag,InnerHtml
content and Closing tag) - Item: an individual article or unit, especially one that is part of a list, collection, or set.
I prefer this when the thing are logically independent like Items in a Shopping cart, Items in a bag, etc
- Entry: an item written or printed in a diary, list, ledger, or reference book.
I usually use this for tables like Hash Table or Accounts(Transaction entry) or Records(recording entries in sales, etc.)
Now we can't refer the items in a bag(considered as an Object in Object oriented paradigm) as entries or elements(probably not elements because the items as not constituents of the bag itself).
However, in some cases like an array we can use the element or item or entry interchangeably too :)

- 4,078
- 3
- 28
- 54
-
1What about entry vs record? – MaxCore Jan 27 '18 at 20:47
Had to think on this for a few minutes, interesting :)
Note I'm not a native English speaker either so my opinions are just that, opinions.
I use 'element' for things that have some connection with each other, like nodes in a graph or tree. I use 'item' for individual elements in a list (i.e. that don't necessarily have a connection to each other). I don't use 'entry' because I don't like it in this context, but it's just a matter of preference.
Since I'm primarily a C# dev, this is apparent in .Net's naming too: a List<T>
has Items, but WPF building blocks in XAML, or XML tags, are Elements (and many more similar examples); that's probably at least part of the reason why I formed this habit.
I don't think there would be anything very wrong with switching things around though; it would certainly be understandable enough from my point of view.

- 5,539
- 2
- 21
- 35