November 2018
Intermediate to advanced
346 pages
8h 12m
English
When you are careful and stingy about your exported API, many good things happen. Chiefly, it becomes easier for others to understand; when a method has fewer parameters, it is naturally easier to understand. Look at the following code:
NewPet("Fido", true)
What does true mean? It's hard to tell without opening the function or the documentation. However, what if we do the following:
NewDog("Fido")
In this case, the purpose is clear, mistakes are unlikely and, as a bonus, encapsulation is improved.
Similarly, interfaces and structs with fewer methods and packages with objects are all easier to understand, and are more likely to have a more definite purpose. Let's look at another example:
type WideFormatter interface ...
Read now
Unlock full access