3 ms·
Go makes it easy to understand what is happening at a micro per-statement level and not a macro level. For me, readability is about expressing __intent__ and no
by higerordermap 6y ago
Go makes it easy to understand what is happening at a micro per-statement level and not a macro level. For me, readability is about expressing __intent__ and not about every machine detail. Writing all that boilerplate is also more error prone.
My favourite example: see the following code in Go
containsVal = false
for _,i := range array {
if (i == val) {
containsVal = true
}
}
This is one statement in any language with reasonable abstraction capabilities:
python:
`val in array`
Javascript:
`array.includes(val)`
Java:
`array.indexOf(val) != -1`
C++:
`std::find(array.begin(), array.end(), val) != array.end()`
(Actually C++ one is already quite verbose and little distracting, but sure you can implement it better in C++)
Go is only so-called modern language in which standard library cannot provide trivial abstractions to convey intent. Instead you have to use interface{} escape hatch or use codegen.
The 'Go is readable' meme is misguided.
- jahaja 6y agoStuff like this just isn't important compared to the benefits. One has to focus on the positives and negatives and each of their proportional importance overall. In that particular case, it's just fine to workaround these things with interface{} and move on to more important stuff. Or perhaps consider to use a map if you find yourself constantly needing to pick out an entry from a slice.