Better Code Highlighting

Questions, comments, and suggestions about this site should go here.
phillid
Member
Member
Posts: 58
Joined: Mon Jan 31, 2011 6:07 pm

Better Code Highlighting

Post by phillid »

Currently, I've noticed that the only highlighting of code on the forum is that it's put in green text. Could we use some means of syntax-highlighting code inside [code] tags? I understand that it might take a bit of work thanks to different languages - and especially assembly with all its syntax-variants and processor types...

Just a thought.
Cheers
phillid - Newbie-ish operating system developer with a toy OS on the main burner
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Freenode IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Better Code Highlighting

Post by Combuster »

You'll be getting quite a source of nuisance if you are ever going to try to implement this properly:
Forum Rules wrote:6: Please try to write legibly
(...) Use [code][/code] tags when posting code. Use indentation and source comments. Use a spell checker. Don't use colours - not everybody uses the same theme and colouring your text might render it invisible. (...)


(Also, green text? Where? :wink:)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
phillid
Member
Member
Posts: 58
Joined: Mon Jan 31, 2011 6:07 pm

Re: Better Code Highlighting

Post by phillid »

Okay, I see a point there, but that aside, surely highlighted code would be better? Couldn't we put a neutral colour choice like white or black for code block backgrounds and do the highlighting from there?
phillid - Newbie-ish operating system developer with a toy OS on the main burner
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Better Code Highlighting

Post by Kevin »

In theory the highlighting colours could be specific to each theme. Not sure what extensions exist and how hard it would be to set up, though.
Developer of tyndur - community OS of Lowlevel (German)
phillid
Member
Member
Posts: 58
Joined: Mon Jan 31, 2011 6:07 pm

Re: Better Code Highlighting

Post by phillid »

I'm not aware of any PHPBB-specific plugins, but a quick Google Search would deal with my ignorance. I've used one or two non-PHPBB-plugins before, and I hear Prettify is supposed to be quite good.
phillid - Newbie-ish operating system developer with a toy OS on the main burner
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Better Code Highlighting

Post by bluemoon »

You should narrow down the scope and avoid posting long code in the first place.

Code: Select all

If (SLOC() < 10) {
  YouDontNeedColor = true;
} else {
  TL();DR();
}
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Better Code Highlighting

Post by DavidCooper »

Combuster wrote:(Also, green text? Where? :wink:)

Code: Select all

If (SLOC() < 10) {
  YouDontNeedColor = true;
} else {
  TL();DR();
}

I hadn't noticed this before. The above code doesn't look green, until you scroll it, and then it turns green while it's moving.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
phillid
Member
Member
Posts: 58
Joined: Mon Jan 31, 2011 6:07 pm

Re: Better Code Highlighting

Post by phillid »

bluemoon wrote:You should narrow down the scope and avoid posting long code in the first place.


Correct, but sometimes long-ish code may need to be posted. Plus highlighting would make languages like assembly easier to read for example.
phillid - Newbie-ish operating system developer with a toy OS on the main burner
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Freenode IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Better Code Highlighting

Post by pcmattman »

phillid wrote:Currently, I've noticed that the only highlighting of code on the forum is that it's put in green text.


Alas, code in my code tags is white. That is to say, any syntax highlighting solution must integrate nicely with the multiple themes this board supports. But Combuster basically said that already.

I also use the theme I do specifically because it's dark, it would be awfully disconcerting to have every code block suddenly became bright white in background (assuming a 'global' scheme was decided upon, irrespective of theme).
User avatar
iansjack
Member
Member
Posts: 4604
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Better Code Highlighting

Post by iansjack »

I'm not convinced that syntax highlighting would be useful. It serves a purpose in a code editor, helping to make errors stand out, but that shouldn't be necessary here, assuming the OP has already checked for syntax errors.

Most books don't employ syntax highlighting, and I don't miss it.
phillid
Member
Member
Posts: 58
Joined: Mon Jan 31, 2011 6:07 pm

Re: Better Code Highlighting

Post by phillid »

pcmattman wrote:it would be awfully disconcerting to have every code block suddenly became bright white in background

Fair enough. To cater for those who use dark themes, the background colour of a code segment could be dark for a dark theme and light for a light theme. Admittedly, that would cause problems with, say, black parts of code on that dark background of the code segment, but it'd be easy for such text's colour to be changed depending on the theme.

iansjack wrote:It serves a purpose in a code editor, helping to make errors stand out...

Correct, but how does it make errors more apparent? By making it more readable by, for example, making (valid) types of variables stand out better, mathematical operations a different colour from values around the operators, and so on. I believe that it would make the 'consumption' of code much more efficient.
phillid - Newbie-ish operating system developer with a toy OS on the main burner
User avatar
xenos
Member
Member
Posts: 1115
Joined: Thu Aug 11, 2005 11:00 pm
Freenode IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Better Code Highlighting

Post by xenos »

I also think that highlighting improves the readability of code, both in an editor and here in the forum or the wiki (where we already have some nice highlighting, and if it works there, why not in the forum as well?). When I read some code in the wiki or elsewhere on the web I'm usually happy when I see immediately what's going on, and the structure becomes clear. Highlighting helps in this scenario.

I'm not 100% familiar with how PHPBB styles work, or how those syntax highlighting plugins work. But if one had a plugin that simply puts some <span class="keyword">...</span> around keywords (and similar for variables, functions, types, asm stuff, strings etc.), and if each style simply comes with a CSS file with all the color definitions, it shouldn't be too hard to come up with, say, one highlighting color scheme for dark styles and one for bright styles, that one could copy into the CSS style definitions.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

Re: Better Code Highlighting

Post by HugeCode »

Well, it's true that users use different styles, but I think that another special bbcode for code part (as a keyword alone in text or some constant) would be good. It wouldn't be full code highlighting, but it would serve for explaining code. Currently, when somebody adds code to his post and he has some mistake in name of variable or keyword, other refer it using italic text or ``, ' '. On CodeProject, there's special var button for it. I think in administrator control panel of phpBB there are settings for BBcodes.
phillid
Member
Member
Posts: 58
Joined: Mon Jan 31, 2011 6:07 pm

Re: Better Code Highlighting

Post by phillid »

iansjack wrote:Most books don't employ syntax highlighting

That'd be due to the fact that a lot of them are printed primarily in black and white, I guess. Just because they don't use it doesn't mean that it's the best option, especially on a different medium. On the web, it's easier and not at all more expensive (Unless you're going to start talking about a few extra KB of internet usage :roll: ) to publish in colour, so why not do it?

Oh well, you're entitled to your opinion :D
phillid - Newbie-ish operating system developer with a toy OS on the main burner
User avatar
iansjack
Member
Member
Posts: 4604
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Better Code Highlighting

Post by iansjack »

phillid wrote:Oh well, you're entitled to your opinion :D
That's very generous of you.

If such a facility were ever to be implemented then I would hope it would be a user-configurable option. I would find it distracting and I can see it causing all sorts of problem with some browser/display setups. I think here of those nasty versions of xterm that do colour coding and can end up with near-invisible text.
Post Reply