11.1 Naming Conventions
Cliquez içi pour plus de vidéos disponibles sur notre chaine youtube !First of all, what is the purpose of a coding convention? Well, it’s so that everyone codes in the same way more or less and like that when we take someone’s code we don’t get lost completely.. Here are three main reasons: 80% of the life of an application is maintenance. The code will not be maintained by the same person for the life of the code. Coding conventions improve the readability of the code and a faster understanding of a new code First, let’s start with the naming convention. It is a good practice to follow the conventions adopted by everyone to make the codes we write more readable by ourselves and other programmers. For example in a company it will allow a new programmer to become familiar with these rules and will be able to understand the code written by a programmer who may have left the company several years before. Let’s start, so let’s talk about packages The package name should always be lowercase Generally packages are named with a domain name starting at the end and then adding the name of the project.. This would give for the Testproject project of the site of zero something in this style com.siteduzero.Testproject Naming the packages in this way helps to avoid conflicts between classes having then the same name and to navigate well. Then classes Classes are named according to the camelCase method but start with a capital letter. You should also avoid abbreviations and try to use words that describe the class well while not being too long. Example: ArrayList, Main, etc. Interfaces are named in the same way as classes. The methods are named according to the camelCase method and usually contain an action verb. This gives for example: fermLaFenetre(), donnerDeLArgent(), manger(), etc. In addition to this, it should be known that in a class we often find methods like getter and setter accessor, modifier to retrieve a class variable or modify it without directly touching the variable. It is usually called getNamDeLaVariable() and setNamDeLaVariable( Object nameDeLaVariable) There are also other keywords frequently used as add and remove(add, remove) to add and remove something So it will be, addQuelqueChose removeTout(), etc. Variables are also called in camelCase and start with a letter (a-z). The name of a variable should be short and clear. Variables with 1 character are to be avoided except for temporary use i, j, k, l, m, n for integers and c, d , e for characters This gives for example: tailleAppartement i, j, etc Constants, that is to say "static final" must be written in capital letters and to separate the words the "_" are to be used. This gives for example So, to make a long story short, the purpose of coding convention you facilitate the life and that of programmers that precedes you. I mean the next one.