Line wrapping and the lack of some convention

124 views
Skip to first unread message

Sotirios Mantziaris

unread,
Sep 5, 2019, 1:58:49 PM9/5/19
to golang-nuts
Hi,

I would liked that gofmt would handle this one also in order to avoid battles about what is the correct line wrapping in go.

In Effective Go there is a section, with smaller fonts than the usual document that states:

Line length
Go has no line length limit. Don't worry about overflowing a punched card. If a line feels too long, wrap it and indent with an extra tab.

The above line leaves a lot of room for interpretation:

Assume you have something lengthy, which is also left for interpretation, you should wrap and ident with an extra tab:

Now I have the following outcomes:

shinyThing := New(argument1 string, argument2 string, argument3 string,
  argument4
string, argument5 string)


you have

shinyThing  := New(
  argument1
string,
  argument2
string,
  argument3
string,
  argument4
string,
  argument5
string
)

and there are possibly 100 more variations out there.

I personally prefer the first one because I use as much horizontal space as I can (i have a limit for 120 chars per line) and I use as little as possible vertical space in order to not need to scroll. I optimize for having as much as possible in one screen.

Does anybody have a convention that is generally accepted for this?
Would this make sense to be part of gofmt?

Ian Lance Taylor

unread,
Sep 5, 2019, 7:21:29 PM9/5/19
to Sotirios Mantziaris, golang-nuts
On Thu, Sep 5, 2019 at 10:59 AM Sotirios Mantziaris
<smant...@gmail.com> wrote:
>
> I would liked that gofmt would handle this one also in order to avoid battles about what is the correct line wrapping in go.
>
> In Effective Go there is a section, with smaller fonts than the usual document that states:
>
> Line lengthGo has no line length limit. Don't worry about overflowing a punched card. If a line feels too long, wrap it and indent with an extra tab.
>
> The above line leaves a lot of room for interpretation:
>
> Assume you have something lengthy, which is also left for interpretation, you should wrap and ident with an extra tab:
>
> Now I have the following outcomes:
>
> shinyThing := New(argument1 string, argument2 string, argument3 string,
> argument4 string, argument5 string)
>
>
> you have
>
> shinyThing := New(
> argument1 string,
> argument2 string,
> argument3 string,
> argument4 string,
> argument5 string
> )
>
> and there are possibly 100 more variations out there.
>
> I personally prefer the first one because I use as much horizontal space as I can (i have a limit for 120 chars per line) and I use as little as possible vertical space in order to not need to scroll. I optimize for having as much as possible in one screen.
>
> Does anybody have a convention that is generally accepted for this?

There is some discussion at
https://golang.org/wiki/CodeReviewComments#line-length .

> Would this make sense to be part of gofmt?

I don't think so, because good line breaks require semantic knowledge
that gofmt doesn't have.

Ian

Sotirios Mantziaris

unread,
Sep 7, 2019, 8:22:42 AM9/7/19
to Ian Lance Taylor, golang-nuts
Thanks for the link, this clears things out a bit.
--
Regards,

S. Mantziaris
Reply all
Reply to author
Forward
0 new messages