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

Re: Re: IYHO, what do you consider good code?

by halley (Prior)
on Jun 13, 2003 at 12:11 UTC ( #265652=note: print w/replies, xml ) Need Help??

in reply to Re: IYHO, what do you consider good code?
in thread IYHO, what do you consider good code?

A couple of my tips on style, regardless of language.

Strategy in comments, tactics in code. Don't explain every statement or operator, but explain the goal of the following few statements or chunk of code. Another suggestion is to write the comments first as you're thinking about what you want to get done, then "translate" the intent into implementation. Don't write clever code which needs explaining-- just accomplish the tactics simply and directly.

There are only three numbers in Computer Science. Zero, One and N. Zero refers to the complete lack of something: no variable, no method, no capability, no support. One refers to a sole solution: one variable, one method, my way or the highway. N represents an arbitrary scalability, an array which can grow, a method reference, a parameterized technique with room to expand. If you find a need for two, structure your code so it can handle three, four or more. That goes for allocations, methods, strategies, resources, resource types, everything.

[ e d @ h a l l e y . c c ]

  • Comment on Re: Re: IYHO, what do you consider good code?

Replies are listed 'Best First'.
Re: Re: Re: IYHO, what do you consider good code?
by DrHyde (Prior) on Jun 20, 2003 at 09:00 UTC
    There are only three numbers in Computer Science. Zero, One and N

    Someone suggested on the mailing list some time ago that if you ever use a constant other than 0 or 1 you should comment why. I can see his point, although I make exceptions for well-known scaling factors like 7, 24, 60, 3600 and 86400 when mangling times and so on. I also don't bother documenting the constants when I do something like:

    $foo = ($foo & 112) >> 4;
    although that gets wrapped up in a little subroutine whose function is documented, including a pointer to the relevant standard. But just about every other constant I do inded comment. eg, from my current project ...
    $price /= 100; # convert from pence to pounds ... $time += 23 * 3600 # because we're changing timezone

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://265652]
Discipulus progammer is an organism that transforms caffeine into software..
[LanX]: hmm interesting link
[Discipulus]: Eduardo De Filippo explains how to do coffe - ITA

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2017-01-16 11:03 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (149 votes). Check out past polls.