This would save lots of time for those of us who need to run the code to figure out what's wrong. It's aggravting to download code and try to run it only to get errors because the OP has lines like '...' in the "code", or to get errors because the code doesn't really represent a full example of what's wrong.

Possible drawbacks:
  1. permonks would need every module known to man installed.

  2. We'd have to find some other way to conveneniently represent progam output or other things that can contain wierd characters. I'll admit to using code tags for this.

--Bob Niederman, http://bob-n.com
  • Comment on Require everything between innermost <code></code> tags to compile.

Replies are listed 'Best First'.
•Re: Require everything between innermost <code></code> tags to compile.
by merlyn (Sage) on Aug 02, 2003 at 20:08 UTC
    That definitely wouldn't work for me. There are many times that I put CODE tags around snippets inline, simply because I use a lot of brackets in the code I write.

    Also, there's really no way to do this safely. Compilation of code can always involve arbitrary execution of code, thanks to BEGIN blocks. Which means the compilation would have to be in a Safe compartment, and there's issues around that. Big issues.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      I'm curious. What kind of big issues?

      Makeshifts last the longest.

        For one, there's no protection against using up tons of memory. Someone could easily write code like "my @foo = 1..1e6; while(1) { push @foo, @foo }" and Safe will allow it.

        --MrNobo1024
        s]]HrLfbfe|EbBibmv]e|s}w}ciZx^RYhL}e^print

        {redo}
        It's not 100% safe.

        Liz

Re: Require everything between innermost <code></code> tags to compile.
by dws (Chancellor) on Aug 02, 2003 at 20:23 UTC
    Require everything between innermost <code></code> tags to compile.

    And when someone posts a Java or Python snippet as a point of comparison with equivalent Perl code? Compile the other language? Or when someone uses <code> tags to format representative script output? Or when someone posts small A vs. B snippets that aren't intended to be compiled as is?

    I think this is a problem better solved by human intervention, whether it be the brain of the reader, or the harassment leveled at the writer when necessary.

      Strictly speaking (strict HTML, that is) <code> tags should not contain output... Something like <pre> would be more appropriate, although IIRC those tags are deprecated at perlmonks.

      Nevertheless, I agree with other monks on this idea. Too risky, and too problematic to be workable.

      </ajdelore>

        <pre> is not deprecated, but can easily cause scrollbars if you don't pay attention, so their use is discouraged, but not deprecated.

        Makeshifts last the longest.

Re: Require everything between innermost <code></code> tags to compile.
by CountZero (Bishop) on Aug 02, 2003 at 20:12 UTC

    A good idea but not very likely to be implemented by the posters.

    Also it would open perlmonks to malicious code.

    Finally, as many times the code has some bugs in it (which is the reason the poster turned to perlmonks), a lot of the code will simply refuse to compile/run, either because of syntax errors, logical errors, or "..." somewhere in the code.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Require everything between innermost <code></code> tags to compile.
by Popcorn Dave (Abbot) on Aug 02, 2003 at 20:23 UTC
    It's an interesting idea, but I think you're right in the drawbacks you point out yourself. In addition, the points others have made about using "code" tags for general formatting purposes make it unworkable as well.

    Perhaps strongly nudging posters in to the

    use strict;
    use diagnostics

    way of thinking before posting code could eliminate some of the problems you run in to, let the OP catch some of their own errors, and perhaps help the OP's in the long run as well in understanding the errors.

    There is no emoticon for what I'm feeling now.

Re: Require everything between innermost <code></code> tags to compile.
by liz (Monsignor) on Aug 02, 2003 at 20:10 UTC
    That would be a time saver, yes. But how would you do that without grave security implications for the Monastery itself?
    <code>
    BEGIN { do naughty stuff }
    </code>
    

    Liz

Re: Require everything between innermost <code></code> tags to compile.
by castaway (Parson) on Aug 03, 2003 at 08:16 UTC
    It sounds like a terrible idea to me, for several reasons. One of them just happened to be the quote line as I was reading your post: "Keep It Simple Stupid". ,)

    Another would be that the whole point of most posts, is to try and solve erroneous errors in code, which probably means that the poster *cant* get the code to compile. Forcing them to figure out workarounds just to be able to post would just obscure the problem.

    We'd need a whole heap of new tags too, <code>, <code that doesnt compile>, <literal non-code stuff> etc. pp. It really sounds like overdoing it to me.

    I suggest you just create a script that downloads code (plenty of examples for that about), and automatically checks it. (And for bonus points, an intelligent syntax-repairer, that removes or comments out '...' etc. ;)

    C.

Re: Require everything between innermost <code></code> tags to compile.
by DrHyde (Prior) on Aug 02, 2003 at 21:45 UTC
    How do you know what language the code is in? For example, I recently posted a snippet from a shell script (which shell? using which external programs?) which just happened to have some perl embedded in it. The shell script was incomplete as I only posted what was necessary to illustrate my point and so would have thrown up errors all over the place.
Re: Require everything between innermost <code></code> tags to compile.
by SyN/AcK (Scribe) on Aug 02, 2003 at 22:06 UTC

    What if you are just putting a snippet of code in? There's lots of times where the code you might put in would be huge in order for it to work, but you know that the problem occurs only in a small section of the code. The code wouldn't really work without the rest, but when you think of it, the rest is just background noise to the real problem.

Re: Require everything between innermost <code></code> tags to compile.
by Anonymous Monk on Aug 03, 2003 at 00:58 UTC

    Keep in mind what most people refer to as "PerlMonks" is just a database of posts & user info selectively converted into html output. You could easily implement your suggestion on your end (albeit a little more difficult) and prevent Perlmonks from having to deal with the security issues.

Re: Require everything between innermost <code></code> tags to compile.
by bobn (Chaplain) on Aug 02, 2003 at 20:59 UTC

    Thanks for all the responses.

    Although many mentioned uses of code that are for snippets, , program output, etc., this could be resolved with a new tag, such as <lit>stuff here</lit>, which would act like code tags in everyway except trying to compile the ontents.

    The issues of code that runs in BEGIN blocks is much tougher. This would have to be dealt with or disabled, diminishing the usefulness of this tool.

    As far as people posting in other languages, screw 'em, there are no other languages. JUST KIDDING!

    An additional problem: if perlmonks is on *NIX, (Netcraft indicates FreeBSD) Win32:: modules have no chance of working.

    If this were to be implmented at all, it would have to be an advisory, rather than a requirement.

    Thanks again, everyone.

    --Bob Niederman, http://bob-n.com

      Keep in mind that if you prevented me from saying BEGIN {...} that I could always say it another way. Similar tricks can be played with overload as well. Anyone know of other modules I can get to execute arbitrary code during BEGIN?

      use lib sub { die 'bad code' }; use foo_bar;
        perl -le 'use if eval("print `echo hello`"), CGI; BEGIN{ print "goodbye"}'
        -sauoq
        "My two cents aren't worth a dime.";
        
Re: Require everything between innermost <code></code> tags to compile.
by skyknight (Hermit) on Aug 03, 2003 at 00:40 UTC
    The only safe way that I could imagine doing this would be to have a chroot jail in which to execute the script, as well as having the process launched by another process that would monitor if it did anything suspect, such as not exiting within a certain amount of time, using an obscene amount of memory, etc. This might be doable, but probably not worth the trouble. Defining the parameters of sanity would be very difficult, and would probably result in breaking lots of benign scripts. It's a nice idea, but not terribly practical. We'll just have to rely on people being decent because they want to be, not because we have a shotgun in our living room, or bars on our windows. ;-)
Re: Require everything between innermost <code></code> tags to compile.
by naChoZ (Curate) on Aug 03, 2003 at 03:03 UTC
    I think it's a pretty good idea. I can think of a couple things that would keep the impact to the site minimal. First, only check <code> items with a perl shebang line. 2nd, simply put the results of a perl -c in a separate block underneath the block of code in the node. No muss no fuss. Then it doesn't go trying to check a java snippet, or a single subroutine that someone posted, or anything like that.

    ~~
    naChoZ