http://www.perlmonks.org?node_id=939587

I have never seen perltidy syntax highlighting in PerlMonks posts. Is it available? Is it desired? Most questions only have snippets of code, so maybe it isn't necessary there. But what about the code catacombs, cool uses for perl or a user's scratchpad. I think converting from the original plain text code => perltidy syntax highlighting could be done by a simple ajax request. Just wondering.

Replies are listed 'Best First'.
Re: perltidy in PM posts
by davido (Cardinal) on Nov 23, 2011 at 05:39 UTC

    PerlMonks strives to minimize the impact of "editing" of original posts. Site Janitors do their best to walk lightly. Whether it be by human touch or automation, changing the code's layout ala perltidy would break away from the spirit of that philosophy. Speaking for myself as a janitor, I have evolved to prefer simply wrapping naked code in code tags without altering the code's actual layout, as much as possible (or more accurately, as little as possible). I wouldn't want to automate something more heavy handed than that.

    As for syntax highlighting, I know that though there are many proponents, there are some who feel that it encourages sloppy code layout.


    Dave

      There are two sides of the coin too. Running perltidy at the user end would be fine with me. He or she selects that feature. Running it at the server end would definitely chase me away, as it will change my style with some other style and thus remove my artistic freedom - I actually care a lot about style and layout, and the fact that it is changed by others made me decide to never ever write for books that change code style to their standard, as it then no longer is my code.

      A second reason not to allow whatever form of code-reformatter is that many of the posts are just about this: why is may layout like XXX, and what should I change to get layout YYY. If that was formatted, you'd see no difference. Example.


      Enjoy, Have FUN! H.Merijn
        And don't forget that not everything between <code> tags is perl code!
        Tux nice 1.
        totally agree with you
      I think the answer to different needs is easy: provide different options.

      We already have different displaytypes and could add a tidy one, which could be chosen in individual user settings.

      As for syntax highlighting people are free to choose monochrome CSS classes.

      Backwards compatibility is no problem here.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Re: perltidy in PM posts
by Anonymous Monk on Nov 23, 2011 at 07:20 UTC
Re: perltidy in PM posts
by juster (Friar) on Nov 27, 2011 at 21:07 UTC
    A few years ago I wrote a simple web service that highlights and/or tidies code blocks on PerlMonks by using Perl::Tidy and a Greasemonkey userscript for AJAX: http://juster.us/perl/pmtidy/

    Over the years I have come to like syntax highlighting less and less but the tidying comes in really handy for some posts.

Re: perltidy in PM posts
by ansh batra (Friar) on Nov 23, 2011 at 04:19 UTC
    first of all this topic belong to PerlMonks Discussion
    and secondly some sections like Obfuscation would loose their beauty with perltidy
    rest it would be a great thing and also help full to the newbies like me if it is implemented

      Not to criticize you, ansh batra, but just to, I hope, inform you a little and perhaps amuse you, simply because I enjoyed your comment about newbies the most of the comments so far... :)

      Yes, syntax highlighting certainly makes things easier to understand for newbies. Consider perlop. This excerpt would just be so much harder to understand if I hadn't copied the "syntax highlighting" from perldoc.perl.org:

      The fact that the only text within sight that is blue is the three '$' characters (I'm sorry, I should have made that dollar sign that I just typed blue; I'm sure I've confused most of the newbies now) clearly indicates something that newbies would not have understood without the clarion indicator of "blueness" (every newbie knows what blue means in that context; that goes without saying).

      But that pales in comparison to the boundless clarity that is only possible by having the red parts be red.

      The indentation getting a bit wonky in a couple of places is such a small price to pay for these huge leaps in clarity of the text.

      On a serious note, if you want to know about syntax highlighting at PerlMonks, then there are several facilities provided for searching for such things.

      I'm sure somebody will soon post links to no small number of previous discussions. (Ah, yes, as I expected, this happened before I even finished composing this.)

      In the mean time, I'll summarize: If you want colors assigned to things based on some algorithm that clearly fails when it tries to parse some Perl code and fails even more interestingly when it tries to parse things that aren't Perl code as if they were Perl code (or if you want to go the stackoverflow route of assigning colors based on some vague feel of "bits of syntax that are somewhat common to more than one programming language"), then you need to pick the poison of your choice and impose it upon yourself. And that isn't particularly hard. I'm sure some of the linked threads even provide instructions (but I didn't check).

      Though, if anyone still thinks that either of those approaches won't often decrease clarity, then I suspect that mostly means that they don't pay all that much attention much of the time. (:

      BTW, the perldoc example is just something I stumbled upon last week. I wasn't even looking for examples of "syntax highlighting gone wrong". I run into those often enough without looking for them and that's even though I never use syntax highlighting by choice.

      - tye        

Re: perltidy in PM posts
by JavaFan (Canon) on Nov 23, 2011 at 13:23 UTC
    I'd love to see syntax highlighting. But then, only if it's using my choice of colours:
    • Background: white.
    • Keywords: black.
    • Variables: black.
    • Comments: black.
    • Strings: black.
    • Operators: black.
    • Semi-colons: #000000.
    • Barewords: black.
    • Here doc terminators: black.
    • The letter 'q': black.
    • __TOKENS__: black.
    • Whitespace: white.
    • Hash bang lines: black.
    • Regular expressions: black.
    • POD: black.
    • Everything else: anti-white.
    I think we can all agree that this is the only sensible colouring scheme.

    Update: I've gotten many messages from people agreeing with me, but they are too afraid to speak up.

      While it's amusing, and I wouldn't reply at all but for your update, I disagree about the colors and I'm not afraid to do so. The syntax highlighting and general CSS on github is very nice for example.

      There is nothing to disagree with here: only if it's using my choice of colors.

      While I'd like some of the things in this vein that are discussed from time to time, I would never demand it from the unpaid maintainers of the site and I'm too lazy busy to offer patches so… hush mai mouf.

      I love it!

      Let's call it the:
      Hey You Damn Kids with Your Rocky-Roll Music, Floppy Haircuts and Damn Syntax Highlighters, GET OFF MY LAWN!!!
       - Syntax Color Theme.

      ;-)


      Update: *sigh* I don't know how to tell you this but in the 5 minutes since I first posted my support for your new ...GET OFF MY LAWN syntax color theme, I've been inundated with messages from people who say they absolutely HATE it ( I KNOW, I was just as surprised as you! ). They didn't seem too afraid to tell me about it either, just apathetic enough to not bother posting. This happens with innovative artists, they're never appreciated in their time. :(


      "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." — Don Quixote
Re: perltidy in PM posts
by TJPride (Pilgrim) on Nov 26, 2011 at 18:14 UTC
    This sounds like a good idea, but only if it's an optional setting - as in the posts are dynamically converted for some people, but not for others. It should default to off, so there's no appreciable additional load on the server when spiders go through (I know things lag enough as it is).