Loading...
Pages: 1 2 [3]   Go Down
Author Topic: Programming Style  (Read 903 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 75
Posts: 6970
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad http://www.robgray.com

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 334
Posts: 36442
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
God Member
*****
Karma: 9
Posts: 839
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

80 characters comes from punched cards.
Logged

Croatia
Offline Offline
Full Member
***
Karma: 9
Posts: 243
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley
Logged

Offline Offline
Sr. Member
****
Karma: 15
Posts: 463
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
    }
Logged

New Jersey
Offline Offline
Edison Member
*
Karma: 26
Posts: 2450
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 282
Posts: 15443
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-wink  Humans, can't live without them, can't live with them.

Lefty
Logged

East Anglia (UK)
Offline Offline
Edison Member
*
Karma: 55
Posts: 1599
May all of your blinks be without delay
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 2 [3]   Go Up
Print
 
Jump to: