4 ms·
> Enter Golang... a language smaller than even ANSI C. It's readable because if you've worked with Golang for more than a week, you basically know every languag
by ctz 10y ago
> Enter Golang... a language smaller than even ANSI C. It's readable because if you've worked with Golang for more than a week, you basically know every language construct you'll encounter.
That's not really what readability is to me. For example, I consider this idiomatic golang code (from the standard library, no less) to be entirely unreadable:
https://golang.org/src/crypto/tls/handshake_messages.go#L297 https://golang.org/src/crypto/tls/handshake_messages.go#L297
For me readability is more about suitable levels of abstraction. Languages can affect that by making abstraction longwinded, or expensive at runtime, or hard to compose.
- panic 10y agoIt's ultimately subjective, but I think that code is readable: the variables are well-named and each line says exactly what it does. Abstraction makes it easier for you to think you understand what the code is doing, but if you want to really understand what's going on, you also have to understand how the abstraction is implemented. Straightforward code like this can be understood directly, without having to dig through layers of function calls.
- catnaroek 10y agoIf you think that code is readable, could you correctly write all pre/post-conditions in between statements?
- panic 10y agoI think that's a little different. Reading code almost never involves analyzing it to that degree. Usually you're just trying to figure out what part is broken or where you need to add some new functionality.
- catnaroek 10y agoThe meaning of an imperative program is given in terms of Hoare triples. If you can't produce such triples on demand, then you don't understand the program in question.
- EdiX 10y ago> For example, I consider this idiomatic golang code (from the standard library, no less) to be entirely unreadable Really? It's a binary parser that's parsing data from a byte array and stuffing the results into a struct, it seems pretty straightforward.