Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Tidy feature to implement recommended code style

by Wassercrats
on Nov 23, 2003 at 05:26 UTC ( #309225=monkdiscuss: print w/ replies, xml ) Need Help??

How about the editors coming up with a single, recommended style for all posted code, and intergrating a pre-configured PerlTidy into the message board? If a monk enters Perl code within code tags, he could click a button and have it formatted with PerlTidy.

I've used PerlTidy only three times with intervals of several months, and I always forget that it doesn't have a .pl extenstion and I always try running it at the command prompt without prepending "perl," which doesn't work. I've had other problems, including not being able to use the standard installation procedure because I couldn't get nmake to work on Windows. The installation instructions aren't for beginners, and I figured some beginners might like a PerlTidy web application. Then I thought of the Perl Monks feature.

Comment on Tidy feature to implement recommended code style
Re: Tidy feature to implement recommended code style
by !1 (Hermit) on Nov 23, 2003 at 05:35 UTC

    Then how will we know that the poster is coding in a poorly formatted way that would make maintenance difficult so we can note it to them?

      Indentation isn't really standardized, but on a single message board (perlmonks.com), it should be. The PerlMonks standard could be limited to something as simple as indentation and bracket alignment. It could also be used only for the sections Snippets and Code. I'd kind of like a full featured version to be available somewhere though. I'm thinking of creating such a web application.
        The PerlMonks standard could be limited to something as simple as indentation and bracket alignment. It could also be used only for the sections Snippets and Code.

        If "Code" section gets the auto-always-on-perltidy feature, i would post my code ONCE. There would be no incentive for me to deal w/ differences in style if code ever needs to be updated, say a bug fix or such.

Re: Tidy feature to implement recommended code style
by duff (Vicar) on Nov 23, 2003 at 05:38 UTC
    If a monk enters Perl code within code tags, he could click a button and have it formatted with PerlTidy.

    And if a monk enters some non-perl code ... ? Pseudocode, C, etc. are fairly common.

      I'm going to go waaaaaaay out on a limb here and make an incredibly wild guess but uh, MAYBE HE DON'T CLICK DE BUTTON, YA?
Re: Tidy feature to implement recommended code style
by Zaxo (Archbishop) on Nov 23, 2003 at 05:48 UTC

    Yikes!! How will we get into stylin' riffs if we all look like vroom?

    How will we know who only knows code from college?

    How will we spot the manic twitches of lisp and VB?

    Down With Uniformitarianism!
    No Top-Down SoPW!
    Let Informed Quality Show!

    Do you really want some babelfish between us and our teachers?

    After Compline,
    Zaxo

Re: Tidy feature to implement recommended code style
by tcf22 (Priest) on Nov 23, 2003 at 06:26 UTC
    I totally disagree with the idea of forcing posts to use a certain coding style. I've seen posts from beginners here, where the problem was simply unbalanced braces. There was no indentation, so other more experienced monks gave some formatting advice, in order to prevent this problem from happening to them again. If you use perltidy on all of the posts, no one would notice this.

    Not to mention, I don't like being forced to format my code a certain way by anyone that isn't paying me.

    - Tom

Re: Tidy feature to implement recommended code style
by sauoq (Abbot) on Nov 23, 2003 at 07:05 UTC

    I can think of lots of reasons not to do this...

    • There are lots of good styles and exposure to them all will help you develop your own.
    • If someone needs to improve their style, but they can hide that fact with the push of a button, they may never receive some much needed advice and direction.
    • Server load.
    • Reading poorly formatted code will help you improve your maintenance skills.
    • A disconnect between the code they are helped with and their actual code will make it harder for them to implement suggested changes.
    • Just try getting all the editors to agree on one recommended style.
    • Formatting code fragments would often not give desirable results anyway.
    • I don't see an easy way to integrate this into the existing interface. We can have multiple code sections, for instance. They can be inline if we want. Etc. How can you decide which to run through perltidy?
    • This would be a poor alternative to suggesting to someone that he download perltidy himself and learn to use it.

    And, I don't see one good reason to do it.

    Somewhere else in this thread you said, "Indentation isn't really standardized, but on a single message board (perlmonks.com), it should be." I disagree, but that's okay. You've expressed an opinion. Now, present an argument to support it.

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

      • There are lots of good styles and exposure to them all will help you develop your own.
      Yes, but unless the different styles are being presented as examples of different styles, there is a danger of an infrequent monk adopting the style of the script he just happens to have read. I suggest an additional list item under the text boxes that links to a short and simple code formatting tutorial that covers only the basics, such as the few things that I've read Larry Wall considers important. I believe that such a tutorial and the various benefits of a tidy feature outweigh the bad points.

      Some tips on making the current bulleted items under the text boxes more concise and readable--eliminate "Are you posting in the right place..." Just include helpful subtitles under the section names on the pages of the sections. Such a helpful subtitle ("This area is for discussion relating to this site. If you're looking to ask a question about a Perl problem you should go to the Seekers of Perl Wisdom page.") is already included on the Perl Monks Discussion page. Keep the "Perl Monks Approved HTML tags" item, but make it read:

      Perl Monks Approved HTML tags (avoid pre): a, b, big, blockquote, br, center, code, dd, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, li, ol, p, pre, readmore, small, span, strike, strong, sub, sup, table, td, th, tr, tt, u, ul
      Note the addition of "avoid pre" and "code." Make "avoid pre" into a link to Perl Monks Approved HTML tags with details on why to avoid pre at the top of the page. The "Snippets of code" item should be eliminated.

      I also recommend using title attributes containing brief descriptions for the upper right links to the sections. They are displayed when hovering over links, at least in IE.

      • Reading poorly formatted code will help you improve your maintenance skills.
      • A disconnect between the code they are helped with and their actual code will make it harder for them to implement suggested changes.
      • If someone needs to improve their style, but they can hide that fact with the push of a button, they may never receive some much needed advice and direction.
      Applies mostly if the code in one of the help sections, where the reader might be looking to improve it. Reading bad form is more likely to result in more bad form. As I said, the tidy feature could be limited to the snippets and code sections.
      • This would be a poor alternative to suggesting to someone that he download perltidy himself and learn to use it.
      No argument there. I suggest noting the importance of learning to use PerlTidy rather than avoiding the feature.
      • Just try getting all the editors to agree on one recommended style.
      I wouldn't try it, but I'd like to read the debate.
      • Formatting code fragments would often not give desirable results anyway.
      If there is still a problem with a warning, then maybe offer the tidy feature in the Code section only, or sniff for a full script by checking for a "user/bin/perl line at the top.
      • I don't see an easy way to integrate this into the existing interface. We can have multiple code sections, for instance. They can be inline if we want. Etc. How can you decide which to run through perltidy?
      The last code section only. To tidy more than one code block, you would enter one, click tidy, enter another, click tidy, etc. Inline code wouldn't be tidied.
      • Server load.
      I don't think there are that many new entries in the Snippets and Code sections each day. You might get slowdown spikes when PerlTidy is run though. Don't know how well the Perl Monks servers could handle that.
      Somewhere else in this thread you said, "Indentation isn't really standardized, but on a single message board (perlmonks.com), it should be." I disagree, but that's okay. You've expressed an opinion. Now, present an argument to support it.
      I know that writing style is standardized in magazines. I'm not sure about coding style, though I'm sure it's standardized in books. There's not the same style in every book, but within a given book, the coding style would probably be consistent. Doing the same on PerlMonks would be in keeping with the standard for code conformity set by the non-electronic media. There isn't much of a standard on the web. I don't know of another message board with a significant number of full length scripts. But more important than that is setting a good example with the posted code.
        I know that writing style is standardized in magazines. I'm not sure about coding style, though I'm sure it's standardized in books. There's not the same style in every book, but within a given book, the coding style would probably be consistent. Doing the same on PerlMonks would be in keeping with the standard for code conformity set by the non-electronic media. There isn't much of a standard on the web. I don't know of another message board with a significant number of full length scripts. But more important than that is setting a good example with the posted code.

        There are a lot of people on this site contributing a lot of content for a lot of different reasons. Some of the code in the snippets and code sections may be there for pedagogical purposes, but most is probably posted with only the intent of sharing the code. Trying to enforce a particular style on those sections would be like trying to enforce a coding style on CPAN submissions. Shall we also set up a GrammarTidy for non-code content?

Re: Tidy feature to implement recommended code style
by Anonymous Monk on Nov 23, 2003 at 08:37 UTC
    How about the editors coming up with a single

    What editors? You're saying you want to create an editor?

      PerlMonks already has editors. See this and this.
Re: Tidy feature to implement recommended code style
by Aristotle (Chancellor) on Nov 23, 2003 at 13:31 UTC
    I've used PerlTidy only three times with intervals of several months, and I always forget that it doesn't have a .pl extenstion and I always try running it at the command prompt without prepending "perl," which doesn't work. I've had other problems, including not being able to use the standard installation procedure because I couldn't get nmake to work on Windows. The installation instructions aren't for beginners
    Yeah, so? Is it PM's job when you can't remember how to invoke a tool?
    I figured some beginners might like a PerlTidy web application.

    So go ahead and write one. Put it up, post about it here, get some XP*. Write beginner's instructions on how to install it on Windows, post them here, get some XP*. Talk is cheap, feature requests are a dime a dozen dozen (sic). Show some effort.

    * As in, that would be appreciated by the "community".

    Makeshifts last the longest.

Re: Tidy feature to implement recommended code style
by Abigail-II (Bishop) on Nov 23, 2003 at 22:12 UTC
    How about the editors coming up with a single, recommended style for all posted code,
    That's a great idea! Let the editors look at my coding style, which is the only one true style, and enforce that on everyone posting here. I'd say, a post containing code that doesn't have that style shouldn't even be allowed to be posted.

    Abigail

      That's also a great idea to once and for all end these silly golf threads. All that useless punctuation that was removed will be added back, so that the claims won't match the code at all anymore.

      The only slight problem is that of course my code style is the only true one, but we can work out little details like that on the field of honor.

Re: Tidy feature to implement recommended code style
by etcshadow (Priest) on Nov 23, 2003 at 23:58 UTC
    Perhaps a more interesting and agreeable idea is to allow each user to specify their own .perltidyrc and put it in their user config. Then, the server could render everyone's <code> tags how each user likes to see them.

    Obviously, though, this still falls victim the habit that many monks have (myself included), of putting various code-like snippets in <code> blocks (like command-lines, shell scripts, psuedocode, code for other languages than perl). That could be dealt with with attributes: <code lang=perl>, or with a new tag like <perl> which behaves the same as <code> except for the auto-perltidy'ing.

    Anyway, I suppose it's somewhat academic, because it probably ain't gonna happen, regardless, and I don't know that that's a bad thing.


    ------------
    :Wq
    Not an editor command: Wq
      It will happen some day.

      Even if I hadn't said/implied it, the "make it optional" feature would be an obvious alternative to those with open minds who gave it any thought, as would the implementations you mentioned. If PerlTidy is good to have on your own machine, it's good to have here as a web application. It would be easy and free too, both for users and for the head monks who create the feature. In fact, it would attract more visitors and donations. It would also make people more aware of how to use PerlTidy and how useful it is and more people would put it on their own computers, especially if the proper restrictions on it's use on PerlMonks are in place.

        If PerlTidy is good to have on your own machine, it's good to have here as a web application.

        That is the flaw in your reasoning. You are talking about adding a feature that puts additional load on the perlmonks server, to do something that is very plainly the responsibility of the submitter.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: monkdiscuss [id://309225]
Approved by rob_au
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2014-09-21 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls