I expect to see pseudo code and maybe even HPL code on regular basis. I think syntax highlighting would be a great thing to have.

On Stackoverflow, code is highlighted nicely; the schema used is inferred from the respective question's tags. This won't work for us, I think, because we probably won't have tags for programming languages. Are there other ways?

And what about pseudo code? Should it just highlight common keywords or should we establish a certain style?


We've turned on Syntax Highlighting in an opt-in basis. That is, to use it, you'll need to specify the language for your highlighting in an HTML comment, as explained in the Editing Help section for Syntax Highlighting. It will also apply it to questions that have a particular language tag, though I don't think that's a regular occurrence given the subject matter here.

  • $\begingroup$ Awesome, thanks! Hopefully, this will make quite some pseudocode more readable (as long as the authors care). $\endgroup$
    – Raphael Mod
    Sep 17 '15 at 9:06
  • $\begingroup$ @Grace Is opt-in highlighting only available for graduated sites? $\endgroup$
    – muru
    Sep 20 '15 at 18:23

I don't think Prettify would do a very good job at highlighting pseudo code - especially since conventions for pseudo code widely differ (and I don't think it would be realistic to enforce a standard convention).

It might be a better idea to use TeX for pseudo code - that way anybody can decide for himself what's a keyword and what isn't (it also allows us to pretty the code up a bit by using non-ASCII characters).

As far as highlighting for real languages is concerned, I don't think they would be used often enough to make this necessary.


I think it's not necessarily bad to use the syntax of a particular programming language to express algorithms. For example, one may describe QuickSort as follows.

   def qsort(i, k):
     j = choose_pivot(i, k)
     j = partition(i, j, k)
     qsort(i, j)
     qsort(j, k)

And then explain only in words what choose_pivot and partition are supposed to do.

So, syntax highlight would benefit people who prefer such a style. We must be careful, however, to not encourage writing actual programs with non-relevant details.


I definitely think that syntax highlighting can make huge chunks of pseudocode more readable. At a minimum, keywords could be fat to indicate some structure.

The hightlighting method Stack Exchange uses is already able to let the use choose from a list of languages (for each code block). Thus, every user could pick the language that matches their pseudocode best.
The default on cs.SE should definitely be "no highlighting".

Ideally, following the idea of "just show keywords bold", there would be some way to give Prettify a list of keywords to highlight, and have it do nothing else. I'm not clear whether it already supports this -- there is some mention of extendable language handlers, but no documentation.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .