The book has just started to sell, and I am going to point out one thing that some Go purists may find frustrating: I don't use short declarations extensively in the book. They may think that this somewhat violates the whole purpose of the language : to be able to do things quickly.
However, I don't believe this is the case. The book does clarify that you can use short declarations, but I prefer to show how to do things the long way because that is the one that the beginners may find most difficult. The syntax is somewhat "backwards" of what they may expect.
Let's say I want to declare an integer and assign a value to it. If I use short declarative form, this is:
a := 5;
or even shorter
a:= 5
(no semicolon).
This is all fine and dandy, but is not very self-documenting of the variable a. One could argue that simply using a more useful name like numberOfCows or whatever describes the variable's purpose is the solution. I agree to an extent. This is most helpful, especially with primitive data types. But this can get remarkably confusing when the data types are not as clear cut, like various similar custom data types.
Regardless, for the book I chose to show the long declarations because these are self-documenting and if the reader doesn't like long declarations, they can feel free to create their program in short declarative form. There's no harm in declaring an integer variable (or any variable of any other data type) this way:
var a int;
a = 5;
So, pick your poison! Choose whichever feels best for you. The writability of Go is improved by using short declarations, but not necessarily the overall readability, in my opinion.
No comments:
Post a Comment