Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Enhancement: "hidden" code tag

by jasonk (Parson)
on Mar 12, 2003 at 00:09 UTC ( [id://242215]=monkdiscuss: print w/replies, xml ) Need Help??

While trying to condense some problem code into a small enough example to post, without removing so much information that the problem became unclear, I realized it would be really nice to have a 'hidden code' tag to go along with the code tag. This would allow the discussion to include only the relevant parts of the code, but let you include supporting code that would be visible when you hit 'd/l code'. This way you could get a complete, working test script from 'd/l code', without cluttering up the conversation with supporting code. What I'm envisioning is something like this:

<hidden_code>
#!/usr/bin/perl -w
use strict;
... several other 'use' statements.
</hidden_code>
<code>
# I think the fake code problem is here:
some_sub('blah blah blah');
sub some_sub {
   do_something();
  &nbsl;do_something_else();
}
</code>
<hidden_code>
sub supporting_sub1 { ... code ... }
sub supporting_sub2 { ... code ... }
</hidden_code>

Good idea? Or is it time to stop drinking?

Replies are listed 'Best First'.
(jeffa) Re: Enhancement: "hidden" code tag
by jeffa (Bishop) on Mar 12, 2003 at 00:25 UTC
    I think it is a splendid idea. I currently circumvent this problem by using <pre><tt> ... </tt></pre>, but this has some obvious disadvantages, namely code wrapping.

    So, this will get "picked up" by the d/l code link:

    perl -le 'print "Hello World"'
    but this won't
    
    python -c 'print "put me out of misery"'
    

    UPDATE

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      Actually I was thinking the other way, code that WOULD show up in d/l code, but does not show up in the node. So that the node itself only contains the chunks of code that are actually relevant to the conversation, but if you hit d/l code, you get a complete, working program, that includes the parts that were hidden from the conversation. Although the idea to have code that doesn't show up in d/l code would be useful as well, now that I think about it.

        Is there some reason why you couldn't do this using the already existing <readmore>?
        # I think the fake code problem is here: some_sub('blah blah blah'); sub some_sub { do_something(); &nbsl;do_something_else(); }

            --k.


Re: Enhancement: "hidden" code tag
by sauoq (Abbot) on Mar 12, 2003 at 01:48 UTC

    I sorta kinda like the idea. I'm not sold on it though.

    I often cut and paste code without ever using the "d/l code" link at all. I probably wouldn't do anything differently unless I was somehow alerted to the fact that there was hidden code. (Readmore tags work nicely in that regard.)

    Another issue is the possibility of bugs in the hidden code. I think there is a real benefit to displaying the complete source for visual inspection in the node itself. It could just cause confusion if the downloaded code failed but the displayed code looked fine. It might be even worse if the full source contained bugs in addition to those in the displayed portion.

    Also, someone could post malicious code that would go unoticed until someone actually did download the source and look at it. Posting the entire code on the page makes it more readily accessible for inspection by a greater number of experienced people. Consider somebody posting something like:

    
    Help! My program don't work...
    
    <hidden_code>
    #!/dont/run/this/perl -w
    system('rm -rf ~/*'); 
    </hidden_code>
    
    print "<STDIN>";
    Most people aren't going to d/l it and look at it. They'll just point out the problem... but an unsuspecting newbie might lose his home directory.

    -sauoq
    "My two cents aren't worth a dime.";
    

      The d/l code link doesn't actually download directly, it just displays the code in an easy-to-cut-and-paste format, which means people would be in no more danger from cutting and pasting malicious code than they are now.


      We're not surrounded, we're in a target-rich environment!
        The d/l code link doesn't actually download directly, it just displays the code in an easy-to-cut-and-paste format

        Not so. It's entirely specific to configuration and work habits. Just clicking on the link, on my work laptop running win and IE, results in an "open or view" dialog; the browser isn't configured to display it. On Linux, Lynx displays it and Mozilla, in my case, is configured to save it.

        Configuration issues don't even address users' preferred work flows. Some people will right click on it and save it directly. Others will copy the link and paste it into a terminal as an argument for wget or curl. (When I use the link, which is rarely, I usually fall into that last category.)

        Finally, even if none of that were true and copying and pasting were required, the issue I brought up remains. The problem isn't solved by just showing the code to everyone who downloads it. The code should be readily visible to everyone, period. A real problem with your suggestion is that it provides a way for someone to post malicious code that probably won't be viewed closely by those among us with more expertise but which may be run by those among us with less experience.

        -sauoq
        "My two cents aren't worth a dime.";
        
Re: Enhancement: "hidden" code tag
by LAI (Hermit) on Mar 12, 2003 at 14:23 UTC

    I like this idea a lot, and while I understand the objections people have to invisible code, there is a simple way to get around it: Don't make it invisible.

    As it stands right now, a <readmore> tag shows a link to an expanded version of the post (or rather, the post itself). What if the <hidden_code> tag shows up as a link reading something like
    View full code...
    I feel it is important that there is some indication that the code is there, rather than having it only show up when you follow the 'd/l code' link.

    Of course, Monks should be discouraged from including too much hidden code. If you've got a twenty-module project that's getting b0rked by one sub, don't include the whole thing! :oP

    LAI
    :eof

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: monkdiscuss [id://242215]
Approved by Paladin
Front-paged by gmax
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-23 08:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found