A lot of newcomers to perlmonks don't seem to know about the <code> tag. How about adding a check in the posting module so that if 1) a post looks like it contains perl code, but 2) it doesn't contain any <code> tags, then the user is either forced to edit the post or check a box affirming that the post is correctly formatted. This would help reduce the number of considered nodes.

The key would be coming up with a good perl code recognizer. I'm sure there are some pretty sophisticated ways of doing this, and I'd be very interested in seeing how it could be done using advanced CS/machine learning/statistical methods, but perhaps something as simple as the following would suffice (at least initially):

sub contains_perl { $_[0] =~ m/[\$@%]\w/; }
Other factors that could be taken into consideration include: I'm relatively new here so perhaps this has been thought of/tried before. Comments?

Replies are listed 'Best First'.
Re: newbies, <code> tags and recognizing perl
by BrowserUk (Patriarch) on Mar 21, 2008 at 03:32 UTC

    Personally, I think a simple approach of presenting the textarea with a couple of the common tags already in it would guide most new users into doing the right thing. Eg:

    Your text: +-----------------------------------------+ |<p>Your question here</p> | | | |<code> | |#Perl code goes here | |</code> | | | | | | | +-----------------------------------------+ [preview]

    But then I always favour simple solutions.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I agree w/ BrowserUK; the "snippets" section is almost like this. Even better would be to just include text that you might actually want to erase (and, hence, pay attention to) in the create box, eg:
      
      Use this space to ask your question.  You can delete this text.  
      Place actual perl code inside the <code> tags below.
      
      <code>
      CODE GOES HERE
      </code>
      
      See below for more formatting tips.
      
      
      I think almost anyone asking a legitimate question will be able to deal with this PLUS:
    • it's PROACTIVE!
    • it's easier.
        Did you really intend your post to be such a mixture of unclosed tags, mixed font-weight and -style, etc? And if so, please clarify how is it supposed to differ from BrowserUk's above.

        Whether or not the appearance of your post reflects inadequate previewing or not, it's quite plausible (to me, anyway) that many posters eliminate the "Preview" button when creating a node, or treat it as so many treat an "accept this license" box during software installs; that is, as something to click through as quickly (and carelessly) as possible.

        Sorry if this sounds snarky (and I'm not trying to suggest that you're among those who simply haven't read the docs), but many of the formatting problems here are created by those who haven't understood them.

        We can't cure the former, except by gentle guidance and by making the markup docs easier to follow, which might also automagically address the latter.

        Puff: Please see Markup in the Monastery for one attempt at enhancing the guidance.

        I think this is a great idea. My only problem with it is that it reduces the need of the poster to think before posting.

        Is that necessarily a good thing?

      I'm undecided as to whether or not this is a good idea, but it is certainly the best way to increase the number of new monks that use code tags. Messages will not work, task-driven people generally ignore text that isn't needed for completing their task (even if you make it giant and blinking!).

      The only way to stop a user is to force them into a decision, like this solution which makes them remove default values.

        It is a good suggestion, but I can't help thinking that we'd see a sudden rash of


        Help! My code doesn't work! Please tell me how to fix it even though my extended rambling insistence that it doesn't work never once specifies (or even alludes to) what I'm trying to accomplish or the way in which it doesn't work, much less provides any code or other hints for reproducing my results. How do I fix it?

        Your question here

        #Perl code goes here

        I'm not quite sure whether I think that would be an improvement or not.

      The </p> is not required.

      <code></code> should be used for data and output as well.

Re: newbies, <code> tags and recognizing perl
by Roy Johnson (Monsignor) on Mar 20, 2008 at 17:09 UTC
    I made a similar suggestion almost exactly three years ago. You can see the discussion there.

    I wonder whether having the submission box pre-loaded with an empty code tag pair would be the suggestion some people need? It would be simpler than parsing their post, and it's an option that could be turned off in user prefs.


    Caution: Contents may have been coded under pressure.
      I wonder whether having the submission box pre-loaded with an empty code tag pair would be the suggestion some people need?

      I doubt it. Plenty of people don't read Writeup Formatting Tips, and plenty of people always type the body of their posts in their signature tags.

Re: newbies, <code> tags and recognizing perl
by CountZero (Bishop) on Mar 20, 2008 at 23:13 UTC
    ++ for thinking about ways to improve our Monastery!

    As our Monastery-site has always been on the limit of what is still considered acceptable responsiveness, adding such a check will be quite a heavy burden on the servers, I think.

    Still, from a theoretical point of view, a module such as Algorithm::NaiveBayes could form its basis. Feeding it a significant number of nodes, both with and without code tags will quickly make it distinguish between nodes containing Perl-code and those without.

    I recently used it to categorize database-records and had a successrate of about 85%. It could easily have been higher but the field which was the basis of the categorization was at the most 70 characters long, contained many "stopwords" and I had 6 categories to choose from.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Might detecting the presence of ^\s*my\s+\$.+; without <code> having been encountered first be enough to send up a flare?
        Could be, but if the newbie does not use strict; he is unlikely to have lexical variables and your regex will not trigger.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: newbies, <code> tags and recognizing perl
by GrandFather (Saint) on Mar 21, 2008 at 02:35 UTC
Re: newbies, <code> tags and recognizing perl
by Anonymous Monk on Mar 21, 2008 at 12:03 UTC
    Isn't there a module for this?

    I want a cheese sandwich.

    Output:
         <code>