PDA

View Full Version : Proposal: Code colouring



Perspective
04-13-2007, 01:27 PM
Hey y'all, I'd like to make a proposal for the cboard.

Let me prefix this by saying that PHP code colouring looks terrible for C/C++, and C/C++ code should not be posted in PHP tags.


I think we should add a board feature, a paramater for code tags which uses something like this (http://cboard.cprogramming.com/showthread.php?t=87777&page=3) to colour code. Syntax highlighting is standard in editors and we're all used to seeing it. Having looked at recent posts by dwks, it's clear to me that this would make it easier to read posted code, and consequently help others.

I propose something like:



That way people who really don't want to use it don't have to. It should default to "on" so that omitting the highlight parameter defaults to highlighted code.


As a second suggestion, all ad revenue generated from pages with highlighted code should have royalties to dwks, and a modest 87% of that to me as a finders fee :p

dwks
04-13-2007, 01:33 PM
Great idea, but I'll take 95%, thanks. :D

If you wanted to add code colouring to this board, I would strongly recommend GeSHi (geshi.org). It's written in PHP, like the board, and it supports dozens of languages. It's a lot slower than codeform, but hey. :)

I don't think code should be coloured by default. Why? Because then you can't colour code specially to highlight it, like this:

int main() {
gets(s);
puts(s);
}
I think code should only be coloured for some code segments, like examples such as this: http://cboard.cprogramming.com/showpost.php?p=633896&postcount=9

But I really like code colouring. So I think it should be enabled, but maybe not by default. Or at least have a way to turn it off.

So I'm voting Yes, but what I really mean is, enable it but not by default.

I think this would be a good syntax:





That way, it's not enabled by default.

Never mind, Geshi takes rather a long time to execute. Highlighting codeform with itself on a 400MHz computer takes less than 700 milliseconds, but takes nearly 11 seconds with Geshi (and I'm sure that server is a lot faster than 400 MHz!):

0.161/10.601/0.004 seconds (language loading/parsing/cleanup)

You could always take matters into your own hands and use codeform! :D

Do you think all Canadians like coloured code? :P

Perspective
04-13-2007, 01:38 PM
yeah, I agree there are a few situations when you would want it disabled. I just figured that if it was disabled by default most people/noobs won't use it (because they don't realize it's there).

dwks
04-13-2007, 01:48 PM
Well, here's what I think. Make the "code tag" buttons use



by default. Anyone who actually types "[code]" probably knows to use code tags.

Or the default could be c++ and you have to use [code=] or =none to turn it off, like you suggested.

Rashakil Fol
04-13-2007, 01:52 PM
Code coloring is useless -- on a forum. Being able to highlight pieces of code as dwks described is useful.

Wraithan
04-13-2007, 04:20 PM
Rashakil Fol:

Obviously you have never seen the complex problems that are posted from time to time on this board. Also people like Bubba like to share their code as examples(lessons) and it would be a lot nicer to see it in colored form.

VirtualAce
04-13-2007, 04:33 PM
...or as lessons in what NOT to do. :D

I like the idea.

Perspective
04-13-2007, 05:26 PM
Code coloring is useless -- on a forum. Being able to highlight pieces of code as dwks described is useful.

when people post significant sized portions of code, even like this (http://cboard.cprogramming.com/showthread.php?t=88601), for example, it's not useless in my opinion.

Queatrix
04-13-2007, 09:59 PM
I say yes, definitely not useless, it makes code a lot easier to read, especially when a noobie post unformatted code.

whiteflags
04-13-2007, 10:05 PM
You will be very surpised, I think, how noobs who don't format their code will abuse this feature. Ugly code will still look like ........ except now it's colored ......... Monochrome 4 lyfe.

Dave_Sinkula
04-13-2007, 11:50 PM
I've had a different take (http://community.slickedit.com/index.php?topic=531.msg2249#msg2249) on this lately. But it has received more comment here now *chirp* *chirp* than anywhere else yet.

whiteflags
04-14-2007, 01:01 AM
That's a bit different though isn't it - if code tags were smart enough to beautify code, then I wouldn't have any objections. But the posts there only managed to convince me that seems difficult unless we get to work. dwk seems the closest to achieving the goal! He will lead us! :D

cboard_member
04-14-2007, 01:14 AM
I'm all for this as long as we don't go psycho on the colours (like Python's IDLE thing - you don't have to assign a colour to everything).

Salem
04-14-2007, 03:42 AM
"I hate your colour scheme" along with "your indentation sucks" will be an additional refrain.

If I want your code in pretty colours, then I'm perfectly capable of copy/pasting your monochrome code into my IDE with MY preferred colour scheme.

Besides, there seem to be several "colouring in" tools out there which do a fine job of actually corrupting the code.

Used sparingly, colour is very useful for highlighting specific points in the code, but blanket colouring in like some cheap IDE - no thanks.

twomers
04-14-2007, 04:08 AM
I think it's a good idea, and voted to echo that, but perhaps defaulting it to colouring is not the greatest idea. Just like quoting doesn't default to pointing to a user unless you explicated tell it to.

>> "I hate your colour scheme" along with "your indentation sucks" will be an additional refrain.
You talking about a beautifier that indents your code too? The thing is that people could give out about your colour scheme and your indentation anyway if you were using any "colouring in" tools which don't corrupt the code.

>> If I want your code in pretty colours, then I'm perfectly capable of copy/pasting your monochrome code into my IDE with MY preferred colour scheme.
Or you could just look at it here with the your preferred colour scheme :) Perhaps user-programmable colours may be a neat idea so you don't have to go to all that trouble, Salem ;) A user could fill out what they want the colours to look like, in their control panel, and then if code has been posted with a special identifier, such as
... , when you upload a page it will load your defaults so you see it as you wish.

Salem
04-14-2007, 04:27 AM
95% of the noobs only post in code tags because we have a script which won't let them post code without them. Even then, there are a few creative idiots who still manage to screw that up.

On other boards, untagged code is routine, and so is the nagging to get the noobs into line.

Even when it's tagged, they've obviously either never used indentation, or used some horrid mix of spaces and tabs (see past GD topics) and the code still looks like a mess. "HELLO PEOPLE" the preview button is there for a reason.

> when you upload a page it will load your defaults so you see it as you wish.
Excellent - I'll turn it all off thanks.
At least it won't be me coding that system, and ensuring that through the myriad of choices that everyone sees exactly the same code.

twomers
04-14-2007, 07:01 AM
>> Even when it's tagged, they've obviously either never used indentation, or used some horrid mix of spaces and tabs (see past GD topics) and the code still looks like a mess.

Well, that's not a problem with the colouring at all, it could be blamed on the tags but mainly the newbs themselves. You can't change how they are going to post their code. They just want answers, nothing more. So perhaps an indentation-beautification treatment with the code tags might be worth implementing, if not the colouring. But then it'll be absolutely necessary to make sure that they don't "do a fine job of actually corrupting the code".

>> Excellent - I'll turn it all off thanks.
:rolleyes: That's your choice. But I find it easier to 'see' errors in code when the code itself is in colour. I mean the obvious ones, such as people messing up "'s and such. The same goes for the indenting which is one of the reasons why we get so upset with people don't use them. I find it somewhat ironic that you petitioned (http://cboard.cprogramming.com/showthread.php?t=81961&highlight=code+tags)so hard for code tags, granted it wasn't only for the reasons I've given, but do not wish for code colouring. Only somewhat. I understand they are not the same, don't worry.

edit:
>> Great idea, but I'll take 95%, thanks. :D
I reported some bugs to you, so with inflation, exchange rates, political tensions ... mumbles ... I'll have 23%

MacGyver
04-14-2007, 07:11 AM
Code coloring and some sort of auto-indention would be great. I don't want to get picky about the proper way to beautify code, but at least if some standard was used here, it would be easier to see what the clueless people are doing or not doing.

dwks
04-14-2007, 01:22 PM
Given the format of other tags, like [quote], I think if this feature was enabled it might have this syntax:

[code]
or
[code=language]
or
[code=language;style] (maybe)

I agree that if this were enabled there would probably be arguments about which style was better. Perhaps it could be colour coded and the viewer could choose the style, in their User Profile or something?

dwks
04-14-2007, 02:15 PM
Another blow for PHP code tags: In IE 6, when you have a PHP code block selected (i.e., you click on it) you can't scroll with the keyboard: up, down, page up, page down, nothing works. You can of course just click off to the side. But it annoys me at least . . .

(Yes I know that IE 6 is not the best browser in the world . . . this is not my computer.)

twomers
04-14-2007, 02:22 PM
One thing I was wondering was how come the php script-colour-er is enabled. Not so much 'why is it enabled', I know it's in a good few programming forums, but why is it so common around the place? Is it just ... there or something?


>> Perhaps it could be colour coded and the viewer could choose the style, in their User Profile or something?
Yeah, that's what I suggested. Could be defaulted to nothing and you change it, or something.

laserlight
04-14-2007, 02:25 PM
One thing I was wondering was how come the php script-colour-er is enabled. Not so much 'why is it enabled', I know it's in a good few programming forums, but why is it so common around the place? Is it just ... there or something?
A vBulletin (and other forum software) default?

dwks
04-14-2007, 02:25 PM
One thing I was wondering was how come the php script-colour-er is enabled. Not so much 'why is it enabled', I know it's in a good few programming forums, but why is it so common around the place? Is it just ... there or something?

PHP can highlight itself. It's built in to the language. So any board written in PHP usually supports highlighting PHP.


>> Perhaps it could be colour coded and the viewer could choose the style, in their User Profile or something?
Yeah, that's what I suggested. Could be defaulted to nothing and you change it, or something.
Now that's an idea!

But I think that you should still need to mark code that is to be coloured, because having all code coloured would be annoying (see my first post).

Dave_Sinkula
04-14-2007, 02:35 PM
Elseweb, on sites that have introduced it, at first it seemed nice to me. But it's always someone else's scheme, so as the novelty wears off it ends up looking to me as unappealing as the PHP code coloring.

I think it would be interesting to be able to post with some magic tags that present code in the same manner as my editor. But then again, as Salem mentioned, plain Jane code tags display the bad formatting that is the issue often in newb-presented code. And as has also been mentioned, I am also one who likes to take "plain" code tags and use my own coloring to highlight certain parts of the code.

So by default, the enforced code tag script is best for newbs and passersby. If a special colorizer were available, I would be unlikely to use it. I've even stopped using the minimal one I started to write long ago. (Once in a while, however.)

I understand the sentiment, but I think you may also arrive at the "keep the status quo" point of view after you've come full circle.

dwks
04-14-2007, 02:50 PM
I think my/twomers' idea is a good one: you put



and each member gets to choose how coloured C++ code is displayed. Perhaps they could choose Dev-C++ style, or Kate style, or no style (disabled altogether).

zacs7
05-14-2007, 05:51 AM
But then if they had Kate colouring for example, and the author had highlighted a few specific lines... oh noes :(

ulillillia
05-14-2007, 06:19 AM
I voted yes, as highlighting code, especially if more than 20 or so lines, can make things easier to pick out. Fundamental C syntax things like "if", "while", "sizeof", "long", or "unsigned" would be one color. Common C functions like "printf", "scanf", "malloc", "fopen", etc. would be another, strings as another, and everything else as fourth.

This image gives a decent overview of some of it (http://www.ulillillia.us/temporary/coloredsyntax01.png) - blue is for C's fundamental key words, white for basic syntax, teal for user functions, red for variables, yellow for structs, magenta for numbers, and green for comments.

Govtcheez
05-14-2007, 07:18 AM
But then if they had Kate colouring for example, and the author had highlighted a few specific lines... oh noes :(
Why do you keep bumping old threads?

ulillillia
05-14-2007, 07:23 AM
Wow! I didn't notice that this thread was a month old! I still support the idea though.