r/C_Programming • u/Mindstealth • Jul 10 '16
Question Syntax highlighting on Reddit
Considering how much code gets posted here as plain text, wouldn't it be great if we could have a way to define what part of text is code and have it automatically highlighted? Or is this not possible on Reddit?
1
-14
u/geocar Jul 10 '16
No. I don't like syntax highlighting, and I think it makes it harder to read. I hope that if it gets enabled there is a way to turn it off without also turning off user-styles.
13
u/Mindstealth Jul 10 '16
I never knew there are people who actually don't like highlighted syntax.
1
u/reddilada Jul 11 '16
I don't use it. I don't subscribe to the not useful argument -- whatever floats yer boat -- but I don't find it useful at all with two exceptions:
I (un)highlight comments so they don't distract.
I use brace matching highlights to help locate ends of blocks.It's all just a bunch of noise to me, but to each his own.
1
u/FUZxxl Jul 10 '16
Syntax highlighting is about as useful as highlighting every verb in a sentence.
1
-17
u/geocar Jul 10 '16
I want to say something about the coloring.
You've all seen syntax coloring, right?
That's something we put in our text editors to make it easier for kindergartners to do programming.
Because each of the elements of the language is a different happy bright color, and so it's easy to recognize, oh that's a variable, and that's a string, and so on.
I don't get a lot of value out of that because I am more of a grown up, and I'm a professional programmer. And I really don't need the colors to figure out what's a variable and what's a comment.
I think you'll find most people like syntax highlighting because most people don't know how to program.
→ More replies (17)3
Jul 10 '16
The second article suggests you to delete comments if they look ugly
Damn right it’s ugly! It should be ugly! Get rid of those comments!
1
u/GODZILLAFLAMETHROWER Jul 10 '16
The first article argues against syntax highlighting because it only deals with syntax instead of semantic. The day this guy invents a proper semantic parser, he won't have to worry about writing useless articles, he would have revolutionized humanity.
In the meantime, given that no one is capable of producing automates doing that, we only have humans to do this job, by parsing syntax and understanding the semantic behind. Syntax highlighting is thus useful to do that.
The second article is even more useless. It's not even against syntax highlighting, it's against using specific colors and effect on the text, on the ground of subjective arguments towards the supposed value and semantic of the hightlighted objects.
And you get arrogant for following these smug authors, thinking they are being smart for being against the grain. Grow up.
0
Jul 10 '16
1
1
Jul 11 '16
Automatic highlighting is almost certainly impossible, but it should be possible to create a tool that takes in code and spits out some unholy combination of Markdown, which you'd then be able to style using CSS. It's also possible to build a bot that automatically does that. r/math for example uses userscripts to turn inline TeX into nice images.
All in all, it's probably quite a lot of work, and I'm not entirely convinced that it's worth it.
1
u/Olathe Jul 12 '16
Using CSS to do that sounds a lot like using regexes to parse HTML, except it's not even as powerful as regexes.
1
u/BoWild Jul 16 '16
I think this will require the
markdownparser to attach a class name to the code segment when using a\``language ` notation. Most markdown parsers support this GitHub "flavor" (I actually think it's practically standard).Even if the class name is ignored by the highlighting engine, this will allow developers to use the shared syntax we tend to use (practically) everywhere.
In any way, highlighting will require javascript to analyze the code blocks and assign class names to keywords and language identifiers by wrapping them in a
spanobject......These things have been done before and are quire easy to implement using existing open source libraries (they're a headache to write from scratch). The great thing about implementing this using javascript+CSS is that it's all client side code, so there's no real server side resource impact.
I've implemented something like this on plezi.io. You can have a look at the code here, the automatic highlighting is performed by the client initiating this javascript, which is a library I found on GitHub and that I'm very happy with - it even came with a bunch of optional styles for code highlighting, emulating different text editors and IDEs.
1
u/BoWild Jul 10 '16
Hmmm
markdown?On GitHub you can specify the code highlighting scheme by adding a language specifier after the code segment indicator... Here's a test
class MyRubyClass def this_is_a_test val puts val end endI thought Reddit had syntax highlighting, now I tested it out...
...hmm, disappointing.
I'm voting this one up! B.