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. Programming standards...no flaming please!

Programming standards...no flaming please!

Scheduled Pinned Locked Moved The Lounge
csharpdatabasequestion
84 Posts 36 Posters 0 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.
  • L leckey 0

    I wasn't really sure if this belonged to a particular message board so please no flaming! I am wondering what others habits are when it comes to programming. I just inherited a huge VB.NET program. In one VB page it has over 10k lines of code. One function within that has about half those lines. Do you have a "limit" on how big/small a function/method/class should be before breaking it into smaller parts? We just used the analyzer on this thing and found one case statement has over 70 routes to go. So I'm hoping to clean this puppy up. BTW...heat index is currently at 109 degrees. Hope everyone else is staying cool.

    M Offline
    M Offline
    Michael A Barnhart
    wrote on last edited by
    #29

    leckey wrote:

    Do you have a "limit" on how big/small a function

    No, so long as it is a clear and understandable. If a section is reused then it should be broken out is more of a rule then just length of code.

    leckey wrote:

    one case statement has over 70 routes to go.

    Just my opinion but that does not sound understandable.

    leckey wrote:

    I'm hoping to clean this puppy up.

    go to it. "Yes I know the voices are not real. But they have some pretty good ideas."

    1 Reply Last reply
    0
    • L led mike

      leckey wrote:

      Do you have a "limit" on how big/small a function/method/class should be before breaking it into smaller parts?

      No. Object Oriented Analysis and Design is the solution.

      leckey wrote:

      In one VB page it has over 10k lines of code. One function within that has about half those lines.

      I once touched VB with a ten foot pole. :-D I have seen C/C++ code that is just as bad... actually worse since it was using pointers out the arse! Old non structured C code was typically littered with gigantic global structures filled with pointers and giant functions to go with them. allocs and frees all over the place resulting in massive memory leaks. I once saw an entire company port C code to C++ by replacing all the alloc/free calls with new/delete. That was it... done porting to C++! :laugh: "Too many freaks... not enough circuses" :((

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #30

      led mike wrote:

      I once touched VB with a ten foot pole.

      What happened to the 10 foot pole? Did it rot apart?

      L 1 Reply Last reply
      0
      • E Ennis Ray Lynch Jr

        I was just offering a reminder that formal training is no gaurantee of good results. 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

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #31

        Ennis Ray Lynch, Jr. wrote:

        I was just offering a reminder that formal training is no gaurantee of good results

        I've seen formal training have both good and bad results. It depends on the teacher and students.

        1 Reply Last reply
        0
        • L leckey 0

          I wasn't really sure if this belonged to a particular message board so please no flaming! I am wondering what others habits are when it comes to programming. I just inherited a huge VB.NET program. In one VB page it has over 10k lines of code. One function within that has about half those lines. Do you have a "limit" on how big/small a function/method/class should be before breaking it into smaller parts? We just used the analyzer on this thing and found one case statement has over 70 routes to go. So I'm hoping to clean this puppy up. BTW...heat index is currently at 109 degrees. Hope everyone else is staying cool.

          L Offline
          L Offline
          leckey 0
          wrote on last edited by
          #32

          Going through a function and saw this: Print(FileNumber, CStr(System.Math.Round(.Horiz.ZBracedAllowableLoad(Garbage) * Tower.AllowableStressIncrease, 2)) & ",") Guess what garbage is? Dim Garbage As String = "" So I emailed my boss (in TX). Here is the conversation. Me: Why the one space of garbage? Him: The function being called there returns a value in that parameter, but in this case, it is not needed Me: Okay, maybe this is a dumb question, but why not overload that function to not return a value? Him: Not a huge priority, it could be….

          P J 2 Replies Last reply
          0
          • L leckey 0

            I wasn't really sure if this belonged to a particular message board so please no flaming! I am wondering what others habits are when it comes to programming. I just inherited a huge VB.NET program. In one VB page it has over 10k lines of code. One function within that has about half those lines. Do you have a "limit" on how big/small a function/method/class should be before breaking it into smaller parts? We just used the analyzer on this thing and found one case statement has over 70 routes to go. So I'm hoping to clean this puppy up. BTW...heat index is currently at 109 degrees. Hope everyone else is staying cool.

            J Offline
            J Offline
            Jeremy Falcon
            wrote on last edited by
            #33

            I'm with Joe Woodbury on this one. I don't think you should split up a function just because it's 12 lines long, that's just as crazy as a 5K long function (especially considering the overhead involved and the potential for stack overflows in recursive situations). It should be based on logical scope of processing in a modular fashion. However, 5K lines for one function sounds like really poor design and zero modularity IMO. It doesn't matter how complex the task, most likely it can be broken down into different parts, which most certainly helps with unit testing as well. With that being said and on a different topic, I do reuse temp variables and/or buffers in the same function to save memory, increase speed, etc. but at the point I swap over the intent of the variable there's always a comment saying what I'm doing with it. Granted, this is for temp data only; I won't do that with data meant to represent something in particular. Jeremy Falcon

            1 Reply Last reply
            0
            • L leckey 0

              Going through a function and saw this: Print(FileNumber, CStr(System.Math.Round(.Horiz.ZBracedAllowableLoad(Garbage) * Tower.AllowableStressIncrease, 2)) & ",") Guess what garbage is? Dim Garbage As String = "" So I emailed my boss (in TX). Here is the conversation. Me: Why the one space of garbage? Him: The function being called there returns a value in that parameter, but in this case, it is not needed Me: Okay, maybe this is a dumb question, but why not overload that function to not return a value? Him: Not a huge priority, it could be….

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #34

              leckey wrote:

              Him: The function being called there returns a value in that parameter, but in this case, it is not needed

              Then why have anything being passed if it isn't going to be used? Looks scary :)

              1 Reply Last reply
              0
              • L leckey 0

                Going through a function and saw this: Print(FileNumber, CStr(System.Math.Round(.Horiz.ZBracedAllowableLoad(Garbage) * Tower.AllowableStressIncrease, 2)) & ",") Guess what garbage is? Dim Garbage As String = "" So I emailed my boss (in TX). Here is the conversation. Me: Why the one space of garbage? Him: The function being called there returns a value in that parameter, but in this case, it is not needed Me: Okay, maybe this is a dumb question, but why not overload that function to not return a value? Him: Not a huge priority, it could be….

                J Offline
                J Offline
                Jeremy Falcon
                wrote on last edited by
                #35

                leckey wrote:

                Not a huge priority, it could be….

                Translation: "I can't design software." Hell, I don't even use "sometimes unused" output params in C. Hey, he's not my boss, so I can say it. :laugh: Jeremy Falcon

                1 Reply Last reply
                0
                • C Christian Graus

                  If you inherited it from someone within the company, go and smack them on the head. No code file should be 10k lines. Some functions may tend to be long, but they should be refactored where-ever possible, ideally I would say 30 lines is a max for a function. The book that covers all of this is called Code Complete. If you don't own it, buy it. While I found I knew most of what it was saying, I still found it exciting to see it all in written form, with logical explanations for the benefit of people like the clown who wrote the code you're now looking at. I am however cautious about refactoring existing code, do it if you can, but beware, lest you go crazy and spend heaps of time chasing an ideal that may introduce bugs in code that already works. Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                  L Offline
                  L Offline
                  led mike
                  wrote on last edited by
                  #36

                  Christian Graus wrote:

                  The book that covers all of this is called Code Complete

                  4 cups of coffee: $3.25 Bag of M&M peanuts: $2.49 Surfing Code Project: Free Don Miguel's comment on Code Complete[^]: Priceless There are some things money can't buy, for everything else there's Mastercard :-D

                  L R 2 Replies Last reply
                  0
                  • P Paul Conrad

                    led mike wrote:

                    I once touched VB with a ten foot pole.

                    What happened to the 10 foot pole? Did it rot apart?

                    L Offline
                    L Offline
                    led mike
                    wrote on last edited by
                    #37

                    No he hated VB so he quit and moved back to Poland.

                    P 1 Reply Last reply
                    0
                    • L leckey 0

                      I wasn't really sure if this belonged to a particular message board so please no flaming! I am wondering what others habits are when it comes to programming. I just inherited a huge VB.NET program. In one VB page it has over 10k lines of code. One function within that has about half those lines. Do you have a "limit" on how big/small a function/method/class should be before breaking it into smaller parts? We just used the analyzer on this thing and found one case statement has over 70 routes to go. So I'm hoping to clean this puppy up. BTW...heat index is currently at 109 degrees. Hope everyone else is staying cool.

                      C Offline
                      C Offline
                      Christian Graus
                      wrote on last edited by
                      #38

                      leckey wrote:

                      We just used the analyzer on this thing and found one case statement has over 70 routes to go.

                      Wow - I missed this. Huge case statements sometimes show a need for polymorphism ( that is, each case becomes a class ). Other time, they just may show incompetence. Does it have 70 different cases, or is it rife with goto statements ? Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                      L 1 Reply Last reply
                      0
                      • L led mike

                        No he hated VB so he quit and moved back to Poland.

                        P Offline
                        P Offline
                        Paul Conrad
                        wrote on last edited by
                        #39

                        led mike wrote:

                        No he hated VB so he quit and moved back to Poland.

                        :laugh::laugh::laugh:

                        1 Reply Last reply
                        0
                        • C Christian Graus

                          leckey wrote:

                          We just used the analyzer on this thing and found one case statement has over 70 routes to go.

                          Wow - I missed this. Huge case statements sometimes show a need for polymorphism ( that is, each case becomes a class ). Other time, they just may show incompetence. Does it have 70 different cases, or is it rife with goto statements ? Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                          L Offline
                          L Offline
                          leckey 0
                          wrote on last edited by
                          #40

                          I'm not sure. He was playing with the new analyzer we got and just told me about it. I'm just starting to go through the code to figure it out. It's an engineering program so it's a lot of "trying" to get the smallest weight depending on the factors (of which there seem to be a zillion).

                          L 1 Reply Last reply
                          0
                          • L led mike

                            Christian Graus wrote:

                            The book that covers all of this is called Code Complete

                            4 cups of coffee: $3.25 Bag of M&M peanuts: $2.49 Surfing Code Project: Free Don Miguel's comment on Code Complete[^]: Priceless There are some things money can't buy, for everything else there's Mastercard :-D

                            L Offline
                            L Offline
                            leckey 0
                            wrote on last edited by
                            #41

                            Ooh, you better hide! They'll get you for copyright infringement!:-D

                            1 Reply Last reply
                            0
                            • E Ennis Ray Lynch Jr

                              While I did have formal training in the form of a CS degree I taught myself coding long before I was degreed. 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

                              C Offline
                              C Offline
                              Christian Graus
                              wrote on last edited by
                              #42

                              Me too. But I'm not offended, I'd expect more self taught people to write bad code than good. Although, sometimes I think more formally trained people write bad code than good.... Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                              E 1 Reply Last reply
                              0
                              • L leckey 0

                                I wasn't really sure if this belonged to a particular message board so please no flaming! I am wondering what others habits are when it comes to programming. I just inherited a huge VB.NET program. In one VB page it has over 10k lines of code. One function within that has about half those lines. Do you have a "limit" on how big/small a function/method/class should be before breaking it into smaller parts? We just used the analyzer on this thing and found one case statement has over 70 routes to go. So I'm hoping to clean this puppy up. BTW...heat index is currently at 109 degrees. Hope everyone else is staying cool.

                                A Offline
                                A Offline
                                Andy Brummer
                                wrote on last edited by
                                #43

                                leckey wrote:

                                We just used the analyzer on this thing and found one case statement has over 70 routes to go.

                                Ha, I once had to fix one that only had 30 branches, but each branch had it's own 10 branch case statement that were all cut and pasted from one original and had one or two cases modified in each of the 30 branches. As far as advice for fixing it goes. Clean it up in VB first before you try to convert it to any other language. Otherwise you are merging understanding the code and translating it into one step which will cause more problems.


                                I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

                                1 Reply Last reply
                                0
                                • L leckey 0

                                  I'm not sure. He was playing with the new analyzer we got and just told me about it. I'm just starting to go through the code to figure it out. It's an engineering program so it's a lot of "trying" to get the smallest weight depending on the factors (of which there seem to be a zillion).

                                  L Offline
                                  L Offline
                                  led mike
                                  wrote on last edited by
                                  #44

                                  leckey wrote:

                                  It's an engineering program

                                  ROTFLMAO :laugh::laugh::laugh::laugh::laugh::laugh: :laugh::laugh::laugh::laugh::laugh::laugh: Yes we are writing this engineering program in VB! What's next building a space craft out of bricks? Some days CP is one of the funniest .... ummm whatever.... tired from laughing now.

                                  L 1 Reply Last reply
                                  0
                                  • L led mike

                                    leckey wrote:

                                    It's an engineering program

                                    ROTFLMAO :laugh::laugh::laugh::laugh::laugh::laugh: :laugh::laugh::laugh::laugh::laugh::laugh: Yes we are writing this engineering program in VB! What's next building a space craft out of bricks? Some days CP is one of the funniest .... ummm whatever.... tired from laughing now.

                                    L Offline
                                    L Offline
                                    leckey 0
                                    wrote on last edited by
                                    #45

                                    I know...I know. It does interact with another 3rd party product that uses FORTRAN. Glad I could make you laugh though....as I cry while going through this code.

                                    P 1 Reply Last reply
                                    0
                                    • L leckey 0

                                      I know...I know. It does interact with another 3rd party product that uses FORTRAN. Glad I could make you laugh though....as I cry while going through this code.

                                      P Offline
                                      P Offline
                                      Paul Conrad
                                      wrote on last edited by
                                      #46

                                      leckey wrote:

                                      I know...I know. It does interact with another 3rd party product that uses FORTRAN.

                                      :omg:

                                      L S 2 Replies Last reply
                                      0
                                      • P Paul Conrad

                                        leckey wrote:

                                        I know...I know. It does interact with another 3rd party product that uses FORTRAN.

                                        :omg:

                                        L Offline
                                        L Offline
                                        led mike
                                        wrote on last edited by
                                        #47

                                        hehehehe if I don't stop laughing soon I will need to got to hospital

                                        P 1 Reply Last reply
                                        0
                                        • C Christian Graus

                                          Me too. But I'm not offended, I'd expect more self taught people to write bad code than good. Although, sometimes I think more formally trained people write bad code than good.... Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                                          E Offline
                                          E Offline
                                          Ennis Ray Lynch Jr
                                          wrote on last edited by
                                          #48

                                          There are more people that write bad code than good. Formal training, unf., doesn't even enter into the equation. 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

                                          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