Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between element, item and entry when it comes to programming?

Tags:

naming

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.

like image 770
Martin Kersten Avatar asked Jul 15 '15 09:07

Martin Kersten


People also ask

What are entries in programming?

In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.

How do you find the difference between elements in arrays?

You can use array#map . For the first index value subtract from 0 and for other indexes, subtract from the previous number.


2 Answers

Let us start with the plain English meaning of each of these:

  1. 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)

  2. 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

  3. 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 :)

like image 59
TryinHard Avatar answered Oct 23 '22 00:10

TryinHard


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.

like image 1
Alex Paven Avatar answered Oct 23 '22 00:10

Alex Paven