FAQ
I thought it was quite neat that each .go file is defined to have the
package declaration always on top, followed by imports (if any) and
everything else after. It makes parsing just the package name, or imports
easier and faster since the moment you run into something in the following
group, you know the previous ended.

I'm quite surprised something similar wasn't done with the //go:generate
commands. It seems they are allowed to be absolutely anywhere in any .go
file, so `go generate` has to read through absolutely everything.

In practice, I'm seeing most //go:generate comments placed on top of
package declaration.

Due to current implementation that uses bufio.Scanner that has a 64 KB line
length limit, this places an artificial restriction on all .go files to not
contain lines longer than 64 KB, as described
in https://code.google.com/p/go/issues/detail?id=9143. No one is going to
write 64 KB lines by hand, but it may happen for other unforeseen reasons,
including copy-pasting raw string data or other generated code scenarios
(e.g. see https://github.com/jteeuwen/go-bindata/issues/60). This
limitation did not exist before Go 1.4.

Is there a good reason not to add the requirement for //go:generate
comments to be either above package clause, or above imports, or at the
very least above the rest of the program? It seems like not having such a
restriction has a lot of downsides. Thank you.

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Egon Elbre at Dec 1, 2014 at 8:58 am

    On Monday, 1 December 2014 10:32:03 UTC+2, Dmitri Shuralyov wrote:
    I thought it was quite neat that each .go file is defined to have the
    package declaration always on top, followed by imports (if any) and
    everything else after. It makes parsing just the package name, or imports
    easier and faster since the moment you run into something in the following
    group, you know the previous ended.

    I'm quite surprised something similar wasn't done with the //go:generate
    commands. It seems they are allowed to be absolutely anywhere in any .go
    file, so `go generate` has to read through absolutely everything.

    In practice, I'm seeing most //go:generate comments placed on top of
    package declaration.

    Due to current implementation that uses bufio.Scanner that has a 64 KB
    line length limit, this places an artificial restriction on all .go files
    to not contain lines longer than 64 KB, as described in
    https://code.google.com/p/go/issues/detail?id=9143. No one is going to
    write 64 KB lines by hand, but it may happen for other unforeseen reasons,
    including copy-pasting raw string data or other generated code scenarios
    (e.g. see https://github.com/jteeuwen/go-bindata/issues/60). This
    limitation did not exist before Go 1.4.

    Is there a good reason not to add the requirement for //go:generate
    comments to be either above package clause, or above imports, or at the
    very least above the rest of the program? It seems like not having such a
    restriction has a lot of downsides. Thank you.
    I'm guessing the reason is that the go generate won't be called that often
    and it's convenient to have the generate command near the thing that it's
    working on:

    //go:generate types Foo > foo_types.go
    type Foo struct {
    //...
    }

    //go:generate types Bar > bar_types.go
    type Bar struct {
    //...
    }

    //go:generate types Baz > baz_types.go
    type Baz struct {
    //...
    }

    + Egon

    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dmitri Shuralyov at Dec 2, 2014 at 4:01 am
    That's a convincing reason. Thanks for insight Egon.

    On Monday, December 1, 2014 12:58:16 AM UTC-8, Egon Elbre wrote:
    On Monday, 1 December 2014 10:32:03 UTC+2, Dmitri Shuralyov wrote:

    I thought it was quite neat that each .go file is defined to have the
    package declaration always on top, followed by imports (if any) and
    everything else after. It makes parsing just the package name, or imports
    easier and faster since the moment you run into something in the following
    group, you know the previous ended.

    I'm quite surprised something similar wasn't done with the //go:generate
    commands. It seems they are allowed to be absolutely anywhere in any .go
    file, so `go generate` has to read through absolutely everything.

    In practice, I'm seeing most //go:generate comments placed on top of
    package declaration.

    Due to current implementation that uses bufio.Scanner that has a 64 KB
    line length limit, this places an artificial restriction on all .go files
    to not contain lines longer than 64 KB, as described in
    https://code.google.com/p/go/issues/detail?id=9143. No one is going to
    write 64 KB lines by hand, but it may happen for other unforeseen reasons,
    including copy-pasting raw string data or other generated code scenarios
    (e.g. see https://github.com/jteeuwen/go-bindata/issues/60). This
    limitation did not exist before Go 1.4.

    Is there a good reason not to add the requirement for //go:generate
    comments to be either above package clause, or above imports, or at the
    very least above the rest of the program? It seems like not having such a
    restriction has a lot of downsides. Thank you.
    I'm guessing the reason is that the go generate won't be called that often
    and it's convenient to have the generate command near the thing that it's
    working on:

    //go:generate types Foo > foo_types.go
    type Foo struct {
    //...
    }

    //go:generate types Bar > bar_types.go
    type Bar struct {
    //...
    }

    //go:generate types Baz > baz_types.go
    type Baz struct {
    //...
    }

    + Egon
    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedDec 1, '14 at 8:32a
activeDec 2, '14 at 4:01a
posts3
users2
websitegolang.org

2 users in discussion

Dmitri Shuralyov: 2 posts Egon Elbre: 1 post

People

Translate

site design / logo © 2021 Grokbase