OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 30, 2017 12:40 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Better Code Highlighting
PostPosted: Tue Aug 13, 2013 12:58 am 
Offline
Member
Member

Joined: Mon Jan 31, 2011 6:07 pm
Posts: 58
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


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Tue Aug 13, 2013 1:21 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9228
Location: An der schönen blauen Donau, watching muppets
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 ]


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Tue Aug 13, 2013 1:32 am 
Offline
Member
Member

Joined: Mon Jan 31, 2011 6:07 pm
Posts: 58
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


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Tue Aug 13, 2013 1:43 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1046
Location: Germany
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)


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Tue Aug 13, 2013 1:48 am 
Offline
Member
Member

Joined: Mon Jan 31, 2011 6:07 pm
Posts: 58
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


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Tue Aug 13, 2013 3:26 am 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1702
Location: Hong Kong
You should narrow down the scope and avoid posting long code in the first place.
Code:
If (SLOC() < 10) {
  YouDontNeedColor = true;
} else {
  TL();DR();
}

_________________
We choose to OSDev and do the other things, not because they are easy but because they are hard.
> Bluemoon OS: [Description] [Screenshot 32-bit] [Screenshot 64-bit]


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Tue Aug 13, 2013 11:53 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 27, 2010 4:53 pm
Posts: 926
Location: Scotland
Combuster wrote:
(Also, green text? Where? :wink:)

Code:
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.

_________________
When AGI takes over the world, every house with ivory or rhino horn in it will be burned to the ground.

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Tue Aug 13, 2013 11:25 pm 
Offline
Member
Member

Joined: Mon Jan 31, 2011 6:07 pm
Posts: 58
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


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Wed Aug 14, 2013 8:47 pm 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2561
Location: Sydney, Australia (I come from a land down under!)
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).

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Thu Aug 15, 2013 9:27 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 2665
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Fri Aug 16, 2013 4:56 am 
Offline
Member
Member

Joined: Mon Jan 31, 2011 6:07 pm
Posts: 58
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


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Fri Aug 16, 2013 5:38 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1019
Location: Tartu, Estonia
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 // SF user: xenos1984; OS project: XeNOS


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Fri Aug 16, 2013 8:40 am 
Offline
Member
Member

Joined: Mon Dec 17, 2012 9:12 am
Posts: 112
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.


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Sat Aug 17, 2013 5:45 pm 
Offline
Member
Member

Joined: Mon Jan 31, 2011 6:07 pm
Posts: 58
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


Top
 Profile  
 
 Post subject: Re: Better Code Highlighting
PostPosted: Sun Aug 18, 2013 12:08 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 2665
Location: Chichester, UK
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group