Naming convention on a computer

When starting out in the development of websites, applications or databases, we often wonder how to name things. Here are some ways to help you, inspire you and minimize the risk of errors.

A   naming convention   in computer programming is a set of rules for choosing the identifiers (element names) in the source code and documentation. To better understand the benefits and challenges of doing this, visit the full wikipedia article.

Why to follow a naming convention?

humor man machine

First because a machine, a computer system, a file system is not human at all. Reduced to its smallest scale, it is electricity that oscillates between 0 and 5 volts at a frantic pace and we ultimately want the result to have an aspect that we can understand. Between the two, there is often a machine, an OS, a file and an application which finally appears on a screen.

We must separate the result that we see and the way we achieve it. Separate the human aspect from the technical aspect. This article deals with the second.

Name of files and folders

Suppose we have just made a logo that will only be used during the summer and that it should be recorded. Our mind suggests us to name it:

High Résolution Logo, Summer 2018.jpg

This name is not appropriate, even if locally on your computer everything will be fine. It’s in your memory, in applications and on the internet that it’s going to get stuck.

  1. It contains capital letters – On the Internet, a capital letter is not equivalent to a lower case. Windows and MacOS are very tolerant, while a web server is not at all.
    Which means that if you have to write it in code, you will have to remember the exact syntax.
    If you do not use it, it will be less beautiful to read for a human, but you will remember much better.
  2. It contains accents – On the internet, an accent must be encoded (replaced by a code) and this code is not identical according to the platform (Windows ISO 8859-1, MacOS   Novel).
    Do not use accent ensures full compatibility between all platforms.
  3. It contains special signs – Apostrophe and punctuation are special signs. Some signs have special meanings (‘ “,;? = # /: < >) All serve something special in programming or on the internet.
    Do not use signs, avoid side effects and do not need to encode them.
    Four signs are allowed _ ( underscore ) – (drew) and parentheses. However, it is recommended to use only one, the underscore . The others can be interpreted as arithmetic operations.
  4. It contains spaces – On the internet, when accessing a file within a URI (URL) spaces are not allowed. It will therefore be necessary to replace the space with a code (% 20).
    Do not use spaces, you do not have to encode the file name. Use an _ ( underscore ) instead.
  5. It contains a date – If a year later you change logo, you will probably redo a new file and name it “… December_2019.jpg” but then you will have to think about updating all the applications, all your pages web site as well as all related sites that used your logo, to inform them that the logo at changed and you have to bond with the new one. It’s a titanic job, if not impossible.
    Instead, archive the old file by naming it with a date, but always keep the same name for the one that will serve as a reference.

It should therefore be named:

logo_haute_resolution.jpg

For a folder, use the same rules for the same reasons.

Conclusion

To name a file, use the letters from a to z , in lowercase as well as   the numbers from 0 to 9 .

To separate the words,   do not use spaces , use the underscore _ instead.

Avoid any other sign or punctuation.

Databases, Tables and Topics

Imagine that we have to create a database containing the logos of our customers. It will contain two tables.

A database is a file, the previous 5 rules are required. So we will name it:

images_entreprises

Why not logos_clients ?

Our current project may be limited to the logos of our customers, but if it works well it could evolve easily and can store photos and logos, for all partner companies, customers and suppliers.

Now let’s name our two tables, the same naming rules apply, although there is a variant with capital letters:

  • companies or Companies
  • logos or Logos

It is advisable to create tables according to their nature and to name them in order to be able to make them evolve easily.

A logo is an image of a certain type, just like a photo. It will be easy to distinguish them by a heading.

A client and supplier are similar, they share a lot of characteristics in common are wholes two companies.

Every table must have a primary key (primary key), an identifier   unique and invariable allowing another table to link to our record. There is absolutely no need for it to be humanly understandable, on the contrary. The company name is not a primary key, it is probably unique, but not invariable. A company can suddenly change its name, even if it’s rare. Often a primary key is an automatic number or a unique complex text string within the database.

Other tables will then have a foreign key (foreign key) referring to it.

It’s all about naming rules.   If you want more information about databases, you’ll find all information on wikipedia .

Let’s make some headings allowing to:

  • See a company and its official logo
  • Identify the director and his email address
  • Click on a link to go to their website
  • See postal address

First without the capital letters

businessThe table is plural, it contains several
pk_entreprise( Primary key, primary key) unique for a single company, that’s why it is singular
entreprise_nomThe name of the company
entreprise_typeThe type of company, customer or supplier
fk_image( Foreign Key, secondary key) The key of the image to bind to a single image identifying the company, its logo.
directeur_nomThe last name of the director
directeur_prenomThe director’s first name
directeur_emailThe director’s email address
uri_protocoleFor the internet protocol (http or https)
uri_adresseFor the domain name (www.truc.com )
adr_rueThe street of the postal address
adr_case_postaleThe postal box of the postal address
adr_npaThe postal code for the postal address
adr_villeThe city for the postal address
calc_adresse_postalethe calculated heading which will compose the postal address
calc_hyperlinkthe calculated item that will add the address to the protocol in order to create the hyperlink

And to store the logos in the image table:

imageryThe table is plural, it contains several
pk_image( Primary key, primary key) unique for a single image, it is singular
filenamethe file name
fk_entreprise( Foreign Key, secondary key) of the company to which it belongs
uri_protocoleTo display the image, the internet protocol (http or https)
uri_adresseThe web address where the image is
calc_image_sourcethe calculated item that will load the address to the protocol in order to obtain the source of the image

With capital letters

companiesThe table is plural, it contains several
ID_Entreprise( Primary key, primary key) unique for a single company, that’s why it is singular
entreprise_NomThe name of the company
entreprise_TypeThe type of company, customer or supplier
image_id( Foreign Key, secondary key) The key of the image to bind to a single image identifying the company, its logo.
directeur_NomThe last name of the director
directeur_PrenomThe director’s first name
directeur_EmailThe director’s email address
uri_ProtocoleFor the internet protocol (http or https)
uri_AdresseFor the domain name (www.truc.com )
adr_RueThe street of the postal address
adr_CasePostaleThe postal box of the postal address
adr_NPAThe postal code for the postal address
adr_VilleThe city for the postal address
_ PostalAddressthe calculated heading which will compose the postal address
_ Hyperlinkthe calculated item that will add the address to the protocol in order to create the hyperlink

And to store the logos in the image table:

imageryThe table is plural, it contains several
ID_Image( Primary key, primary key) unique for a single image, it is singular
filenamethe file name
Entreprise_ID( Foreign Key, secondary key) of the company to which it belongs
uri_ProtocoleTo display the image, the internet protocol (http or https)
uri_AdresseThe web address where the image is
_ ImageSourcethe calculated item that will load the address to the protocol in order to obtain the source of the image

Conclusion

The use of prefixes is strongly recommended to group topics and clarify their usefulness.

To name a heading address or name only, makes sense only if there is no ambiguity , here there would have been; web address or mailing address, company name or director’s name.

Both tables have fields with the same name, which is quite common. It is not necessary to use a prefix with the name of the table, this only lengthens them unnecessarily. And that makes sense because their content is similar.

Coding

In programming, naming rules are important in order to distinguish between   variables , objects or classes .

These rules may vary from one language to another but speci c applies to most currents (Java, C #, PHP,   javascript , css )

Let’s take a look at the examples where we have to code descriptions of logos.

  • We use the letters from a to z and from A to Z , the variants between upper and lower case having a meaning.
  • We start with a capital letter , when we name an object or a class .
    The object to describe a logo would be named: DescriptionLogo
  • We   starts with a lowercase , if it is a variable .
    The variable that instantiates the object would be named: descriptionLogo
  • Never space . In programming, space is used to separate the elements of an instruction.
    The statement that creates the variable instantiating an object would be: private descriptionLogo = new DescriptionLogo ( );
  • Never punctuation   or special signs. In programming they serve the syntax of our instructions.
    If our logo description contains a text property, a dot allows you to reach it: Print ( descriptionLogo.text );
  • Never accents . To avoid encoding problems when moving from one platform to another.
  • Numbers are rarely used . In general, if we need it, we have different values ​​for a variable. It is then necessary to create an array whose number will be the index of the variable.
    If we had multiple descriptions, we would call each of them by:
    descriptionLogo [ 0],
       descriptionLogo [1] , etc …

Conclusion

Every programming language and every person has its own conventions and convictions. This article is not a norm, it is mainly about answering questions that we can ask ourselves when we start to discover and act in a computer system.

Leave a comment