I’m a Rubyist, and just started writing Go several months ago. And at the beginning of learning Go, the most uncomfortable thing for me is that for most of the time, there is only one way to get things done.
For example, if you want to go through each elements in an array, you can only do it using the for
keyword:
for _, elem := range elements {
// Do something
}
In contrast, you can do this using several approaches in Ruby
elements.each do |elem|
# Do something
endi = 0
while i < elements.length do
elem = elements[i]
# Do something
i += 1
endfor elem in elements do
# Do something
end
And I think most Rubyists will agree that using the first approach is the best practice for going through each elements in an array.
So here comes the keyword: best practice.
This means instead of just knowing how to do the task, the programmer should also know how to do it in a right way. But why do we provide so many approaches for doing one job to language users, but tell them to learn and use only one of the them?
If you give programmers too much options to do one thing, they need to learn all those options and remember the best one, which in a sense is increasing the learning cost of the language. Also, the community might spend time arguing about what is the best practice.
Conclusion
So from my perspective, a language should only provide the best practice to its users. Which means there will be no best practice, because there will only be one practice.
This can be done by reducing the types of statements, providing less builtin methods or having an official linter…etc. And this is why we don’t have the for
statement in Goby. Because we can, and should only just use Array#each
or Range#each
if we want to do the task.