Go Down

Topic: Programming Style (Read 2 times) previous topic - next topic

Graynomad

I also aim to get a function on a page, often don't achieve that but it's a good guideline.

And yes I think it's totally based on the screen size and in the past paper size which had more lines of course (does anyone actually print out a program these days? I haven't for about 15 years).

I saw on another forum the other day that the special editor they use for their board limits the line length to 80 chars...now that's bit 80s I think but OTOH lines shouldn't be too long either.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

PaulS

Quote
No.  Display resolution had increased.

So, what you can see without scrolling defines the optimum function size. Interesting.

I'd guess that when the body is idle (not scrolling up and down), the brain is more active, spotting what doesn't look right, and that the adage out of sight, out of mind applies with coding, too.

michinyon

80 characters comes from punched cards.

Shpaget

I've been told once that if my function has more than 50 lines that I'm doing something wrong and only inviting trouble.

As for pronounciation, I was thinking along the same line, but mommy thought not to swear. :)

Krupski


That's the one I use.


What REALLY bugs me is code like this:

    if (flag)
        { setbit(1); }
    else
        { setbit(0); }


I much prefer:

    if (flag) {
        setbit(1);
    } else {
        setbit(0);
    }
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

wildbill

Quote
I've been told once that if my function has more than 50 lines that I'm doing something wrong and only inviting trouble.


I think my limit is a lot lower than that - anything over 20 would have me wondering how to refactor it. Complexity plays into that too - any more than three control flow statements and I'll want to break out some of it into a separate function. Basically, I want to be able to look at any function in my code and see immediately what it does.

retrolefty



That's the one I use.


What REALLY bugs me is code like this:

    if (flag)
        { setbit(1); }
    else
        { setbit(0); }


I much prefer:

    if (flag) {
        setbit(1);
    } else {
        setbit(0);
    }



Funny of the two I prefer the first example.  ;)  Humans, can't live without them, can't live with them.

Lefty

UKHeliBob

Quote
Basically, I want to be able to look at any function in my code and see immediately what it does.

I agree.  Good function names help a lot too, as does having functions that do the thing that is indicated by their name rather than several things.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up