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 Offline
    L Offline
    leckey 0
    wrote on last edited by
    #1

    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.

    E R C S J 24 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.

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

      Our heat index is the same here! If a function can be broken up, break it up. With care. If some functionality can be reused then it will likely be reused and breaking it into more distinct methods and classes really help. Remove use of globals? Were possible. While members are extrememly useful and necessary I often see them used as globals to avoid parameter passing when in fact parameter passing is the best way to go. If you are passing more than 5 parameters you probably have too many parameters If you look at your finished product and it does not appear neat and elegant it probably isn't Switch to c# Use your best judgement with any thing you do. And remember the first several times you do something it is wrong. Fearless refactor is something to live by. Oh, yeah, almost forgot, add unit tests. See: NUNIT and use xml comments and extensive source comments. (Ok more advice) In business applications readability and maintainability and self-documentation is more important that the absolute fastest code [in most cases]. 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

      L C 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.

        R Offline
        R Offline
        Robert Rohde
        wrote on last edited by
        #3

        leckey wrote:

        one VB page it has over 10k lines of code

        :omg:

        leckey wrote:

        one case statement has over 70 routes to go

        :wtf: This is a definitive candidate for a refactoring tool. I would say even one class with over 1000 lines is too big. That's normally the point when I begin to rethink what I'm doing...

        J 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
          #4

          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 P L S 4 Replies Last reply
          0
          • E Ennis Ray Lynch Jr

            Our heat index is the same here! If a function can be broken up, break it up. With care. If some functionality can be reused then it will likely be reused and breaking it into more distinct methods and classes really help. Remove use of globals? Were possible. While members are extrememly useful and necessary I often see them used as globals to avoid parameter passing when in fact parameter passing is the best way to go. If you are passing more than 5 parameters you probably have too many parameters If you look at your finished product and it does not appear neat and elegant it probably isn't Switch to c# Use your best judgement with any thing you do. And remember the first several times you do something it is wrong. Fearless refactor is something to live by. Oh, yeah, almost forgot, add unit tests. See: NUNIT and use xml comments and extensive source comments. (Ok more advice) In business applications readability and maintainability and self-documentation is more important that the absolute fastest code [in most cases]. 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

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

            Ennis Ray Lynch, Jr. wrote:

            Switch to c#

            Amen brother! I hate VB.

            Ennis Ray Lynch, Jr. wrote:

            In business applications readability and maintainability and self-documentation is more important that the absolute fastest code [in most cases].

            Like I said, it's ugly code. Not much commenting. Old code just commented out. And it is definately not that fast. If it were me I'd rewrite the entire thing.

            M K H M 4 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.

              S Offline
              S Offline
              Shog9 0
              wrote on last edited by
              #6

              leckey wrote:

              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.

              Wow, yeah, that needs work. VB.NET standards state that at least 90% of each module must consist of a single method - the original author must not have been a Native VB coder.

              ---- Scripts i’ve known... CPhog 1.0.0.0 - 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

              L 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.

                J Offline
                J Offline
                Josh Smith
                wrote on last edited by
                #7

                leckey wrote:

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

                :wtf: X| :omg:

                leckey wrote:

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

                My rule for methods: the entire method body should fit on my screen at once. My rule for classes: most classes should have a small surface area (public/protected/internal members) where all access points are functionally related. My rule for being handed gigantic crappy VB apps: shoot, stab, burn, and crush until the app gets poured into someone else's soul. :-D :josh: My WPF Blog[^]

                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.

                  J Offline
                  J Offline
                  Joe Woodbury
                  wrote on last edited by
                  #8

                  leckey wrote:

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

                  Absolutely not. Breaking code into smaller parts should be entirely dictated by logical divisions. Having said that, a 5,000 line function is insane. Still, when I encounter stuff like this, I usually just hold my nose and procede VERY carefully. It isn't unusual to find a variable being set at line 200 that is used again, and even modified, at line 2000 and then again at line 4500 (worse, the variable is probably named something stupid.) Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

                  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
                    leckey 0
                    wrote on last edited by
                    #9

                    Christian Graus wrote:

                    If you inherited it from someone within the company, go and smack them on the head.

                    Unfortunately, it's my BOSS. I will look at the book. I am hoping to persuade said boss to let me rewrite this evil thing in C#.

                    C P L E 4 Replies Last reply
                    0
                    • R Robert Rohde

                      leckey wrote:

                      one VB page it has over 10k lines of code

                      :omg:

                      leckey wrote:

                      one case statement has over 70 routes to go

                      :wtf: This is a definitive candidate for a refactoring tool. I would say even one class with over 1000 lines is too big. That's normally the point when I begin to rethink what I'm doing...

                      J Offline
                      J Offline
                      Josh Smith
                      wrote on last edited by
                      #10

                      Robert Rohde wrote:

                      That's normally the point when I begin to rethink what I'm doing...

                      That's the point where the developer needs to begin to think, nevermind rethink! :) :josh: My WPF Blog[^]

                      1 Reply Last reply
                      0
                      • E Ennis Ray Lynch Jr

                        Our heat index is the same here! If a function can be broken up, break it up. With care. If some functionality can be reused then it will likely be reused and breaking it into more distinct methods and classes really help. Remove use of globals? Were possible. While members are extrememly useful and necessary I often see them used as globals to avoid parameter passing when in fact parameter passing is the best way to go. If you are passing more than 5 parameters you probably have too many parameters If you look at your finished product and it does not appear neat and elegant it probably isn't Switch to c# Use your best judgement with any thing you do. And remember the first several times you do something it is wrong. Fearless refactor is something to live by. Oh, yeah, almost forgot, add unit tests. See: NUNIT and use xml comments and extensive source comments. (Ok more advice) In business applications readability and maintainability and self-documentation is more important that the absolute fastest code [in most cases]. 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
                        #11

                        Ennis Ray Lynch, Jr. wrote:

                        Switch to c#

                        *grin* That may be an effective filter to increase the odds of people who write 5000 line functions never working on the code again, but beyond that I don't see how moving to C# is a good thing. I've done large VB -> C# moves, and there's always a lot of stuff the converters can't fix, or places where the code they write really sucks. One can remove the VisualBasic namespace without moving to C#, if you want to get rid of legacy garbage.

                        Ennis Ray Lynch, Jr. wrote:

                        add unit tests.

                        Adding unit tests to an existing project of any size is a pretty decent sort of task. Unit tests are best written during development, not after. Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                        E P 2 Replies Last reply
                        0
                        • S Shog9 0

                          leckey wrote:

                          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.

                          Wow, yeah, that needs work. VB.NET standards state that at least 90% of each module must consist of a single method - the original author must not have been a Native VB coder.

                          ---- Scripts i’ve known... CPhog 1.0.0.0 - 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

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

                          The problem is he doesn't have formal training. He just learned as he went along. Hence the bad code ontop of bad code. I'll look at something and ask him why he did that and he'll say it was the only way he knew how to make it work at the time.

                          E 1 Reply Last reply
                          0
                          • C Christian Graus

                            Ennis Ray Lynch, Jr. wrote:

                            Switch to c#

                            *grin* That may be an effective filter to increase the odds of people who write 5000 line functions never working on the code again, but beyond that I don't see how moving to C# is a good thing. I've done large VB -> C# moves, and there's always a lot of stuff the converters can't fix, or places where the code they write really sucks. One can remove the VisualBasic namespace without moving to C#, if you want to get rid of legacy garbage.

                            Ennis Ray Lynch, Jr. wrote:

                            add unit tests.

                            Adding unit tests to an existing project of any size is a pretty decent sort of task. Unit tests are best written during development, not after. 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
                            #13

                            How to fix the code base. BTW, when I convert code bases I retype it. I don't trust automated tools. Besides doing it yourself will give an intimate understanding with the code. Fortunately with .NET you can mix languages and having c# classes definately help you to differentiate new code from old (which is being replaced.) 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

                            L C 2 Replies Last reply
                            0
                            • L leckey 0

                              The problem is he doesn't have formal training. He just learned as he went along. Hence the bad code ontop of bad code. I'll look at something and ask him why he did that and he'll say it was the only way he knew how to make it work at the time.

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

                              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

                              L C 2 Replies Last reply
                              0
                              • E Ennis Ray Lynch Jr

                                How to fix the code base. BTW, when I convert code bases I retype it. I don't trust automated tools. Besides doing it yourself will give an intimate understanding with the code. Fortunately with .NET you can mix languages and having c# classes definately help you to differentiate new code from old (which is being replaced.) 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

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

                                Right now it's a windows application. I'd like to make ASP.NET which again makes me want to start from scratch.

                                E C 2 Replies 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

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

                                  I certainly didn't mean to insult you or anyone else who learned this way. :sigh: His methods at the time just weren't the best. He also doesn't care about the SDLC like requirements gathering. Just do it/fix it, even if it's ugly.

                                  E 1 Reply Last reply
                                  0
                                  • L leckey 0

                                    Right now it's a windows application. I'd like to make ASP.NET which again makes me want to start from scratch.

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

                                    Between a Windows Application and an ASP.NET application other than the GUI code. Keep that in mind when you rewrite. The code and the classes should all be seperate from the GUI code and classes. 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
                                    • 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

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

                                      Christian Graus wrote:

                                      No code file should be 10k lines.

                                      I agree. A code file in my opinion should be 500-1000 maximum.

                                      Christian Graus wrote:

                                      I would say 30 lines is a max for a function.

                                      Same here. If you open it in the good old MS-DOS Edit and it exceeds the number of lines visible on the screen at one time, then it's too big for a function and should be refactored.

                                      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
                                        Chris S Kaiser
                                        wrote on last edited by
                                        #19

                                        I try and keep my functions to a 10 line max. Unless there's a bit of exception handling and/or database manip, as populating a row with ten fields already busts this, but generally, I try to think atomically. But we have files up to around 3k. A few of em'. I tend to think differently in this regard. If the file is a database helper class with a manager and the like, I like to keep em' all together so I'm not ctrl-tabbing like crazy. But eh.. it depends on your environment. As far as how big it should be before breaking it up.. first if anything repeats, that's a signal to move it out into a function, second, if you could name a section in that it can be defined using English or your language of choice, I'd move it out. Again, I just try to think atomically. [edit] And I'd at the least make each case statement a call to a function that handled that case. [/edit] 70 routes... that's alot. If its going to continue to grow, you might be better off dumping a bunch of delegates into hashtable and looking up the case. Keeps the code simpler if your not that worried about max performance. Sounds fun! Except for the VB part. ;) This statement is false. -- modified at 16:47 Wednesday 19th July, 2006

                                        1 Reply Last reply
                                        0
                                        • L leckey 0

                                          I certainly didn't mean to insult you or anyone else who learned this way. :sigh: His methods at the time just weren't the best. He also doesn't care about the SDLC like requirements gathering. Just do it/fix it, even if it's ugly.

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

                                          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 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