Live data from Hacker News

Go Lang: Comments Are Not Directives

news.ycombinator.com

91–100 of 222 posts

Re: Go Lang: Comments Are Not Directives

#91
post #8

Want to know what's even worse? Using comments for something but not parsing the syntax tree . In go 1.4, save the following to a file and run 'go generate' on it: https://play.golang.org/p/9WJtxClRXr (I'd make it run in the playground, but you can't 'fork exec', so exec.Command($GOBIN, generate) won't work sadly) Even though that code has no comments (only a multi-line string), go generate will run and print out a '…

"Go often prefers pain for the programmer for the compiler developer's life being simpler by about 5 minutes."

Interesting contrast to the philosophy of Perl 6: 'torture the implementor on behalf of the user'.

Re: Go Lang: Comments Are Not Directives

#92
post #60
post #4

Earlier quoted context omitted.

> Go generate is just sweeping issues under the carpet and say to developers "it has been dealt with", which is ,at the minimum, insulting. Nobody expects a language to be perfect, but sometimes I feel the Go team takes devs for idiots with half baked solutions. That's absolutely a mischaracterisation, and a hurtful one at that because we absolutely care about our developer experience. "go generate" is a mechanism fo…

(I regularly downvote comments that are negative, and leave comments explaining why I found the comment to be negative). I actually don't think this was an unfair phrasing. I had actually felt insulted when `go generate` was announced. "You're sweeping [generics et al] under the rug using comment-bound directives and telling me it's an elegant solution to problems? Do you think I'm an idiot?" Was, in fact, very close…

Well, I get quite the opposite impression of condescending with them hanging around HN and golang nuts discussing language issues. And I'm actually fine with them making the decisions in the end. Go wouldnt be as clear and productive as it is today if every request for a feature would find it's way into the language in some half-hearted manner.

Re: Go Lang: Comments Are Not Directives

#93
post #56

If you're feeling paranoid and don't have time to look up the set of magical incantations, maybe you should write your actual comments like this: // COMMENT we have to check that [...] :)

Code should not be magical. Magic is bad engeneering. Magic involving a whitespace is madness.

Re: Go Lang: Comments Are Not Directives

#94
post #75

Earlier quoted context omitted.

Go has the best and most consistent std library I have seen.

Consistent standard library? It's a crapshoot what will be an interface and what will be a struct, which is one of the fundamental features of the language. Returned error values are sometimes errors.New (e.g. io.EOF) and sometimes random fmt.Errorf strings that couldn't possibly be handled (e.g. all of tls.go basically), sometimes actual structs (e.g. PathError), and sometimes panics. If you can't even get error han…

Sorry, but I can't find what you're referencing with the "as mentioned above" on math; could you clarify?

My biggest problem with the math library was, IIRC, everything only takes float64s, which makes dealing with any of the other number types more difficult than it should be (I shouldn't need to cast an int to a float and back in order to get the max of two numbers).

Re: Go Lang: Comments Are Not Directives

#95
post #57
post #14

Earlier quoted context omitted.

That's pretty bad. I think the reason why people are so upset/surprised is because they expect better from the Go team. Sometimes it really feels like they take the lazy route without putting enough thought and polish into things. Which is amplified by the previous statements regarding for example generics where they said they wont introduce them until they find a really good way to do it but then crank out half bake…

I have been using Perl for a long time, it did not get everything right when it first rolled out its object system. Through incremental improvements and backward compatibility the language has become very stable. Go is just getting to 1.5, so I expect it to have some issues at the beginning.

That $DOLLAR fix isn't just some "issue" at the beginning as though it was a design mistake or architectural oversight. It is flat out sloppy work.

If you are creating a programming language that wants to maintain backwards compatibility surely every check in you make would be as close to perfect. No ?

Re: Go Lang: Comments Are Not Directives

#96
post #49
post #37

Earlier quoted context omitted.

Agree. Something like decorators could have been used instead.

Go is typical "hurr durr, Java an C# are obsolete" write-only code by people who only ever work on ephemeral greenfield projects with a lifetime of 3 months and therefore can tell exactly what software development is all about.

Such an inflammatory troll... Do you you even know who is involved in the Go project?

Re: Go Lang: Comments Are Not Directives

#97
post #52

Partially agreed. Directives should be visually distinct from comments and syntax should be formally defined such that compilers, code generators, editors and IDE's can use them consistently.

The compiler doesn't need to care about these directives. They don't have anything to do with the compiler. That's half the reason they're in comments. Otherwise you're just adding another kind of comment the compiler has to also ignore. The directives are pretty visually distinct. You could easily configure your editor to highlight them differently if you so chose.

1. I don't understand what you mean by "They don't have anything to do with the compiler"

https://golang.org/cmd/gc/#hdr-Compiler_Directives

2. I could keep adding syntax support as they come along and handle all the inconsistencies, but that is not a solution. It's a hack.

Re: Go Lang: Comments Are Not Directives

#98
post #75

Earlier quoted context omitted.

Go has the best and most consistent std library I have seen.

Consistent standard library? It's a crapshoot what will be an interface and what will be a struct, which is one of the fundamental features of the language. Returned error values are sometimes errors.New (e.g. io.EOF) and sometimes random fmt.Errorf strings that couldn't possibly be handled (e.g. all of tls.go basically), sometimes actual structs (e.g. PathError), and sometimes panics. If you can't even get error han…

> Returned error values are sometimes errors.New (e.g. io.EOF) and sometimes random fmt.Errorf strings that couldn't possibly be handled (e.g. all of tls.go basically), sometimes actual structs (e.g. PathError),

This is the advantage of having errors be interfaces rather than concrete values. Once you learn how to use it, it's a strength. The usage of structs that satisfy the interface (as in PathError) is clearly documented and completely predictable. If your concern is that a certain package could use a struct satisfying the interface and does not, well, one advantage of errors as interfaces is that you could propose this change without breaking the backwards compatibility guarantee.

It's really important to keep in mind that errors are adopted from error values in C, which means that their idioms and usage is inspired by that rather than by exception handling. Many new Go programmers (including me, when I started) were more familiar with exception handling in higher-level languages than error handling in idiomatic C, so it does take some getting used to.

> and sometimes panics.

Do you have any examples of the standard library using panics to signal handle-able errors (not counting cases in which the panic is recovered at the top-level in the library and never visible to the caller)?

> The math library, as mentioned above, is pretty darn iffy.

The only complaint I have had about package "math" is that all operations are defined on float64s, which can be annoying, but is far better than any alternative. That's an annoyance, but it's certainly not an inconsistency in the library.

Do you have any other examples of inconsistencies in the math package?

Re: Go Lang: Comments Are Not Directives

#99

At last! I'm not insane! I raised this on the golang dev forums and got nowhere: https://groups.google.com/d/msg/golang-dev/r4rdPdsH1Fg/yjOOz... The response was basically "we disagree" and I wandered away feeling confused that so many bright people couldn't see the problem here.

> The response was basically "we disagree" and I wandered away feeling confused that so many bright people couldn't see the problem here. That's a rather disingenuous summary given that literally the very first response is Brad Fitzpatrick from the Go team agreeing with you, acknowledging that it's unfortunate, and admitting that it can't feasibly be changed yet due to the compatibility guarantees. And then shortly a…

Actually you seem to be pretty disingenuous by ignoring the rest of the posts and focusing just on the first one. The overall tone of the thread seemed to be pretty dismissive and I doubt if a solution was proposed for Go2 that it would gain any traction.

Re: Go Lang: Comments Are Not Directives

#100
post #64
post #45

Lisp has used directives in comments in the past. Only on the first line of a file but they were parsed.

That had to be very distant past or some non-standard lisp. Common Lisp has no such feature.

That's a feature of the Lisp IDE.

File mode lines described language, the syntax (which Lisp dialect), the Package, the numeric base, the encoding, ...

Example:

    ;;; -*- Mode: lisp; Syntax: ANSI-Common-Lisp; Package: http; Base: 10 -*-
But to implement compiler directives in Common Lisp, this is not needed. That can already be done with macros and reader macros. If you for example use a macro in source code, the compiler will need to expand it. That allows arbitrary code execution during compilation.
Post reply on HN