3 ms·
As a no-go programmer looking through the data race detector docs (http://golang.org/doc/articles/race_detector.html http://golang.org/doc/articles/race_detecto
by azinman2 14y ago
As a no-go programmer looking through the data race detector docs (http://golang.org/doc/articles/race_detector.html http://golang.org/doc/articles/race_detector.html), it to me shows snippets of a really ugly language with poor readability. Examples from Google's page:
var service map[string]net.Addr
When I read this it's easy to skip seeing string, aside from the fact that ] as a delimiter also looks like net.Addr was accidentally combined with the previous line.
func ParallelWrite(data []byte) chan error {
res := make(chan error, 2)
f1, err := os.Create("file1")
if err != nil {
res <- err
} else {
Here we see no parenthesizes used in if statements, yet we retain {. In skimming it's easy to miss the if in the first place. Yet everywhere else they're happy to use parenthesizes. We also see that "make" is lowercase yet a method, but os.Create and ParallelWrite has caps for a method.
There's also the fact that the array (I'm guessing) of bytes diverges from every other language to put them in front of the type which looks like crap. We see the same poor choices of delimiters as with map value types.
Then there's this
func main() {
c := make(chan bool)
m := make(map[string]string)
go func() {
m["1"] = "a" // First conflicting access.
c <- true
}()
m["2"] = "b" // Second conflicting access.
<-c
for k, v := range m {
fmt.Println(k, v)
}
}
<-c looks like its just dangling, and if this is meant to say there's some kind of stream or assignment then does it just go to /dev/null? Yet "c <- true" is also correct? I'd argue for either void <- c, _ <- c, or c.read() if wanted to support something like that.
It's also difficult to tell in the for loop if v is being assigned as "range m", or if "k, v" are a tuple resulting from "range m"
It's too bad because the goals of the language are quite nice from a CS perspective.
- landr0id 14y ago`<-c` is the main routine waiting for the other goroutine to finish (`c <- true`). It's being blocked until there's something for it to receive. > It's also difficult to tell in the for loop if v is being assigned as "range m", or if "k, v" are a tuple resulting from "range m" The `range` clause returns two values: index, and value at that index. It's really pretty easy to read and get used to once you actually read some documents.
- elithrar 14y ago> Here we see no parenthesizes used in if statements, yet we retain {. In skimming it's easy to miss the if in the first place. Yet everywhere else they're happy to use parenthesizes. I feel that braces on blocks are more important to readability/clarity—because blocks should be identifiable—compared to parentheses for if statements. I don't think the if gets lost in there, but if you do then that's fine. > We also see that "make" is lowercase yet a method, but os.Create and ParallelWrite has caps for a method. That's because "make" is a built-in function for building slices and maps. Packages with exportable functions (i.e. os.Create, http.HandleFunc, etc, etc) use capitalisation to denote "public" functions[1]. Functions within the os or http packages (for example) that should not be used directly by someone using the library retain a lowerCase approach. This reduces the risk and confusion surrounding which functions you should be working with when using a library. > It's also difficult to tell in the for loop if v is being assigned as "range m", or if "k, v" are a tuple resulting from "range m" Each key:value pair in m (a map, or "dictionary") is being assigned—hence the :=, which declares & assigns k & v in one line—for the entire range ('length', really). Obviously you don't agree with some of the syntax in Go. That's fine. But some of your criticisms appear to stem from a misunderstanding or lack of knowledge about some language-agnostic concepts (channels, range, exportable functions) that I don't think Go obscures. [1]: http://golang.org/doc/effective_go.html#commentary http://golang.org/doc/effective_go.html#commentary
- azinman2 14y agoI agree with you on blocks/scoping. If dropping the parens I think Python does it right with its tab-based blocks. Was uninformed about caps. That was a minor point for me, however, and in hindsight I should have at least investigated that before saying something. Ok I see the consistency in :=, but in that sense I'd personally like to see something closer to Scala where the tuple is explicit by doing something like: for (k, v) := range m { Which doesn't look all that much better, mostly because of the := (I've never liked in any lang) and the spacing between range, m, and {. for (k, v) := range(m) { Could be yet another way to help make it more clear what is modifying what. When you're tired and have been starting at code all day long having more visual gestalt in the language helps... syntax highlighting serves much of this but it's better IMHO if the language highlights itself.
- __david__ 14y ago> There's also the fact that the array (I'm guessing) of bytes diverges from every other language to put them in front of the type which looks like crap. It does look weird at first—I thought the same thing. But after writing some code with it, the design has a nice simplicity. When decoding C types, you have to sort of go back and forth "int * x[]" (an array of pointers to int) but in go it's always one direction: "int * []x". The type is always grouped together and that ends up being much easier for humans to parse. Ditto for putting the return type after the function args. Seems backward if you're used to C/Java/etc but it makes things nicely composable, plus now every function starts with "func", and not a random return type. I'm fine with the losing the parens around the ifs. Other languages do that and less syntax can look less messy. I do, however, HATE the required curlies. And the fact that stupid go-fmt always wants to format them out differently than I do: if short_check { short_code() } // My preferred formatting for short error tests if short_check { // go-fmt always wants to do this. short_code() } // Blech. For that reason alone I refuse to use go-fmt on my code :-). But I'm stubborn that way...
- losvedir 14y ago> For that reason alone I refuse to use go-fmt on my code Nooooo! :-p I used to prefer short one-liners like that (well, still do in ruby), but in Go I'm starting to kind of enjoy the blindingly obvious, verbose way of doing it. It makes me feel like Mr. Rogers[1][2]. Sure it's plodding, but it's exceedingly clear and easy to understand. [1] http://www.youtube.com/watch?v=yXEuEUQIP3Q http://www.youtube.com/watch?v=yXEuEUQIP3Q [2] http://www.youtube.com/watch?v=Upm9LnuCBUM http://www.youtube.com/watch?v=Upm9LnuCBUM
- bad_user 14y agoOf course, you could have: def parallelWrite(data: Array[Byte]) No pointers to worry about, generics, etc ...
- azinman2 14y agoWhy not int x? :) No confusion there! Except what that actually is underlying it all. I'm actually shocked that Go even has pointers given coding C++ at Google was all about passing by reference, although at least they put a lot of sane constraints on them (no pointing to arbitrary memory addresses, no pointer arithmetic, etc). Google code style guidelines are anti-one liner, so that's not surprising to me that Go's formatter tries to enforce that. I also employ one-liners but judiciously. It can be easy to miss the condition or side effect, particularly with returns. I waffle on whether it should or shouldn't be allowed. But there's something to code compactness on large projects...
- enneff 14y agoDid you seriously just post "As someone who doesn't know how to read this language, this language seems really unreadable!" ?? As any Go programmer will tell you, Go is a very readable language. It's one of the design goals. It is _not_ a design goal to impress people making superficial judgements. Also, LOL: https://news.ycombinator.com/item?id=5327478 https://news.ycombinator.com/item?id=5327478
- jbarham 14y agoAlso, "recent PhD from the MIT Media Lab". Maybe http://scratch.mit.edu/ http://scratch.mit.edu/ is more his thing? ;)
- tikhonj 14y agoThat sort of comment is a horrible scourge on all the Haskell articles. It's somewhat surprising to see it with Go just because of how C-like Go's syntax is.
- azinman2 14y agoWhich makes it all the more odd that they kept so much of C syntax yet left out parenthesis on if statements, for example. It feels really arbitrary and doesn't seem balanced. Python did away with it but the : combined with space-sensitive scoping makes that more elegant and readable.
- azinman2 14y agoI'm hoping you're lol'ing with me and not at me, because that's a comment on the parody of HN, which is obviously a parody comment itself. Yes I did just post that. Should I wait until there's an article on coding aesthetics first? I'm a seasoned programmer with experience in many languages. Reading a new language should make me want to use it because it's an improvement in many ways, particularly around expressivity and clarity. IMHO Go isn't as good as it could be. I wasn't saying Go as a whole is bad or not worthwhile.
- monjaro 14y agoWhat a pointless complaint. Literally none of those things are real issues. Use the language for a day and it'll all be second nature.
- azinman2 14y agoDo aesthetics not matter?
- overcyn 14y agoAesthetics in the sense of an clean syntax, or minimizing language warts. Not choice of delimiters or a lack of parenthesis in certain constructs. There are literally thousands of choices the language designers made that are more important that the criticisms you brought up.
- inopinatus 14y agoI read those examples and had no trouble inferring their meaning. I have no Go experience whatsoever and have not even read the introduction or tutorial. Yet, building entirely on what I know from speaking several C-like and non-C-like languages, here's what it looks like to me: clearly c is some kind of "chan"nel-based synchronisation object for which <- is both the read & write operator (presumably blocking); the "go func" declaration is building a closure that is immediately invoked which, given this appears to be a parallelism demo, probably happens in a separate thread (green or OS unstated). m appears to be a map of string to string, so the assignment to k,v is almost certainly a tuple returned from iterator "range m" because that's just how things go in documentation-level examples. I know nobody likes a smart-ass but it's a good example and even if some of the above is wrong, I got a taste of Go from it that I rather like. So thanks.
- jbeshir 14y agoAll correct.
- kibibu 14y ago> There's also the fact that the array (I'm guessing) of bytes diverges from every other language to put them in front of the type which looks like crap. Every other language except: - Actionscript, TypeScript, Haxe var x:int = 10; - ML, OCaml, Haskell and derivatives val x : int = 10; - Pascal and derivatives Var x : Integer; - Ada and derivatives x : integer := 10; - Old-school MASM Assembly syntax DSEG segment x word - SQL CREATE TABLE tbl { x INT } - Basic Dim x as Integer - XML DTDs even <!ELEMENT x (#PCDATA)>
- azinman2 14y ago"put them in front of the type" I meant the [], not just generally the type. go: data []byte most (all?) other languages that use [] in arrays: data byte[]
- kibibu 14y agoSorry I misinterpreted. When Go was introduced a lot of people got caught up in the declaration order being opposite to C-style languages and I assumed you had too. Nevertheless, it's similar to Algol's bracket syntax, except in Algol the type comes before the variable: []INT numbers = (0, 1, 2);