Go Playground Syntax Highlighting

26,571 views
Skip to first unread message

Torrance Hodgson

unread,
Oct 24, 2012, 8:04:42 PM10/24/12
to golan...@googlegroups.com
Hi!

The Go playground is a really great way to share code, but sometimes it's a little difficult to read. I wonder how difficult it would be to add automatic syntax highlighting?

Solarized light would probably be one of the more pleasant colour schemes that keeps closest to the current color scheme.

Cheers,
Torrance

andrey mirtchovski

unread,
Oct 24, 2012, 9:49:45 PM10/24/12
to Torrance Hodgson, golan...@googlegroups.com
> but sometimes it's a little difficult to read.

the only time i find the playground difficult to read is right after
i've stared at the sun too much. don't do that if you're in my
situation and you'll be fine.

bryanturley

unread,
Oct 26, 2012, 2:28:28 PM10/26/12
to golan...@googlegroups.com
I don't think you can change text color of individual characters inside a <textarea>.
Assuming it is using a textarea...
Also I only ever use simple html so maybe someone else knows some voodoo.
Maybe copy/paste or a download button so you can open it in your own editor would be better?

Herbert Fischer

unread,
Oct 26, 2012, 2:41:25 PM10/26/12
to bryanturley, golan...@googlegroups.com
tour.google.com has syntax highlighting. 

Usually I prefer to use the tour instead of "play" just because of this.

--
 
 

Rob Pike

unread,
Oct 26, 2012, 2:45:28 PM10/26/12
to Herbert Fischer, bryanturley, golan...@googlegroups.com
Gofmt was written to reduce the number of pointless discussions about
code formatting. It succeeded admirably. I'm sad to say it had no
effect whatsoever on the number of pointless discussions about syntax
highlighting, or as I prefer to call it, spitzensparken
blinkelichtzen.

One step at a time.

-rob

DisposaBoy

unread,
Oct 26, 2012, 2:46:52 PM10/26/12
to golan...@googlegroups.com, bryanturley


On Friday, October 26, 2012 7:42:03 PM UTC+1, Herbert G. Fischer wrote:
tour.google.com has syntax highlighting. 

Usually I prefer to use the tour instead of "play" just because of this.


Why not just use a proper text editor?

Francesc Campoy Flores

unread,
Oct 26, 2012, 3:11:20 PM10/26/12
to Herbert Fischer, bryanturley, golan...@googlegroups.com
Hi Herbert,

tour.google.com? Did you mean maybe tour.golang.org?

But as far as I can see there's not syntax highlighting there either.

Cheers,
Francesc

--
 
 



--
--
Francesc

bryanturley

unread,
Oct 26, 2012, 3:15:43 PM10/26/12
to golan...@googlegroups.com
Might also be a good idea to get used to not using syntax highlighting.
If I couldn't read code without highlighting I would see that as a problem, to each his own though.
Before anyone responds in anger, I use syntax highlighting most of the time.
I was not saying don't use syntax highlighting, just don't rely on it.

Christoph Hack

unread,
Oct 26, 2012, 3:30:45 PM10/26/12
to golan...@googlegroups.com, Herbert Fischer, bryanturley
On Friday, October 26, 2012 9:11:49 PM UTC+2, Francesc Campoy Flores wrote:
But as far as I can see there's not syntax highlighting there either.

There is, but it's optional and disabled by default (because of popular demand). You can activate it in the drop-down menu to the right of the run button. 

-christoph

Francesc Campoy Flores

unread,
Oct 26, 2012, 5:38:59 PM10/26/12
to Christoph Hack, golan...@googlegroups.com, Herbert Fischer, bryanturley
Thanks, I didn't notice that before!


-christoph

--
 
 



--
--
Francesc

Christoph Hack

unread,
Oct 27, 2012, 5:11:43 PM10/27/12
to golan...@googlegroups.com, Herbert Fischer, bryanturley, luz...@gmail.com
On Saturday, October 27, 2012 10:54:35 PM UTC+2, luz...@gmail.com wrote:
'gofmt -v' would automatically insert the right ANSI terminal color escape sequences into the source code to make it visually appealing. This might be material for a future Go++.
 
We should also convert all .go files to .gox files. This files are basically .go files inside a zip container, but they have the advantage that programmers can embed their preferred font files that are needed for the highlighting directly in the source files and we also can expand the format later (for example, it might also be a good idea to include some color profiles for different output devices). All those changes would ensure that the viewing experience of Go code is as pleasing as possible.

Thomas Bushnell, BSG

unread,
Oct 27, 2012, 6:02:00 PM10/27/12
to Christoph Hack, luz...@gmail.com, golang-nuts, bryanturley, Herbert Fischer

Or even better, .goxy files, which add to that a more Java-like syntax and automatic conversion from an exception syntax into panic with json-encoded strings and also generic syntax. Of course the result is so unwieldy that you need an eclipse-like IDE to keep track of everything, which will need another layer of "gen" metadata to hold information about generic dependencies.

It seems a lot, but I think with the resulting .goxygen files we will finally be able to breathe easier.

Thomas

--
 
 

Jackie Li

unread,
Oct 27, 2012, 6:06:25 PM10/27/12
to Thomas Bushnell, BSG, Christoph Hack, luz...@gmail.com, golang-nuts, bryanturley, Herbert Fischer
I think I get the joke!

--
 
 



--
Jackie

Rob Pike

unread,
Oct 28, 2012, 1:08:49 AM10/28/12
to Jackie Li, Thomas Bushnell, BSG, Christoph Hack, luz...@gmail.com, golang-nuts, bryanturley, Herbert Fischer
Syntax highlighting is juvenile. When I was a child, I was taught
arithmetic using colored rods
(http://en.wikipedia.org/wiki/Cuisenaire_rods). I grew up and today I
use monochromatic numerals.

-rob

si guy

unread,
Oct 28, 2012, 3:28:43 AM10/28/12
to golan...@googlegroups.com
The most relavent highlight for me is making all := declarations another color, mainly because I'm very farsighted and sometimes I miss the little colon even with glasses on. I think SH has importance to other people with poor vision as well, as an accessibility feature. Color schemes aren't important as long as they're high contrast.

Making my font huge isn't always an option.

bryanturley

unread,
Oct 28, 2012, 4:38:43 AM10/28/12
to golan...@googlegroups.com

I agree, you kids need to get off our monochromatic grass.

Best golang-nuts thread ever ;)
 

Job van der Zwan

unread,
Oct 28, 2012, 5:58:18 AM10/28/12
to golan...@googlegroups.com
On Sunday, 28 October 2012 08:28:43 UTC+1, si guy wrote:
The most relavent highlight for me is making all := declarations another color, mainly because I'm very farsighted and sometimes I miss the little colon even with glasses on. I think SH has importance to other people with poor vision as well, as an accessibility feature. Color schemes aren't important as long as they're high contrast.

Making my font huge isn't always an option.

I second the := and = distinction. Also, being able to immediately see when I forgot a closing " or ` or ' is great. What I like about SH in general is the ability to help me spot basic patterns like this. What I dislike (and what I suppose simply weighs heavier for its detractors) is how it can add cognitive load to my reading process. That's probably also why the opposite is true for me when it comes to contrast in SH colour schemes: I love zenburn for it's low-contrast. And I'm red-green colourblind, so it's extra low-contrast for me.

... as an aside, I'm kind of curious now if automated syntax highlighting is doable for natural languages (subject/object/verb, that sort of thing) and what it would look like.

Lucio

unread,
Oct 28, 2012, 10:04:57 AM10/28/12
to golan...@googlegroups.com, Christoph Hack, Herbert Fischer, bryanturley
It wasn't there before, you might have last looked before it was added, quite recently.

Herbert Fischer

unread,
Oct 28, 2012, 12:02:10 PM10/28/12
to DisposaBoy, golan...@googlegroups.com, bryanturley
I do. I was just giving a choice to the person who opened this thread. Sometimes when I want to try something quick, I use the tour, just some sort of "interactive mode".

--
 
 

Herbert Fischer

unread,
Oct 28, 2012, 12:03:09 PM10/28/12
to Francesc Campoy Flores, bryanturley, golan...@googlegroups.com
Yeah. Sorry for the the "autocomplete" of my tablet... :)

Just click in the arrow right to the "RUN" button and you will see.

Herbert Fischer

unread,
Oct 28, 2012, 12:12:37 PM10/28/12
to Torrance Hodgson, golan...@googlegroups.com
After reading this thread I suppose "syntax highlighting" is too mainstream.

Better to use text mode without ANSI colors then. ;)

Thomas Bushnell, BSG

unread,
Oct 28, 2012, 12:35:01 PM10/28/12
to Rob Pike, golang-nuts, bryanturley, Jackie Li, luz...@gmail.com, Christoph Hack, Herbert Fischer

I loved Cuisenaire rods! Wow, haven't thought about them in like 35 years....

Ingo Oeser

unread,
Oct 28, 2012, 4:56:32 PM10/28/12
to golan...@googlegroups.com
If you are just working with beautifully engineered code in a few languages and grammars, most of it written by your own or at least to your standards, I agree.

My own use case has always been crappy "commercial grade" code written with IDEs and terminals of 200 glyphs wide. Heavy use of ifdef at multiple levels and stuff like code embedded in other languages code (e.g. templates) are the norm.

Add DSLs and the meriad of unix config file languages to the mix and I will proudly confess, that I don't know all those grammars well enough and don't even want to. So I let my editor identify things like keywords, bad white space (Makefiles, Python, shell), strings, escape sequences, comment paragraphs, embedded code fragments in templates and ifdefed out code.

Found many bugs directly after opening the editor while more senior people stared hours at it.

Call me retarded idiot, but it just saved me and my colleagues a lot of time during the last 25 years of coding :-)

bugpowder

unread,
Oct 29, 2012, 12:21:57 PM10/29/12
to golan...@googlegroups.com, Jackie Li, Thomas Bushnell, BSG, Christoph Hack, luz...@gmail.com, bryanturley, Herbert Fischer
Yes, and we should all use Acme --or, wait, isn't mouse chording juvenile too? 

When I was a child, I used programming editors with mouse actions. I grew up and today I use Emacs.

Different strokes for different folks is what I'm getting at. 

Plus, in a field where 3 out of 4 large software projects fail to deliver on time or at all, we can use all the contextual help we can from our editors. 

stevewang

unread,
Oct 29, 2012, 12:57:56 PM10/29/12
to golan...@googlegroups.com
Well, this is a topic on which people will never reach consensus.
So I prefer to look for my favorite editors rather than fight over it.

bryanturley

unread,
Oct 29, 2012, 1:05:09 PM10/29/12
to golan...@googlegroups.com
On Monday, October 29, 2012 11:57:56 AM UTC-5, stevewang wrote:
Well, this is a topic on which people will never reach consensus.
So I prefer to look for my favorite editors rather than fight over it.

The New Holy War
Syntax Highlighting on http://play.golang.org.
 

minux

unread,
Oct 29, 2012, 1:33:05 PM10/29/12
to bryanturley, golan...@googlegroups.com
I'm just about to say i regret the Go authors don't specify a canonical syntax
highlighting scheme for Go, and then I realize that they did specific one, which
is: no syntax highlighting at all -- just look at gofmt's output and you will know
that.

Rob Pike

unread,
Oct 29, 2012, 1:36:08 PM10/29/12
to bryanturley, golan...@googlegroups.com
When I was a child, I used to speak like a child, think like a child,
reason like a child; when I became a man, I did away with childish
things.

-rob

Joe Farro

unread,
Oct 29, 2012, 9:21:53 PM10/29/12
to golan...@googlegroups.com, bryanturley
Looks to me like your remark was designed to be degrading. Pure and simple. This sort of approach fosters an attitude of arrogance and intolerance in the community. This is very unfortunate considering you're such an influential member. 

Jonathan Langevin

unread,
Oct 29, 2012, 9:51:31 PM10/29/12
to Joe Farro, golan...@googlegroups.com, bryanturley
It keeps the theme of his prior comment regarding Cuisenaire rods.
At least it's consistent with his other replies :-)

--
 
 

Rob Pike

unread,
Oct 29, 2012, 9:53:26 PM10/29/12
to Joe Farro, golan...@googlegroups.com, bryanturley
Hey, I was quoting the Bible. If that's degrading, I guess I'm done.

-rob

Patrick Mylund Nielsen

unread,
Oct 29, 2012, 9:58:30 PM10/29/12
to Rob Pike, Joe Farro, golan...@googlegroups.com, bryanturley
Looks to me like your remark was designed to be degrading. Pure and simple. This sort of approach fosters an attitude of arrogance and intolerance in the community. This is very unfortunate considering you're such an influential member. 

I hope you don't use Linux. At least he didn't make remarks about monkeys doing stuff to themselves.

If Jesus rose from the grave and told me syntax highlighting was an abomination, I would still use it. Doesn't matter if somebody with a Wikipedia page frowns on its use. It makes it easier for me to write programs. You don't need everybody else to agree. EOD.

On Tue, Oct 30, 2012 at 2:53 AM, Rob Pike <r...@golang.org> wrote:
Hey, I was quoting the Bible. If that's degrading, I guess I'm done.

-rob

--



bryanturley

unread,
Oct 29, 2012, 11:04:28 PM10/29/12
to golan...@googlegroups.com, Rob Pike, Joe Farro, bryanturley
Looks like you hit a nerve. I wonder what color it was...

mattn

unread,
Oct 29, 2012, 11:21:01 PM10/29/12
to golan...@googlegroups.com
How about using Google Code Prettify?


But, it is applied for static element not textarea. So when you click the code, it should replace it to textarea.

Patrick Mylund Nielsen

unread,
Oct 29, 2012, 11:26:32 PM10/29/12
to bryanturley, golan...@googlegroups.com, Rob Pike, Joe Farro
Just hoping people will make up their own mind about what they want to use. If arguments from authority were all that important, we'd all be browsing the web using smtp and wget.

On Tue, Oct 30, 2012 at 4:04 AM, bryanturley <bryan...@gmail.com> wrote:
Looks like you hit a nerve. I wonder what color it was...

--
 
 

Tim Harig

unread,
Oct 29, 2012, 11:27:48 PM10/29/12
to golang-nuts
On Mon, Oct 29, 2012 at 06:21:53PM -0700, Joe Farro wrote:
> Looks to me like your remark was designed to be degrading. Pure and simple.
> This sort of approach fosters an attitude of arrogance and intolerance in
> the community. This is very unfortunate considering you're such an
> influential member.

Yes, his comments where meant to be degrading -- no matter what their
source and original context. I, approaching my 40th year, am truly
a child compared to the venerable Mr. Pike. The statements say more
about his age than they do about mine. Far from being insulted, I am
a little depressed that a giant such as Mr. Pike has reached an age
when he dismisses ideas, less from their merit, than based on his own
long-ingrained habits and nostalgia.

As for the subject of syntax highlighting, I suspect that most of use
syntax highlighting in our editors. It is not a question of necessity,
it just makes reading code more pleasant. Then again, since the site in
question require opening a web browser window, I often avoid reading code
placed on the go playground. Maybe someday when I have a little time,
I will write an extension that pulls the codes from the playground and
embeds it back into the e-mail body. Then I can syntax highlight it as
I wish.

Dustin

unread,
Oct 29, 2012, 11:41:02 PM10/29/12
to golan...@googlegroups.com, timh...@gmx.com

On Monday, October 29, 2012 8:28:28 PM UTC-7, Tim Harig wrote:

Yes, his comments where meant to be degrading -- no matter what their
source and original context.  I, approaching my 40th year, am truly
a child compared to the venerable Mr. Pike.  The statements say more
about his age than they do about mine.  Far from being insulted, I am
a little depressed that a giant such as Mr. Pike has reached an age
when he dismisses ideas, less from their merit, than based on his own
long-ingrained habits and nostalgia.

  I'm neither insulted by the color of his jackets nor his web sites.  I failed to see the part of the thread where he said you can't make your own software and put your own colors on it.  Otherwise, you're having an emotional response to someone's unwillingness to paint something he made and gave to the world colors you find favorable.

  In less time than I spent trying to find the "mute this discussion" button, I could've written a colorizing/code running pastebin, but like most people in this thread, I don't actually care enough about the topic to make something better.

andrey mirtchovski

unread,
Oct 29, 2012, 11:43:16 PM10/29/12
to Tim Harig, golang-nuts
> Maybe someday when I have a little time,
> I will write an extension that pulls the codes from the playground and
> embeds it back into the e-mail body. Then I can syntax highlight it as
> I wish.

... after you make sure you strip the original syntax highlighting
embedded in the HTML.

here's how the golang "hello world" looks on one of those fancy paste sites:

import <span class='string string_quoted string_quoted_double
string_quoted_double_ruby'>&quot;fmt&quot;</span>

func main() {<span class='meta meta_syntax meta_syntax_ruby
meta_syntax_ruby_start-block'></span>
fmt.<span class='variable variable_other variable_other_constant
variable_other_constant_ruby'>Println</span>(<span class='string
string_quoted string_quoted_double
string_quoted_double_ruby'>&quot;Hello, playground&quot;</span>)
}

even clicking the 'raw' button doesn't help much. the resulting html
renders without fanciness, but is still not very parseable:

package main<br/><br/>import &quot;fmt&quot;<br/><br/>func main()
{<br/> fmt.Println(&quot;Hello, playground&quot;)<br/>}<br/>

clicking 'download' results in a file with a .rb extension saved
somewhere on my computer. because ruby's is the default color
highlighting scheme for that particular site, why not assume that if i
hadn't chosen anything then i, of course, have chosen ruby?

Ross Salas

unread,
Oct 29, 2012, 11:30:46 PM10/29/12
to Tim Harig, golang-nuts
this Go community is small enough as it is... I'm setting down some rules to keep a tighter community...

no discussion about:
religion
politics
syntax hilighting

EOD (I just learned that TLA tonight)

Let's stay focused guys...

Tim Harig

unread,
Oct 30, 2012, 12:36:11 AM10/30/12
to golang-nuts
On Mon, Oct 29, 2012 at 09:43:16PM -0600, andrey mirtchovski wrote:
> > Maybe someday when I have a little time,
> > I will write an extension that pulls the codes from the playground and
> > embeds it back into the e-mail body. Then I can syntax highlight it as
> > I wish.
>
> import <span class='string string_quoted string_quoted_double
> string_quoted_double_ruby'>&quot;fmt&quot;</span>
>
> func main() {<span class='meta meta_syntax meta_syntax_ruby
> meta_syntax_ruby_start-block'></span>
> fmt.<span class='variable variable_other variable_other_constant
> variable_other_constant_ruby'>Println</span>(<span class='string
> string_quoted string_quoted_double
> string_quoted_double_ruby'>&quot;Hello, playground&quot;</span>)
> }
>
> even clicking the 'raw' button doesn't help much. the resulting html
> renders without fanciness, but is still not very parseable:

Actually, I don't think that would be so difficult as long as the markup is
well formed. A simple state machine can be used to extract data that
is not inside of tags. The standard lib has UnescapeString() for removing
the entities. Some care might need to be used for dealing with line breaks
and other whitespace but, it isn't nearly as large of a problem as it might
be a language like Python that is so white space sensitive.

Tim Harig

unread,
Oct 30, 2012, 12:53:51 AM10/30/12
to golang-nuts
On Mon, Oct 29, 2012 at 08:41:02PM -0700, Dustin wrote:
>
> On Monday, October 29, 2012 8:28:28 PM UTC-7, Tim Harig wrote:
> software and put your own colors on it. Otherwise, you're having an
> emotional response to someone's unwillingness to paint something he made
> and gave to the world colors you find favorable.

As I indicated in my post, I don't use the website or others like it.
I avoid it as much as possible and indicated that I may write software
so I don't even have to visit it to see code that is posted there from
this list. As such, I really do not care whether the site has syntax
highlighting or not.

Aram Hăvărneanu

unread,
Oct 30, 2012, 4:30:46 AM10/30/12
to Tim Harig, golang-nuts
> I suspect that most of use
> syntax highlighting in our editors. It is not a question of necessity,
> it just makes reading code more pleasant.

I'm sure crack makes life more "pleasant" as well. That's no argument.

--
Aram Hăvărneanu

Andrew Gerrand

unread,
Oct 30, 2012, 5:58:38 AM10/30/12
to Tim Harig, golang-nuts
On 30 October 2012 14:27, Tim Harig <timh...@gmx.com> wrote:
> On Mon, Oct 29, 2012 at 06:21:53PM -0700, Joe Farro wrote:
>> Looks to me like your remark was designed to be degrading. Pure and simple.
>> This sort of approach fosters an attitude of arrogance and intolerance in
>> the community. This is very unfortunate considering you're such an
>> influential member.
>
> Yes, his comments where meant to be degrading -- no matter what their
> source and original context.

It's obvious to me that Rob was just riffing on the "When I was a
child" refrain that recurred a few times in this thread. I thought it
was kind of funny, and it's not like the thread was going anywhere.
Nothing new has been said here.

> As for the subject of syntax highlighting, I suspect that most of use
> syntax highlighting in our editors. It is not a question of necessity,
> it just makes reading code more pleasant.

For you, sure. Others find it distracting. It's all about personal taste.

> Then again, since the site in
> question require opening a web browser window, I often avoid reading code
> placed on the go playground.

Your views on opening browser windows surely put you in a smaller
minority group than Rob's views on syntax highlighting. Furthermore,
if you don't even USE the playground then why are you posting
inflammatory messages to this thread? Just for fun?

For the record: Christoph Hack said he was going to prepare a change
to restore the more sophisticated editor to the playground. This would
include a syntax highlighting option that defaults to "off" (as per
the tour). If this change can be made without any regressions then it
will be accepted.

Now, can we please stop talking about this?

Andrew

antoni...@gmail.com

unread,
Dec 4, 2016, 12:01:34 AM12/4/16
to golang-nuts, tux...@gmail.com, herbert...@gmail.com, bryan...@gmail.com
Last time I checked, I can still activate it (the syntax highlighting) in the drop-down menu. 

Now the syntax highlighting drop-down menu is no longer there, right? 
I'm using chromium-browser under Linux. 

On Sunday, October 28, 2012 at 10:04:57 AM UTC-4, Lucio wrote:
It wasn't there before, you might have last looked before it was added, quite recently.

On Friday, 26 October 2012 23:39:36 UTC+2, Francesc Campoy Flores wrote:
Thanks, I didn't notice that before!

On Fri, Oct 26, 2012 at 12:30 PM, Christoph Hack <tux...@gmail.com> wrote:
On Friday, October 26, 2012 9:11:49 PM UTC+2, Francesc Campoy Flores wrote:
But as far as I can see there's not syntax highlighting there either.

There is, but it's optional and disabled by default (because of popular demand). You can activate it in the drop-down menu to the right of the run button. 

-christoph

--
 
 



--
--
Francesc

lfa...@me.com

unread,
Jul 4, 2017, 5:04:15 PM7/4/17
to golang-nuts
Use a font like FiraCode and enable 'ligatures' in your editor so := and = will be noticeably distinct.

On Sunday, October 28, 2012 at 10:58:18 AM UTC+1, Job van der Zwan wrote:
On Sunday, 28 October 2012 08:28:43 UTC+1, si guy wrote:
The most relavent highlight for me is making all := declarations another color, mainly because I'm very farsighted and sometimes I miss the little colon even with glasses on. I think SH has importance to other people with poor vision as well, as an accessibility feature. Color schemes aren't important as long as they're high contrast.

Making my font huge isn't always an option.

I second the := and = distinction. Also, being able to immediately see when I forgot a closing " or ` or ' is great. What I like about SH in general is the ability to help me spot basic patterns like this. What I dislike (and what I suppose simply weighs heavier for its detractors) is how it can add cognitive load to my reading process. That's probably also why the opposite is true for me when it comes to contrast in SH colour schemes: I love zenburn for it's low-contrast. And I'm red-green colourblind, so it's extra low-contrast for me.

... as an aside, I'm kind of curious now if automated syntax highlighting is doable for natural languages (subject/object/verb, that sort of thing) and what it would look like.
Reply all
Reply to author
Forward
0 new messages