Your longuest function!
-
Remember the old windows mesage handlers? They were often into the thousands. It is plain silly to restrict function length and end up with massive amounts of nesting. Not only does it read really badly it is a lot slower.
Truth is the subjection of reality to an individuals perception
In case you hadn't noticed, very few people write Windows apps in C these days, so that really isn't relevant. If the design is right, you really shouldn't end up with excessive nesting. :rose:
Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
-
Well I haven't pay attention to how long mine are. But the fact is, I'm porting my boss's MacOSX application to Windows and I routinely found method over... ... ... 1300 lines of code! :doh: To tone done this fact I should mention it's written in Objective-C which, like C and C++, is quite verbose. And there are (a few) comments. Yet, it's long.... That the size of a class for me! Sometimes I found it tiresome to "translate it" to proper C#...
Super Lloyd wrote:
But the fact is, I'm porting my boss's MacOSX application to Windows and I routinely found method over... ... ... 1300 lines of code
Now see you ask for ours... but you are quoting your boss' application. I think my largest function, again is a switch statement, probably smaller than this one, but several hundred lines. However... I took over a project once where the lady wrote the entire program in main() no function calls at all, repetitive operations were handled by cut-n-paste and changing variable names. It was somewhere on the order of 50,000 lines or more. I was told not to rewrite it because that would declare that the original was "bad," so I "refactored it" instead. :laugh:
_________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
-
In case you hadn't noticed, very few people write Windows apps in C these days, so that really isn't relevant. If the design is right, you really shouldn't end up with excessive nesting. :rose:
Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
-
Super Lloyd wrote:
But the fact is, I'm porting my boss's MacOSX application to Windows and I routinely found method over... ... ... 1300 lines of code
Now see you ask for ours... but you are quoting your boss' application. I think my largest function, again is a switch statement, probably smaller than this one, but several hundred lines. However... I took over a project once where the lady wrote the entire program in main() no function calls at all, repetitive operations were handled by cut-n-paste and changing variable names. It was somewhere on the order of 50,000 lines or more. I was told not to rewrite it because that would declare that the original was "bad," so I "refactored it" instead. :laugh:
_________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
Jeffry J. Brickley wrote:
Now see you ask for ours... but you are quoting your boss' application
:->
Jeffry J. Brickley wrote:
took over a project once where the lady wrote the entire program in main() no function calls at all, repetitive operations were handled by cut-n-paste and changing variable names. It was somewhere on the order of 50,000 lines or more. I was told not to rewrite it because that would declare that the original was "bad," so I "refactored it" instead.
Not bad hey! Even politicaly correct! :laugh:
-
That's why I said A4 ;P
Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
Anna-Jayne Metcalfe wrote:
That's why I said A4
but did you specify font size? I used to print 4x1 on each size of standard sheets to save paper. I've even still got the magnifying glass on the shelf above me even though I haven't done that in quite a while. I will still do it for nVidia technology papers, the strain of reading them keeps me from falling asleep from the lack of plot.
_________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
-
Jeffry J. Brickley wrote:
Now see you ask for ours... but you are quoting your boss' application
:->
Jeffry J. Brickley wrote:
took over a project once where the lady wrote the entire program in main() no function calls at all, repetitive operations were handled by cut-n-paste and changing variable names. It was somewhere on the order of 50,000 lines or more. I was told not to rewrite it because that would declare that the original was "bad," so I "refactored it" instead.
Not bad hey! Even politicaly correct! :laugh:
Super Lloyd wrote:
Your longuest function!
fess up! what is yours?? :-D
_________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
-
In case you hadn't noticed, very few people write Windows apps in C these days, so that really isn't relevant. If the design is right, you really shouldn't end up with excessive nesting. :rose:
Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
Anna-Jayne Metcalfe wrote:
In case you hadn't noticed, very few people write Windows apps in C these days, so that really isn't relevant.
you mean I am a minority again?
Anna-Jayne Metcalfe wrote:
If the design is right, you really shouldn't end up with excessive nesting.
part of it has to do with language. Pixel shader 3 finally allowed more use of high level programming structure. There was actually some people against it. Looping in parallel synced operations is dangerous to the efficiency. You've got 24 pipes and one decides to loop due to an exceptional condition and the other 23 idle waiting for it to finish. There was/is still strong resistance to function calls, loops, and high level design techniques that can shorten nested code, but result in more overhead to the compiler/CPU/GPU.
_________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
-
Well I haven't pay attention to how long mine are. But the fact is, I'm porting my boss's MacOSX application to Windows and I routinely found method over... ... ... 1300 lines of code! :doh: To tone done this fact I should mention it's written in Objective-C which, like C and C++, is quite verbose. And there are (a few) comments. Yet, it's long.... That the size of a class for me! Sometimes I found it tiresome to "translate it" to proper C#...
a 128 statement if in c++ once. (Actually 2 because I had to break off into a method call for the rest)
A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane
-
Super Lloyd wrote:
Your longuest function!
fess up! what is yours?? :-D
_________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
My Code is perfect! ;P Hu.. I don't know. Except when working with other people's work I think I never wrote absurdly long function. Although I confess I did write classes I found too .... big and intertwinned. I remember a Java project in 2003. I had a Java class... ahumm.. ~3000 lines long (I know it's little player, but at the time that was my longuest class) and it was awfully messy. Lots of variable, and many variables using in plenty of different function which makes it higly .. surprizing shall I say? I just checked in my current project my most complex class / code. The worst class / file is only 4054 lines.... I guess I can't stand big files, so I avoid it... ;) ON the other hand I have a file of 400.000 lines. But it's autogenerated!
-
a 128 statement if in c++ once. (Actually 2 because I had to break off into a method call for the rest)
A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane
Now you're talking! :omg:
-
:-O I've got a method about 230 lines long (with a lot of comments). It's the main method for a full-fledged table layout algorithm that has: * col/row width options such as fit-to-content, percent, and absolute * the ability to choose which rows/cols get "crushed" or get collapsed when things don't fit * choice of which rows/cols if any are widened to fit the remaining layout area * space prioritization for rows/cols * repeating rows/cols * at least several other features I've broken up the functionality into at least 15 methods, but the main function is still too big for my liking. -- modified at 5:03 Tuesday 1st August, 2006
I say, that's allright?! :laugh:
-
The 1400 line function was manually typed, in C, as is the whole file.
Truth is the subjection of reality to an individuals perception
I mean big swith is easy. The function could be kilometer long, yet have just a few line per case. I think it still qualify as simple! ;P
-
In case you hadn't noticed, very few people write Windows apps in C these days, so that really isn't relevant. If the design is right, you really shouldn't end up with excessive nesting. :rose:
Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
I hate to say it, but... i agree with fat_boy. Much as i love disappearing for a few days and coming back with a nice little self-contained library, i still find myself interfacing with other people's code more often than not. And once you're doing that, you can either propagate their design mistakes throughout your app, or you can buckle down and write a proper wrapper, complete with message crackers, error code translators, and exception handlers. It's ugly by necessity, and having it all in one place is an advantage.
---- Scripts i’ve known... CPhog 1.7.1.2 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.2 - printer-friendly forums Expand all 1.0 - Expand all messages In-place Delete 1.0 - AJAX-style post delete Syntax 0.1 - Syntax highlighting for code blocks in the forums
-
Anna-Jayne Metcalfe wrote:
That's why I said A4
but did you specify font size? I used to print 4x1 on each size of standard sheets to save paper. I've even still got the magnifying glass on the shelf above me even though I haven't done that in quite a while. I will still do it for nVidia technology papers, the strain of reading them keeps me from falling asleep from the lack of plot.
_________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
Yep. Wingdings 24pt. ;P I normally print two pages per sheet, which is just about comfortable reading, and also keeps the number of trees I use on printouts down.
Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
-
I hate to say it, but... i agree with fat_boy. Much as i love disappearing for a few days and coming back with a nice little self-contained library, i still find myself interfacing with other people's code more often than not. And once you're doing that, you can either propagate their design mistakes throughout your app, or you can buckle down and write a proper wrapper, complete with message crackers, error code translators, and exception handlers. It's ugly by necessity, and having it all in one place is an advantage.
---- Scripts i’ve known... CPhog 1.7.1.2 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.2 - printer-friendly forums Expand all 1.0 - Expand all messages In-place Delete 1.0 - AJAX-style post delete Syntax 0.1 - Syntax highlighting for code blocks in the forums
I actually agree...but these are all special cases (I'm also thinking of the previous two replies), rather than the norm for most developers. My point being that if you had to maintain any non-trivial (my emphasis - message crackers are a different story) method of more than 100-200 lines you can all too easily find yourself misunderstanding the paths through the code. That leads to an increased risk of hard to find bugs appearing later as the code is maintained or enhanced. Cyclometic complexity is of course arguably a better all-purpose measure of the maintainability of a method - it will assign a low complexity to a long method with very simple control flow, and a far higher one to a shorter method with excessive nesting. If you can successfully balance complexity metrics with a code density/length/nesting you feel comfortable maintaining you are more likely to end up with code you can work with in the long term.
Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
-
Who mentioned C? A non MFC app can have a defwindowproc in C++. Design has nothing to do with implementation, and in many cases huge switch statements are the best implementation.
Truth is the subjection of reality to an individuals perception
A long switch statement is likely to be very linear in flow, and therefore less of an issue than most methods. There are (as I pointed out in my reply below) a bit of a special case today. Run a cyclomatic complexity analysis on methods within your code and you'll see what I mean.
Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
-
I actually agree...but these are all special cases (I'm also thinking of the previous two replies), rather than the norm for most developers. My point being that if you had to maintain any non-trivial (my emphasis - message crackers are a different story) method of more than 100-200 lines you can all too easily find yourself misunderstanding the paths through the code. That leads to an increased risk of hard to find bugs appearing later as the code is maintained or enhanced. Cyclometic complexity is of course arguably a better all-purpose measure of the maintainability of a method - it will assign a low complexity to a long method with very simple control flow, and a far higher one to a shorter method with excessive nesting. If you can successfully balance complexity metrics with a code density/length/nesting you feel comfortable maintaining you are more likely to end up with code you can work with in the long term.
Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
Anna-Jayne Metcalfe wrote:
My point being that if you had to maintain any non-trivial [...] method of more than 100-200 lines you can all too easily find yourself misunderstanding the paths through the code.
No arguments there! :)
---- Scripts i’ve known... CPhog 1.7.1.2 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.2 - printer-friendly forums Expand all 1.0 - Expand all messages In-place Delete 1.0 - AJAX-style post delete Syntax 0.1 - Syntax highlighting for code blocks in the forums
-
A long switch statement is likely to be very linear in flow, and therefore less of an issue than most methods. There are (as I pointed out in my reply below) a bit of a special case today. Run a cyclomatic complexity analysis on methods within your code and you'll see what I mean.
Anna :rose: Currently working mostly on: Visual Lint :cool: Anna's Place | Tears and Laughter "Be yourself - not what others think you should be" - Marcia Graesch "Anna's just a sexy-looking lesbian tart" - A friend, trying to wind me up. It didn't work.
That is true, this switch statement handles about 10 cases, each one then looks at the state machine, which can be in one of 12 states. Inside some of these a lot of data needs pulling apart. However, I prefer to see the complexity all in one place with just two or three layers of nesting. One thing I really hate is pointless nesting where each layer really does very little work buit calls downm to a lower layer and so on. You can spend hours tracking downthe code that actually does something.
Truth is the subjection of reality to an individuals perception