Let's not look at coding conventions which are essential for writing good clean and professional code 2
then what on like standard rules defined by experts from their own experience since there are standard 3
rules if you follow them it would also help your team members in understanding your code. 4
Even in our project they will follow all the coding conventions that we are going to learn. 5
It's a very important topic and there are books dedicated to just writing good clean code coding conventions 6
include several aspects of programming naming classes methods and variables is one of them how to design 7
our classes and methods is also part of coding conventions. 8
Similarly conventions also include stylistic aspects like how to indent statements or not and when and 9
how to write comments. 10
So let's begin learning about coding conventions by first looking at naming conventions. 11
Follow up Allisons will include other aspects of coding conventions. 12
Here is Item five basics for Effective Java which is dedicated to naming conventions and we will look 13
at most of its suggestions. 14
It's just sticking to the generally accepted naming conventions. 15
The item talks about two aspects of naming one is typographical and other is grammatical and we will 16
look at both of them typographical recommendations are more about appearance. 17
That is for example what is to use like upper or lower case. 18
Grammatical recommendations are more about part of speech like usage of verbs nouns and adjectives. 19
Let's begin with typographical recommendations and let's start with package's just not that there are 20
no separate grammatical laming recommendations for packages. 21
However we already looked at this during our discussion on Hultin in packages. 22
But just quickly glanced through them. 23
We know that package names include one or more components separated by dots. 24
The company should use lowercase alphabet characters and rarely digits. 25
They should generally be shocked that eight of your characters and generally should be single words 26
meaningful abbreviations are fine and so are acronyms like AWG finally package names should never start 27
with our job X which are used by standard July API. 28
Also if your package will be used outside of your organization then you should begin the package Nimrat 29
your organization's reverse Internet domain name. 30
Next let's look at classis methods and variables. 31
We will just look at what we need to use for them classes. 32
Capitalize the first letter of each word and this also applies to interfaces which will be discussed 33
later. 34
For methods and variables used Camelias that is the same as classes. 35
But the first letter is not capitalized when it comes to topic final variables. 36
We already discussed that they need to be in all caps with underscores separating words. 37
Not that this rule does not apply to final instance our final local variables. 38
No this is a place of variable is primitive but if a variable is an object reference then there is a 39
certain restriction which is related to a concept that we have not yet discussed. 40
So I'm not discussing it here. 41
But you can check out the supplementary notch in the resources section where the restriction is explained 42
. 43
Next 100 typographical class is about using abbreviations for classes methods and fields a wide abbreviations 44
that imply static on instance variables. 45
You may use abbreviations only for very commonly used names like minimax. 46
Acronyms are fine for local variables but abbreviations and acronyms are fine. 47
Individual characters are also fine but only if used in any meaningful way. 48
For example it is fine if you use X Y and Z for coordinates or I took you pluck off index like in the 49
case of NRD. 50
So if you look at typographical aspects. 51
Now let's look at grammatical aspects of naming for classes. 52
You're singular No not non-ferrous. 53
So you use user instead of plural users. 54
Similarly buffered Roder is a noun phrase and this clause is part of the job package. 55
Also just try to keep the class names simple and descriptive. 56
The names should tell us what the class does next let's look at matters from a grammatical standpoint 57
. 58
Methods can be named based on what they do or what they're written. 59
So let's look at the specifics if methods perform some action like appending be a string builder or 60
calculating distance between two points. 61
Then you will use a verb or verb phrase as verbs indicate some action. 62
Also use descriptive names for my goods. 63
This should tell us what the method does using descriptive names would in fact serve as documentation 64
too. 65
That is we do not how to write any additional comments about what the method does. 66
Also if needed do not hesitate to use longer descriptive names they are better than having shorter ambiguous 67
ones. 68
Next is about methods that return a boolean value. 69
Usually this starts with the key word IIS followed by a noun or noun phrase or an adjective. 70
One example is a static easy digit method from the character class. 71
It checks if the input character is a digit or not. 72
Another example where an adjective is used is the ease implemented from the string class. 73
It can be invoked on a string object to check whether the string is empty or not when it comes to certain 74
style matters and the field involves a Boolean field. 75
Then for setter it would be a set followed by the filename while forgetter it would be East followed 76
with a feeling. 77
In this example the field name is active for boolean fields. 78
Ideas like Eclipse would auto generate getters and setters with such kind of a convention. 79
We may also sometimes use the E word has instead of ease. 80
Examples could be has license or has children but has is less frequently used than is. 81
Next let's see how the name matters that are written in anon boolean attribute of an object. 82
Here attribute is nothing but an instance variable. 83
Usually such attributes are known or unknown reasons. 84
In this case you can simply use the attribute name as a method name. 85
Alternatively you can also use the word get followed by the attribute name. 86
You should definitely prefer using the prefix especially if there is a corresponding segment there that 87
is we are discussing what setters and getters here. 88
It would be confusing if there is a setter but a set prefix but forgetter we have just the attribute 89
name. 90
So if there is a setter use a good person. 91
Otherwise you may simply use the attribute name as the motard me and it will be very readable in two 92
separate gap. 93
If method is performing some action use of a if it is returning a boolean use and is followed by a noun 94
or adjective or name of the Boolean aggregate. 95
If it is returning a non boolean attribute of an object then either use attribute name directly or attribute 96
name that get prefix. 97
Now before signing off on my text. 98
Let's also look at one final type of method names that deserves special mention. 99
There are certain matters that can with the type of an object that is when involved in an object of 100
a certain type. 101
There is an independent object of a different type in this because it would use a keyword to. 102
Followed by the type of the destination object. 103
Gosling is an example where an independent object of type string is written which would basically be 104
a string representation of the actual object on which the method was invoked. 105
Next there are methods whose sole responsibility is to create objects. 106
These are some commonly used names for such methods. 107
We have already seen value of method when discussing baulks primitives. 108
Finally for feels grammatical Conventions are not that bad as stablished and hence are not as important 109
as for classes on methods for local variables. 110
Conventions are similar to use but even weaker for boolean fields usually adjectives are used. 111
Some programmers use a prefix IIS but it is not recommended. 112
For example use the name actor rather than easier do her nonbelief and feels non-SS unknown phrases 113
are common for data sources like arrays. 114
You can use plural nouns for reference to our age and singular norms for its elements. 115
Finally if you mean how multiple objects of the same class used are the same please. 116
In this case we should name the object of France by that purpose. 117
Here is an example of a method in which Blon use it is sending a message to another using. 118
In this case since both the references are all for user type the first user is named a sender while 119
the second NESA receiver and that's about naming conventions. 120
As much as possible you should try to follow these conventions unblinded them only if there is a very 121
good reason. 122
So do internalize these conventions and start using them in your code. 123
Thank you