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.
  • 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
            • L leckey 0

              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 Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #21

              leckey wrote:

              Unfortunately, it's my BOSS.

              Then tread with care, but still indicate that a lot of refactoring is required in the interest of maintainability.

              leckey wrote:

              I am hoping to persuade said boss to let me rewrite this evil thing in C#.

              I've done conversions of large projects to C# using automated tools, and it went pretty well. I wouldn't advocate a move of language on the basis that this would solve any problems, but if you're more comfortable with C# ( as I am ), then it's a good move to start with. It also has the benefit that perhaps the boss doesn't know C#, so he won't be able to tinker with it again.... Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

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

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

                If your app was written properly, then all you should need to do is write presentation code. I seem to recall answering a question from you tho that showed a ton of business logic in the presentation code, so I am presuming it's probable you don't have a dll of business logic that is called from your presentation executable ? If that's the case, I would certainly aim to change this for the ASP.NET version, write dlls that represent a business logic layer and a data layer, and call those from your ASP.NET pages. Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                1 Reply Last reply
                0
                • L leckey 0

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

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

                  leckey wrote:

                  Unfortunately, it's my BOSS.

                  :~

                  leckey wrote:

                  I will look at the book.

                  Do so, it is a very good book :)

                  leckey wrote:

                  I am hoping to persuade said boss to let me rewrite this evil thing in C#.

                  Try and persuade your boss from a business approach. Sell him on refactoring to "fine-tune" the code. Not sure what the application does, but fixing it up in C# may have benefits that helps everyone win.

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

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

                    Ennis Ray Lynch, Jr. wrote:

                    BTW, when I convert code bases I retype it.

                    OK - the code bases I have changed, it's been because I took a job and found the code was VB, and indicated I only did C#. There was really no option for me to hand type them. One I've been on for two years now, and I admit I still from time to time find code that I change to better reflect what C# can do. But after a day, I had a C# code base that worked fine.

                    Ennis Ray Lynch, Jr. wrote:

                    Fortunately with .NET you can mix languages

                    I thought you could only do that in ASP.NET, unless you mean mix languages between different dlls in the project, not within one project ? Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                    P 1 Reply Last reply
                    0
                    • L leckey 0

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

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

                      leckey wrote:

                      Unfortunately, it's my BOSS.

                      ROTFLMAO :laugh::laugh::laugh::laugh::laugh:

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

                        109 - that's about 45 celcius, I think. I'm just home from the US, and Texas/LA were both pretty warm, getting back to winter is hitting me hard. Canada is amazing, it's the height of summer and it pours with rain. I'm told that it stops in September... Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                        L 1 Reply Last reply
                        0
                        • C Christian Graus

                          109 - that's about 45 celcius, I think. I'm just home from the US, and Texas/LA were both pretty warm, getting back to winter is hitting me hard. Canada is amazing, it's the height of summer and it pours with rain. I'm told that it stops in September... Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

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

                          I know the Australian summers on the mainland have been awful the last couple of years. My friends used live by the Grampians and I remember them catching on fire. They said last summer was terribly hot.

                          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
                            led mike
                            wrote on last edited by
                            #28

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

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