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. Intervention: Coding Guidelines

Intervention: Coding Guidelines

Scheduled Pinned Locked Moved The Lounge
csharpquestionc++visual-studiocode-review
74 Posts 33 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.
  • realJSOPR realJSOP

    I have my own style and coding guidlines, but the determining factor of what I do at work is based on a) Does the company have coding/style guidelines? b) If a is false, I use the style/coding practices of the file I'm editing, and c) try to use the same coding/style as other files in the project in new files i create. Other than that, I try to only have one return point in a method, I declare and ini5t vars at the top of methods or scoped control blocks, try never to use "var" as a variable's type. keep methods within the scope that the method name infers, and I put class components in the order fields, properties, constructors, destructors, and then methods. Ialso put intellisense comments on every method and property. I'm also not shy at all about writinmg copious comments. There are other things, but you get the idea.

    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
    -----
    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
    -----
    When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

    H Offline
    H Offline
    honey the codewitch
    wrote on last edited by
    #43

    lol i use var as much as possible. in fact, i had to build the habit. if C# had proper typedefs (using doesn't count) then I probably wouldn't, but i use generics a lot

    When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

    1 Reply Last reply
    0
    • G Gary Wheeler

      The style guidelines for my group are a little over one page in length, and are mostly naming conventions. I can summarize them as follows:

      • Names should not rely on tribal knowledge for interpretation (use whole words).
      • Non-local names should use Pascal or camel case.
      • Local names should be in lower case.
      • If it's public, capitalize the name.
      • If it's private/protected, prefix the name with an underscore.
      • Acronyms embedded in a name should be prefixed and/or suffixed by an underscore to ensure the acronym is readable.
      • Hungarian notation is strongly discouraged.
      • Above all, BE CONSISTENT.

      We don't prescribe brace style or other formatting (e.g. tabs), source organization, language features, or most of the other things that people argue about.

      Software Zen: delete this;

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #44

      Nothing should ever be camelCase. X|

      G 1 Reply Last reply
      0
      • H honey the codewitch

        Halp! I've become a slave to naming and style guidelines. Years of C++ development and years of development prior to advanced compilers and syntax highlighting and intellisense and doc-comments and all of that made me a fascist about it. To the point where I judge people for not following, say, MS naming and style guidelines for .NET when building C# apps. To the point where I usually kick myself for not putting constants before vars in equality comparisons if(0==foo), etc. I already smoke pot (it's legal here) so how do I loosen up? Y'all don't need my judgment. Nor do any fellow devs. And I need to be able to use other people's code without feeling a little sick about it, or wanting to refactor it before I touch it. I'm half serious about this post.

        When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #45

        codewitch honey crisis wrote:

        if(0==foo)

        That's the most uselessest concept ever conceived.

        codewitch honey crisis wrote:

        MS naming and style guidelines

        I don't follow guidelines from companies I don't work for.

        H 1 Reply Last reply
        0
        • P PIEBALDconsult

          codewitch honey crisis wrote:

          if(0==foo)

          That's the most uselessest concept ever conceived.

          codewitch honey crisis wrote:

          MS naming and style guidelines

          I don't follow guidelines from companies I don't work for.

          H Offline
          H Offline
          honey the codewitch
          wrote on last edited by
          #46

          It was only useless with the advent of more sophisticated compilers. I started coding in 1986 - old habits. And for the record, I *did* work for microsoft. But more, when you're writing company code that's fine. When you're writing APIs to expose outside of your company you should probably adopt standards for your public interfaces that are widely understood. Anyone writing in .NET is going to be familiar with the style of the 6500+ base classes used in the .NET framework, so it's as good a standard as any for public facing APIs, and better than most

          When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

          1 Reply Last reply
          0
          • H honey the codewitch

            Halp! I've become a slave to naming and style guidelines. Years of C++ development and years of development prior to advanced compilers and syntax highlighting and intellisense and doc-comments and all of that made me a fascist about it. To the point where I judge people for not following, say, MS naming and style guidelines for .NET when building C# apps. To the point where I usually kick myself for not putting constants before vars in equality comparisons if(0==foo), etc. I already smoke pot (it's legal here) so how do I loosen up? Y'all don't need my judgment. Nor do any fellow devs. And I need to be able to use other people's code without feeling a little sick about it, or wanting to refactor it before I touch it. I'm half serious about this post.

            When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

            M Offline
            M Offline
            Munchies_Matt
            wrote on last edited by
            #47

            Try growing up.

            H 1 Reply Last reply
            0
            • H honey the codewitch

              Halp! I've become a slave to naming and style guidelines. Years of C++ development and years of development prior to advanced compilers and syntax highlighting and intellisense and doc-comments and all of that made me a fascist about it. To the point where I judge people for not following, say, MS naming and style guidelines for .NET when building C# apps. To the point where I usually kick myself for not putting constants before vars in equality comparisons if(0==foo), etc. I already smoke pot (it's legal here) so how do I loosen up? Y'all don't need my judgment. Nor do any fellow devs. And I need to be able to use other people's code without feeling a little sick about it, or wanting to refactor it before I touch it. I'm half serious about this post.

              When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

              U Offline
              U Offline
              User 11230442
              wrote on last edited by
              #48

              I am an old programmer. started in 1978. ASM all the way till 2010. yep old school. In 2016 I picked up a gig with a company I left in 1992. Tracking equipment. All C based. No problem. NXP processor. Not bad. MQX RTOS. Bloody night mare. (not an RTOS by the way) Had to drill down and re-write the drivers and part of the OS. The young buck in charge! did not like my style of programming. I did not like his. (macro use every where) Who cares if your style is not liked by someone else. does the end result work? Can someone else follow the code you have produced? If so then job done. Am fed up with programmers trying to copy someone else's style and spending months making it look pretty instead of making a product work using their own style. (if possible) STOP copying and pasting. Without understanding that which you are copying. Anyway. The message is. Develop your own style and progress with that. Ken.

              H 1 Reply Last reply
              0
              • M Munchies_Matt

                Try growing up.

                H Offline
                H Offline
                honey the codewitch
                wrote on last edited by
                #49

                That seems like a childish response, tbh

                When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                M 1 Reply Last reply
                0
                • H honey the codewitch

                  That seems like a childish response, tbh

                  When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                  M Offline
                  M Offline
                  Munchies_Matt
                  wrote on last edited by
                  #50

                  :) Seriously though, when you get older you live and let live. Truths become less absolute.

                  H 1 Reply Last reply
                  0
                  • U User 11230442

                    I am an old programmer. started in 1978. ASM all the way till 2010. yep old school. In 2016 I picked up a gig with a company I left in 1992. Tracking equipment. All C based. No problem. NXP processor. Not bad. MQX RTOS. Bloody night mare. (not an RTOS by the way) Had to drill down and re-write the drivers and part of the OS. The young buck in charge! did not like my style of programming. I did not like his. (macro use every where) Who cares if your style is not liked by someone else. does the end result work? Can someone else follow the code you have produced? If so then job done. Am fed up with programmers trying to copy someone else's style and spending months making it look pretty instead of making a product work using their own style. (if possible) STOP copying and pasting. Without understanding that which you are copying. Anyway. The message is. Develop your own style and progress with that. Ken.

                    H Offline
                    H Offline
                    honey the codewitch
                    wrote on last edited by
                    #51

                    That seems sensible, with a heavy caveat. Public APIs with a general/public development audience (meaning beyond your company/team) Like if you're making libraries or components. At that point, I think it's important to adopt as widely available/common denominator standard as possible for the public facing APIs at least. This makes everyone's lives easier, except maybe yours (or mine) due to the research and learning curve, but in the end it saves user headache and in some cases can cut some of the tech documentation down a bit because you don't have to re-explain basic concepts, like say, a dictionary object. If you're using those to enumerate keyed items you don't need to document an "IndexedCollection" class or whatever. So in general i agree, but again public facing APIs are my sticking point. I'll die on that hill.

                    When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                    U 1 Reply Last reply
                    0
                    • M Munchies_Matt

                      :) Seriously though, when you get older you live and let live. Truths become less absolute.

                      H Offline
                      H Offline
                      honey the codewitch
                      wrote on last edited by
                      #52

                      I agree with that. In most aspects of my life I am very buddhist. In most of my coding I am. Public facing APIs are a hill I'll die on though. And by public facing, I meant interfaces that are intended to be consumed by a wider audience than one's company/team Standards here are sooo important, for reasons I could practically write a book on.

                      When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                      M 1 Reply Last reply
                      0
                      • H honey the codewitch

                        I agree with that. In most aspects of my life I am very buddhist. In most of my coding I am. Public facing APIs are a hill I'll die on though. And by public facing, I meant interfaces that are intended to be consumed by a wider audience than one's company/team Standards here are sooo important, for reasons I could practically write a book on.

                        When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                        M Offline
                        M Offline
                        Munchies_Matt
                        wrote on last edited by
                        #53

                        Well, do you think any API became unusable because of the style of its interface?

                        H 1 Reply Last reply
                        0
                        • H honey the codewitch

                          That seems sensible, with a heavy caveat. Public APIs with a general/public development audience (meaning beyond your company/team) Like if you're making libraries or components. At that point, I think it's important to adopt as widely available/common denominator standard as possible for the public facing APIs at least. This makes everyone's lives easier, except maybe yours (or mine) due to the research and learning curve, but in the end it saves user headache and in some cases can cut some of the tech documentation down a bit because you don't have to re-explain basic concepts, like say, a dictionary object. If you're using those to enumerate keyed items you don't need to document an "IndexedCollection" class or whatever. So in general i agree, but again public facing APIs are my sticking point. I'll die on that hill.

                          When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                          U Offline
                          U Offline
                          User 11230442
                          wrote on last edited by
                          #54

                          The point I was trying to make is. Do not loose heart if someone does not like your style. Everyone has their own style. So long as others can follow your code, does it matter. As a programmer (if you view it as I) you will try to make it as efficient as possible. (think and re-write, think and re-write) Keep a problem area in the back of your mind, it may be working, but you know there is a possible problem there. Do not! copy someone else's style. (this is for the new comers) Make mistakes. Admit it and fix them. A programming style cannot be learnt from a book. I love using multi dimensional arrays. They are efficient, but the code is really hard to follow. Therefore, I have to write a document explaining exactly how the code works. Rambling, I know. Ken.

                          H 1 Reply Last reply
                          0
                          • M Munchies_Matt

                            Well, do you think any API became unusable because of the style of its interface?

                            H Offline
                            H Offline
                            honey the codewitch
                            wrote on last edited by
                            #55

                            I think what happens is people get less inclined to use it as the learning curve grows. Especially with the rate people are expected to learn technologies. The more one-off your style is, the more difficult to adapt to it. Furthermore, when integrating many components it makes the glue code clunky if the APIs don't even remotely match up to each other in terms of how they're named and how you navigate them. Pretty soon everything is spaghetti. Glue has always been glue code, and somewhat messy, but how messy largely depends on how standardized everything is in terms of how it's programmed against. It's hard to put a point on specifically, if only because so many APIs with a one-off style suffer from other problems (libutp is a good example) but problematic APIs lead to less adopters. So if you want wider adoption and higher quality code it's a good idea to keep your public APIs playing nice and consistently with as much else as you can. This means in .NET for example, at least familiarizing oneself with microsoft style and standard guidelines. Why? because the 6500+ base classes in .NET are coded out that way, and people already know how to use them. So make your API similar and the learning curve is less steep - seems obvious to me but then i've been coding for a long time too - not quite 40 years like i guess some people here

                            When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                            1 Reply Last reply
                            0
                            • H honey the codewitch

                              Halp! I've become a slave to naming and style guidelines. Years of C++ development and years of development prior to advanced compilers and syntax highlighting and intellisense and doc-comments and all of that made me a fascist about it. To the point where I judge people for not following, say, MS naming and style guidelines for .NET when building C# apps. To the point where I usually kick myself for not putting constants before vars in equality comparisons if(0==foo), etc. I already smoke pot (it's legal here) so how do I loosen up? Y'all don't need my judgment. Nor do any fellow devs. And I need to be able to use other people's code without feeling a little sick about it, or wanting to refactor it before I touch it. I'm half serious about this post.

                              When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                              M Offline
                              M Offline
                              Member 9167057
                              wrote on last edited by
                              #56

                              I used to have OCD some years ago and I overcame it by noticing that I have it, noticing what particular actions I'm doing due to OCD and realizing that those actions are nonsense that cost time, don't even bring enjoyment and that's about it. The rest was a tad of willpower and utilitarism.

                              H 1 Reply Last reply
                              0
                              • U User 11230442

                                The point I was trying to make is. Do not loose heart if someone does not like your style. Everyone has their own style. So long as others can follow your code, does it matter. As a programmer (if you view it as I) you will try to make it as efficient as possible. (think and re-write, think and re-write) Keep a problem area in the back of your mind, it may be working, but you know there is a possible problem there. Do not! copy someone else's style. (this is for the new comers) Make mistakes. Admit it and fix them. A programming style cannot be learnt from a book. I love using multi dimensional arrays. They are efficient, but the code is really hard to follow. Therefore, I have to write a document explaining exactly how the code works. Rambling, I know. Ken.

                                H Offline
                                H Offline
                                honey the codewitch
                                wrote on last edited by
                                #57

                                > I love using multi dimensional arrays. They are efficient, but the code is really hard to follow. In .NET they're inefficient. Nested arrays are more efficient. Weird, I know. But in .NET I end up creating really ugly structures for a similar reason as you using MD arrays (like in C or C++) Here's a recent datatype I had to munge through. Yes, I use comments for this Tuple<TAccept, Tuple<KeyValuePair<char, char>[], int>[]>[] Fortunately, it's opaque to the end consumer. It's basically a "handle"

                                When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                                U 1 Reply Last reply
                                0
                                • M Member 9167057

                                  I used to have OCD some years ago and I overcame it by noticing that I have it, noticing what particular actions I'm doing due to OCD and realizing that those actions are nonsense that cost time, don't even bring enjoyment and that's about it. The rest was a tad of willpower and utilitarism.

                                  H Offline
                                  H Offline
                                  honey the codewitch
                                  wrote on last edited by
                                  #58

                                  Intellectually I understand that. In most areas of my life I can even apply it. Here I'm battling 30 years of NOT doing that (being mindful and letting go) where it comes to coding. Maybe I'm lacking in the willpower department. I usually find ways to hack around my lack of willpower. :laugh:

                                  When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                                  M 1 Reply Last reply
                                  0
                                  • H honey the codewitch

                                    Intellectually I understand that. In most areas of my life I can even apply it. Here I'm battling 30 years of NOT doing that (being mindful and letting go) where it comes to coding. Maybe I'm lacking in the willpower department. I usually find ways to hack around my lack of willpower. :laugh:

                                    When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                                    M Offline
                                    M Offline
                                    Member 9167057
                                    wrote on last edited by
                                    #59

                                    How much of a hardliner utilitarist are you? I very much am and that helps a huge lot in overcoming nonsensical habits. I wouldn't even say that I'm big in the willpower department, but my utilitarism is a suitable substitute.

                                    H 1 Reply Last reply
                                    0
                                    • H honey the codewitch

                                      > I love using multi dimensional arrays. They are efficient, but the code is really hard to follow. In .NET they're inefficient. Nested arrays are more efficient. Weird, I know. But in .NET I end up creating really ugly structures for a similar reason as you using MD arrays (like in C or C++) Here's a recent datatype I had to munge through. Yes, I use comments for this Tuple<TAccept, Tuple<KeyValuePair<char, char>[], int>[]>[] Fortunately, it's opaque to the end consumer. It's basically a "handle"

                                      When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

                                      U Offline
                                      U Offline
                                      User 11230442
                                      wrote on last edited by
                                      #60

                                      I do would not like to come across that in a piece of code.

                                      H 1 Reply Last reply
                                      0
                                      • OriginalGriffO OriginalGriff

                                        Except for 1TB - that's ALWAYS wrong. :laugh:

                                        Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                                        P Offline
                                        P Offline
                                        Paulo_JCG
                                        wrote on last edited by
                                        #61

                                        Is that 1TB or 1TiB?

                                        Paulo Gomes Measuring programming progress by lines of code is like measuring aircraft building progress by weight. —Bill Gates Everything should be made as simple as possible, but not simpler. —Albert Einstein

                                        1 Reply Last reply
                                        0
                                        • P PIEBALDconsult

                                          Nothing should ever be camelCase. X|

                                          G Offline
                                          G Offline
                                          Gary Wheeler
                                          wrote on last edited by
                                          #62

                                          Agreed. I don't like or use it myself, but we had a couple folks who liked it.

                                          Software Zen: delete this;

                                          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