Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

(ichimunki) Re: Why I'm a Pod::Nazi

by ichimunki (Priest)
on Nov 22, 2001 at 07:16 UTC ( #126933=note: print w/replies, xml ) Need Help??


in reply to Why I'm a Pod::Nazi

I find that POD is great for documentation for users. That is for documenting interfaces to class/instance methods, basic usage, etc. It lends itself to sitting just outside a sub{} block, at the beginning and at the end of a piece of code.

But for good comments of the # variety, I really like Steve McConnell's suggestions in "Code Complete". Instead of writing code first you write pseudocode first-- discrete, plain English descriptions of what is to happen in this piece of code, indenting to show sub-blocks and such. Then you prepend # to each line (actually I'd just start with them there). Then you insert actual code in between those comments-- having already "rehearsed" the procedure mentally, writing the code is halfway automatic. Then if you have anything in your code that really isn't readable (but mostly it is because you use sensible variable names, keep your statements simple, etc etc, right?) you make a quick note what that does. Ditto if anything your code in has side-effects that may not be visible just reading that bit of the code. Of course, this sort of precommenting with pseudocode takes some discipline, but I find when I use this technique my code is a lot better.

Replies are listed 'Best First'.
(bmcatt) Pod::Nazi and pseudo-code
by bmcatt (Friar) on Nov 22, 2001 at 08:24 UTC
    Let me add a verbal ++ to the above. I've found (over lots of years of experience), that if you can't express it in pseudo-code you probably don't understand (or don't completely understand) exactly how you're trying to approach the solution. There are lots of times when a lack of being able to express something (completely) in pseudo-code led me to the conclusion that I didn't adequately understand the interfaces I was dealing with and the way I needed to manipulate things.

    The really retentive will then go through after the fact and add in the "why" commentary to supplement the "how" pseudo-code. Or, as a button I own says: "Code as if whoever maintains your code is a violent psychopath who knows where you live."

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2022-05-26 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?