Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Ideological Programming Question...

Ideological Programming Question...

Scheduled Pinned Locked Moved The Lounge
questionbusiness
58 Posts 40 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T ToddHileHoffer

    Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere? The program I am working on has one method that will probably be about 200-250 lines of code. Is too much for a single method? Should I create a couple helper methods just to make it more readable?

    I didn't get any requirements for the signature

    P Offline
    P Offline
    peterchen
    wrote on last edited by
    #25

    ToddHileHoffer wrote:

    Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere?

    Yes.

    ToddHileHoffer wrote:

    The program I am working on has one method that will probably be about 200-250 lines of code.

    I have bigger.

    ToddHileHoffer wrote:

    Is too much for a single method? Should I create a couple helper methods just to make it more readable?

    Yes.

    Don't attribute to stupidity what can be equally well explained by buerocracy.
    My latest article | Linkify!| FoldWithUs! | sighist

    M 1 Reply Last reply
    0
    • T ToddHileHoffer

      Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere? The program I am working on has one method that will probably be about 200-250 lines of code. Is too much for a single method? Should I create a couple helper methods just to make it more readable?

      I didn't get any requirements for the signature

      A Offline
      A Offline
      Abu Mami
      wrote on last edited by
      #26

      ... without being flamed. Of course it's an "Ideological Programming Question".. pretty clever way to sneak a programming question into the Lounge :) And IMHO, always break thing up into small chunks - easier to read, and even if reuse doesn't seem apparent now, it may someday.

      T 1 Reply Last reply
      0
      • A Abu Mami

        ... without being flamed. Of course it's an "Ideological Programming Question".. pretty clever way to sneak a programming question into the Lounge :) And IMHO, always break thing up into small chunks - easier to read, and even if reuse doesn't seem apparent now, it may someday.

        T Offline
        T Offline
        ToddHileHoffer
        wrote on last edited by
        #27

        Well, it is language agnostic. I guess I could have posted the question in Design and Architecture but I figured not that many people would read it. I also thought most people reading the lounge would have an opinion and it would be interested in the topic.

        I didn't get any requirements for the signature

        A 1 Reply Last reply
        0
        • D Dan Neely

          Kevin McFarlane wrote:

          If you're doing .NET then try running it against Reflector + code metrics plugin

          I'll have to take a look at this... I didn't even know reflector had a plugin engine. Are there any others I should take a look at?

          It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains. -- Pride and Prejudice and Zombies

          K Offline
          K Offline
          Kevin McFarlane
          wrote on last edited by
          #28

          See .NET Reflector Add-Ins[^] I've also used Graph. But for code metrics I mostly use the real-time tool that comes with CodeRush/Refactor! Pro (updates complexity graphs dynamically as you edit the code) and serves as a visual cue to when you should refactor.

          Kevin

          1 Reply Last reply
          0
          • P peterchen

            ToddHileHoffer wrote:

            Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere?

            Yes.

            ToddHileHoffer wrote:

            The program I am working on has one method that will probably be about 200-250 lines of code.

            I have bigger.

            ToddHileHoffer wrote:

            Is too much for a single method? Should I create a couple helper methods just to make it more readable?

            Yes.

            Don't attribute to stupidity what can be equally well explained by buerocracy.
            My latest article | Linkify!| FoldWithUs! | sighist

            M Offline
            M Offline
            Mustafa Ismail Mustafa
            wrote on last edited by
            #29

            peterchen wrote:

            I have bigger.

            Programmer's "Method Envy"?

            If the post was helpful, please vote! Current activities: Book: Devils by Fyodor Dostoyevsky Project: Hospital Automation, final stage Learning: Image analysis, LINQ Now and forever, defiant to the end. What is Multiple Sclerosis[^]?

            P 1 Reply Last reply
            0
            • T ToddHileHoffer

              Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere? The program I am working on has one method that will probably be about 200-250 lines of code. Is too much for a single method? Should I create a couple helper methods just to make it more readable?

              I didn't get any requirements for the signature

              A Offline
              A Offline
              Anthony Mushrow
              wrote on last edited by
              #30

              Pff, having separate methods is just a fancy way of putting small comments in your code. You should just have one function called main and your program goes in there. Simple.

              My current favourite word is: Delicious!

              -SK Genius

              Game Programming articles start -here[^]-

              B 1 Reply Last reply
              0
              • M Mustafa Ismail Mustafa

                peterchen wrote:

                I have bigger.

                Programmer's "Method Envy"?

                If the post was helpful, please vote! Current activities: Book: Devils by Fyodor Dostoyevsky Project: Hospital Automation, final stage Learning: Image analysis, LINQ Now and forever, defiant to the end. What is Multiple Sclerosis[^]?

                P Offline
                P Offline
                peterchen
                wrote on last edited by
                #31

                Envy? Pride! ;P

                Don't attribute to stupidity what can be equally well explained by buerocracy.
                My latest article | Linkify!| FoldWithUs! | sighist

                1 Reply Last reply
                0
                • A Anthony Mushrow

                  Pff, having separate methods is just a fancy way of putting small comments in your code. You should just have one function called main and your program goes in there. Simple.

                  My current favourite word is: Delicious!

                  -SK Genius

                  Game Programming articles start -here[^]-

                  B Offline
                  B Offline
                  Big Daddy Farang
                  wrote on last edited by
                  #32

                  But then you haven't really done anything. Everything should be in one function that is called by main(). "Look at all this program does with just one line of code." Now we're getting somewhere!

                  BDF People don't mind being mean; but they never want to be ridiculous. -- Moliere

                  1 Reply Last reply
                  0
                  • T ToddHileHoffer

                    Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere? The program I am working on has one method that will probably be about 200-250 lines of code. Is too much for a single method? Should I create a couple helper methods just to make it more readable?

                    I didn't get any requirements for the signature

                    M Offline
                    M Offline
                    M dHatter
                    wrote on last edited by
                    #33

                    Why make life easy? make you code complicated that way you stay employed. :laugh:

                    "I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein

                    1 Reply Last reply
                    0
                    • T ToddHileHoffer

                      Well, it is language agnostic. I guess I could have posted the question in Design and Architecture but I figured not that many people would read it. I also thought most people reading the lounge would have an opinion and it would be interested in the topic.

                      I didn't get any requirements for the signature

                      A Offline
                      A Offline
                      Abu Mami
                      wrote on last edited by
                      #34

                      ToddHileHoffer wrote:

                      I guess I could have posted the question in Design and Architecture

                      Nah - I'm cool, no complaints here. I just thought it funny that the Lounge states clearly "No programming questions", and of course, the Subject of your post was exactly that - err, with the addition of Ideological. I think you're correct about the Design and Architecture forum - I personally have never visited. Take care

                      1 Reply Last reply
                      0
                      • T ToddHileHoffer

                        Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere? The program I am working on has one method that will probably be about 200-250 lines of code. Is too much for a single method? Should I create a couple helper methods just to make it more readable?

                        I didn't get any requirements for the signature

                        A Offline
                        A Offline
                        Anna Jayne Metcalfe
                        wrote on last edited by
                        #35

                        IMHO 200 lines of code is at least 10 times the size a method should be if you want it to be testable. Make it testable, and maintainable will follow quite happily. :)

                        Anna :rose: Having a bad bug day? Tech Blog | Anna's Place | Tears and Laughter "If mushy peas are the food of the devil, the stotty cake is the frisbee of God"

                        S 1 Reply Last reply
                        0
                        • T ToddHileHoffer

                          Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere? The program I am working on has one method that will probably be about 200-250 lines of code. Is too much for a single method? Should I create a couple helper methods just to make it more readable?

                          I didn't get any requirements for the signature

                          B Offline
                          B Offline
                          bulg
                          wrote on last edited by
                          #36

                          break it up smartly, because catch-all "util.c" files are annoying too

                          1 Reply Last reply
                          0
                          • C Chris Losinger

                            ToddHileHoffer wrote:

                            Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere?

                            sure, as long as it's an obvious break. i'm not so picky about function size that i'll spend too much time trying to find ways to break down a function that gets a little long. and if it's a performance-critical function, i'll avoid function calls as best i can.

                            image processing toolkits | batch image processing

                            S Offline
                            S Offline
                            S Senthil Kumar
                            wrote on last edited by
                            #37

                            Chris Losinger wrote:

                            and if it's a performance-critical function, i'll avoid function calls as best i can

                            Unmanaged code - yes, managed code - maybe. The CLR JIT compiler operates on method level granularity, so if the method has sections of code that is executed very rarely, for example, then moving them to a separate method actually improves performance - the JITter is faster because it doesn't have to JIT the other method right away, the generated code is smaller etc..

                            Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

                            D 1 Reply Last reply
                            0
                            • T ToddHileHoffer

                              Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere? The program I am working on has one method that will probably be about 200-250 lines of code. Is too much for a single method? Should I create a couple helper methods just to make it more readable?

                              I didn't get any requirements for the signature

                              A Offline
                              A Offline
                              Adriaan Davel
                              wrote on last edited by
                              #38

                              One of the really cool (non-functional) features of Visual Studio is regions. I like to group sections of code together with regions if the code becomes less self documenting, and then I often find myself extracting an entire region to a sub method later...

                              ____________________________________________________________ Be brave little warrior, be VERY brave

                              1 Reply Last reply
                              0
                              • T ToddHileHoffer

                                Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere? The program I am working on has one method that will probably be about 200-250 lines of code. Is too much for a single method? Should I create a couple helper methods just to make it more readable?

                                I didn't get any requirements for the signature

                                J Offline
                                J Offline
                                Jonas Hammarberg
                                wrote on last edited by
                                #39

                                Yes. If I can make a code sequence easier to understand by breaking it out into a function with a good name, I'll do it -- even if the original function only holds five lines... As todays compilers are rather smart the cost of function calls are virtually nil and making it easy for the next guy (who might be your elderly alzheimerish self) is a righteous goal in itself. Now, if I only could find a way to break up a VB6 select case monster... [voice fading away]

                                1 Reply Last reply
                                0
                                • T ToddHileHoffer

                                  Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere? The program I am working on has one method that will probably be about 200-250 lines of code. Is too much for a single method? Should I create a couple helper methods just to make it more readable?

                                  I didn't get any requirements for the signature

                                  P Offline
                                  P Offline
                                  Plamen Dragiyski
                                  wrote on last edited by
                                  #40

                                  As a hobby OS developing, I create bootable hex editor, which a __cdecl based draw function of more than 1000 lines of ASM (Since NASM accept only one instruction per line). Then I tried to optimize it (for a 512-bytes bootable program contest). After I spent around four hours trying to understand what and where MY program do expected tasks, I decided to rewrite it, but this time using comments. So you can have 200-250 lines for method if you keep comments, but I really suggest you NOT to be in ASM ;)

                                  1 Reply Last reply
                                  0
                                  • T ToddHileHoffer

                                    Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere? The program I am working on has one method that will probably be about 200-250 lines of code. Is too much for a single method? Should I create a couple helper methods just to make it more readable?

                                    I didn't get any requirements for the signature

                                    D Offline
                                    D Offline
                                    dazfuller
                                    wrote on last edited by
                                    #41

                                    It depends as to whether or not the logic of the operation belongs together, typically though if I get more than about 150 lines I'll try and break it up or if I end up going more than about 4-5 conditional statements deep. Also if the code is doing business logic, database access and file I/O then I'll break those parts out into separate functions and possible even different code files/projects.

                                    1 Reply Last reply
                                    0
                                    • M Michael Bookatz

                                      I think the men in the white coats will be along soon...

                                      B Offline
                                      B Offline
                                      Baeltazor
                                      wrote on last edited by
                                      #42

                                      lol

                                      hopingToCode wrote:

                                      I think the men in the white coats will be along soon...

                                      1 Reply Last reply
                                      0
                                      • T ToddHileHoffer

                                        Would you break up a method into more then one method just to make it smaller even if the code is not going to be used elsewhere? The program I am working on has one method that will probably be about 200-250 lines of code. Is too much for a single method? Should I create a couple helper methods just to make it more readable?

                                        I didn't get any requirements for the signature

                                        U Offline
                                        U Offline
                                        User 3401432
                                        wrote on last edited by
                                        #43

                                        Readability, Readability, Readability. Oh yeah. It should be understandable. Sure. Break it up a little, into logical pieces. Make it yours. It sounds like it might be any way. After our family packed up from a weekend of camping, we'd stand side-by-side and "walk" our camp site, and pick up any trash or sticks. We'd leave the site in better condition than we found it. I apply the same policy to codeing. Leave the site in better condition than you found it. Break up a method here. Comment better there. ... you might return there again someday. ;)

                                        S 1 Reply Last reply
                                        0
                                        • S S Senthil Kumar

                                          Chris Losinger wrote:

                                          and if it's a performance-critical function, i'll avoid function calls as best i can

                                          Unmanaged code - yes, managed code - maybe. The CLR JIT compiler operates on method level granularity, so if the method has sections of code that is executed very rarely, for example, then moving them to a separate method actually improves performance - the JITter is faster because it doesn't have to JIT the other method right away, the generated code is smaller etc..

                                          Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

                                          D Offline
                                          D Offline
                                          dojohansen
                                          wrote on last edited by
                                          #44

                                          But doesn't the compiler ever inline called code? Say I have a small block of just a few lines of code, but that is used in multiple places. For the sake of an example, let's say a "blend" method that takes a foreground and background pixel and an alpha parameter. If I now write a method to do this over an entire image, I'd have a nested loop where the inner loop called blend() on each iteration. It seems clear to me that it'd be nice if this was inlined, though at the same time I would of course love not having to introduce redundancy in my code. I believe the compiler - when compiling "with optimization" - does this sort of thing, but I often thought it would have been nice to have some way of telling the compiler where I'd like it to inline code, leave code external, or - by default - decide for itself what to do. It seems to me a preprocessor directive would be appropriate, or even an attribute, like this:

                                          [Inline("blend")]
                                          Image blend(Image foreground, Image background, double alpha)
                                          {
                                          // ...
                                          for (x=0; x < result.Width; x++)
                                          for (y=0; y < result.Height; y++)
                                          result.SetPixel(x, y, blend(...));
                                          return result;
                                          }

                                          S 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups