Pages: 1 2 [3]   Go Down
Author Topic: Programming Style  (Read 2434 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
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
Online Online
Brattain Member
*****
Karma: 653
Posts: 50923
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
Faraday Member
**
Karma: 62
Posts: 3080
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

80 characters comes from punched cards.
Logged

Croatia
Offline Offline
God Member
*****
Karma: 13
Posts: 524
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: 32
Posts: 819
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

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

New Jersey
Offline Offline
Faraday Member
**
Karma: 72
Posts: 3763
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: 362
Posts: 17307
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: 118
Posts: 4405
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: