Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Re: Perl Programming guidelines/rules

by BrowserUk (Patriarch)
on Nov 21, 2002 at 20:48 UTC ( [id://214915]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Programming guidelines/rules
in thread Perl Programming guidelines/rules

Again, it's all a matter of taste, but

  • # method: getExitCode()

    This just replicates the sub getExitCode { line.

  • # Author: Logan logan@eng.somecompany.com

    Authorship is often mixed even within a script and becomes redundant as soon as the author moves on. Email id's change.

    In a corporate environment, contact information should be in terms of "ownership" (in the 'who is responsible for this code') rather than who actually coded it. In any case, this information is better located in source-control database where it can easily be viewed and aggregated with other such info rather than in the source where it becomes out of date.

  • # Usage: $ahm->getExitCode();

    I understand that this is just a simple example, but I see no benefit in this line at all. It gives me no information not readily available two or three lines below.

    Even if the method takes parameters, these cannot easily be added to this line, and would need to be documented seperately.

  • # return : int

    This might make some sense in a C program, though even then, the function prototype serves much better and is more likely to be correct and up-to-date. What's an "int" in Perl terms? 16-bits? 32-bits?

  • # Gets the exit code from a process and returns it

    If the sub/method name is well chosen, as this appears to be, I see this as redundant.

  • #------------------------------------------- x 2

    Ugg! A personal hate, not a bad as

    ############################################# or

    /*********************************************

    But not much better. My preference is for whitespace to black, but again its all personal (or corporate edict).

    Can you imagine reading your favorite novell if every paragraph started with

    #------------------------------------------- # method: setSceneForSurpriseEnding() # Author: WilliamS@YeTheatre.Olde # Usage: read->setTheSceneForSurpriseEnding() # return : SceneSet # Sets the scene for the surprise ending and returns it #-------------------------------------------

    I hope you won't take my levity too seriously, it's just one nobodys opinion:)

When I first set about trying to understand a piece of code, I generally ignore the comments and have even written several macros to remove them. Too many times I have been coersed into believing them when they only reflected the orginators intentions and not his actions. This can happen easily enough from reading the variable names as I said elsewhere today, but generally the authors actions are more clearly indicated by the code than by comments which all too frequently become out of date and therefore worse than just redundant, they can be misleading.

Of course, a comment warning of an unusually conveluted algorithm or indicating where (for example) additional punctuation is critical to the correct interpretation of the code are necessary and helpful. I also find it helpful if the coder indicates why s/he did certain unusual or unituative things in a particular way. Beyond that, I generally feel that most comments in code are redundant and serve only to obscure the forest with trees.

An untypical, and probably unpopular opinion, but one I have arrived at through bitter experience.


Okay you lot, get your wings on the left, halos on the right. It's one size fits all, and "No!", you can't have a different color.
Pick up your cloud down the end and "Yes" if you get allocated a grey one they are a bit damp under foot, but someone has to get them.
Get used to the wings fast cos its an 8 hour day...unless the Govenor calls for a cyclone or hurricane, in which case 16 hour shifts are mandatory.
Just be grateful that you arrived just as the tornado season finished. Them buggers are real work.

Replies are listed 'Best First'.
Re: Re: Re: Perl Programming guidelines/rules
by logan (Curate) on Nov 22, 2002 at 18:50 UTC
    1) * # method: getExitCode() This just replicates the sub getExitCode { line.

    Yes, it does. That's because I used the simplest possible example for the sake of brevity in this writeup.

    2) Email. I work for a small company that's had a lot of management turnover. I want credit for my code. I also want to make it easy for a new hire to find me if they have questions. I still remember the afternoon I spent wandering around trying to find out who wrote an obscure chunk of code.

    3) # return : int And most of my co-workers use C. Int mostly serves to contrast from returning a string, array, hash, hash ref, or whatever else I may use.

    I recently inherited a major chunk of code from a departed engineer. It was his discipline in using this commenting format that made it possible for me to figure out what he was doing. After years of inheriting spaghetti code, I appreciate a little discipline. Don't get me started on the "Perl Coder" who didn't understand arrays and refused to use them.

    -Logan
    "What do I want? I'm an American. I want more."

Re^3: Perl Programming guidelines/rules
by Aristotle (Chancellor) on Nov 27, 2002 at 16:25 UTC
    When the code and the comments disagree, both are probably wrong.
    -- Norman Schryer
    :)

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://214915]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-16 17:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found