Pages: 1 2 [3]   Go Down
Author Topic: Programming Style  (Read 1821 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8461
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 www.robgray.com

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46300
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
Edison Member
*
Karma: 29
Posts: 2051
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

80 characters comes from punched cards.
Logged

Croatia
Offline Offline
Sr. Member
****
Karma: 11
Posts: 435
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

Worst state in America
Offline Offline
God Member
*****
Karma: 24
Posts: 675
View Profile
WWW
 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
Faraday Member
**
Karma: 51
Posts: 3438
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)
Online Online
Brattain Member
*****
Karma: 332
Posts: 16568
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
Faraday Member
**
Karma: 90
Posts: 3527
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

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

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