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.
3 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
HTMLcode(Opening tag,InnerHtmlcontent 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 :)
2 Comments
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.
Comments
These words may refer the same thing but in different aspects.
- Element is a part of something
abstractIt is anelementaryitem at some level of abstraction. It is a structural part of something. - Item is a part of some collection.
- Entry is an item of some collection that is entered (typed) by user.
- Record is items of information recorded to some collection.
- Node is an item of some collection that have connections - a part of a tree, a graph or an ordered list.
Items in a bag are not elements of a bag, as they are not a structural parts of the bag. But items in the bag are elements of a purchase or elements of a delivery that are now located in the bag.