gofmt alignment irritation

534 views
Skip to first unread message

Erwin

unread,
Sep 12, 2012, 7:17:13 AM9/12/12
to golang-nuts
Hello, gofmt sometimes irritates me, it "messes" up neatly aligned, for example:
(my point is only obvious when you read this mail using a monospace font)

A neatly aligned table like this:

var grid4x4 = [4][4]uint8{
{ 1,  2,  3,  4},
{ 5,  6,  7,  8},
{ 9, 10, 11, 12},
{13, 14, 15, 16},
}

turns into this, after gofmt:

var grid4x4 = [4][4]uint8{
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16},
}


Jan Mercl

unread,
Sep 12, 2012, 7:39:03 AM9/12/12
to Erwin, golang-nuts
On Wed, Sep 12, 2012 at 1:17 PM, Erwin <snes...@gmail.com> wrote:
> Hello, gofmt sometimes irritates me, it "messes" up neatly aligned, for
> example:

Except for writing the constants in octal or hex you're out of luck
(but I think it's better to have it gofmted' like this). On a loosely
related note, I miss the fixed font option which GMail used to have.

-j

Peter

unread,
Sep 12, 2012, 8:06:54 AM9/12/12
to golan...@googlegroups.com, Erwin
We can now use code blocks in this group:

var grid4x4 = [4][4]uint8{
    {1, 2, 3, 4},
   {5, 6, 7, 8},
   {9, 10, 11, 12},
   {13, 14, 15, 16},
}

Makes it look a bit nicer :)

Jan Mercl

unread,
Sep 12, 2012, 8:31:43 AM9/12/12
to Peter, golan...@googlegroups.com, Erwin
On Wed, Sep 12, 2012 at 2:06 PM, Peter <peter.a...@gmail.com> wrote:
> We can now use code blocks in this group:
>
> var grid4x4 = [4][4]uint8{
> {1, 2, 3, 4},
> {5, 6, 7, 8},
> {9, 10, 11, 12},
> {13, 14, 15, 16},
> }
>
> Makes it look a bit nicer :)

I noticed it was enabled recently. It's not exactly welcomed by me.

Strangely enough, AFAICS, it shows in a variable pitch font in GMail
(left in default settings), see attachment. (And I don't use the
Groups web interface). Also the colors... :-(

-j
sshot - 12.9.2012 - 14:19:34.png

peterGo

unread,
Sep 12, 2012, 8:38:07 AM9/12/12
to golan...@googlegroups.com
notnot,

Your formatting is hard to maintain. For example, add some three digit numbers.

    var grid4x4 = [4][4]uint8{
       
{ 1,  2,  3,  4},
       
{ 5,  6,  7,  8},
       
{ 9, 10, 11, 12},
       
{13, 14, 15, 16},

       
{101, 102, 103, 104},
   
}

Peter

Andrew Gerrand

unread,
Sep 12, 2012, 6:28:55 PM9/12/12
to Erwin, golang-nuts

Neither looks  neatly aligned to me, although neither looks bad either. They're both equally readable to my eyes.

Andrew

--
 
 
Screenshot_2012-09-13-08-26-45.png

Erwin

unread,
Sep 12, 2012, 7:25:30 PM9/12/12
to Andrew Gerrand, golang-nuts

Ok, here's a post using a monospaced font... now it looks like i meant it to look :) 

Ingo Oeser

unread,
Sep 12, 2012, 7:31:56 PM9/12/12
to golan...@googlegroups.com, Andrew Gerrand
I understand what you mean. 

In numeric math code or some 3D graphics code I have seen this before. 
But most modern production code has it in shaders (3D use case) or in some input/config files (numeric math use case).

There you can use any formatting you like :-)

Kevin Gillette

unread,
Sep 15, 2012, 2:52:09 PM9/15/12
to golan...@googlegroups.com
This is one place it may have been nice to depart from Go convention for octal int literals, instead taking, for example, 0o777 (lower case oh), while treating leading zeros as decimal.  otoh, mixing zeros and 'o's is usually a bad idea.

Taro Urashima

unread,
Sep 15, 2012, 5:10:39 PM9/15/12
to Kevin Gillette, golan...@googlegroups.com

Not if you are using the correct font for programming in, above is a screen grab of Monospace on Ubuntu.Consolas on Windows does the same if I recall correctly. Easy to tell the difference between 0 and o - seems to work with Courier New as well.

ROuNIN

On 15 September 2012 19:52, Kevin Gillette <extempor...@gmail.com> wrote:
This is one place it may have been nice to depart from Go convention for octal int literals, instead taking, for example, 0o777 (lower case oh), while treating leading zeros as decimal.  otoh, mixing zeros and 'o's is usually a bad idea.

--
 
 

Kevin Gillette

unread,
Sep 15, 2012, 5:58:58 PM9/15/12
to golan...@googlegroups.com, Kevin Gillette
Yeah, but since 0Xff is allowed as well as 0xff, it would stand to reason that 0O777 would be allowed as well. Capital Oh and zero are less clearly distinguishable than zero and the lowercase oh.

si guy

unread,
Sep 16, 2012, 6:28:22 PM9/16/12
to golan...@googlegroups.com
That's why I went through my fonts used and replaced all the zeros with naught symbols (zero with a diagonal slash through it) a useful trick for making octal and the like more readable.

Michael Jones

unread,
Sep 16, 2012, 6:48:00 PM9/16/12
to si guy, golan...@googlegroups.com

How readable is il1 in your font?

On Sep 16, 2012 3:28 PM, "si guy" <sjw...@gmail.com> wrote:
That's why I went through my fonts used and replaced all the zeros with naught symbols (zero with a diagonal slash through it) a useful trick for making octal and the like more readable.

--


Reply all
Reply to author
Forward
0 new messages