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

                    E Offline
                    E Offline
                    englebart
                    wrote on last edited by
                    #63

                    If you are reviewing code, use your smart editor to format it the way you want so you can understand it. If you need to make a change after review, revert the file, make your change, test, move on. And follow this rule: Rule #1 for source control sanity retention: Never combine a reformat with an actual code change in the same commit! Use a separate commit with a "//reformat" comment as the first line for formatting, then remove the comment and do the real change.

                    1 Reply Last reply
                    0
                    • L Lost User

                      your style sucks, so does mine, oh and that bloke over there: his style sucks too. each to their own. If style is an issue you've got a lot more growing up to do.

                      Message Signature (Click to edit ->)

                      D Offline
                      D Offline
                      Dan Neely
                      wrote on last edited by
                      #64

                      All coding styles suck. But it's important that everyone in a project is using the same general style to keep the code readable. When available I prefer platform standards/IDE autoformat defaults. (And yes that means I use different brace placement styles in C# and Java.)

                      Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                      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
                        MikeTheFid
                        wrote on last edited by
                        #65

                        The only strong conviction I have related to coding styles is when changing someone else's code. It is expressed by:

                        Quote:

                        When in Rome, do as the Romans do.

                        It annoys the elephant out of me when a source file has 4 different styles because people can't be bothered to conform to what's there or are so stubborn they want to impose their style on everyone else, or they simply don't give an elephant about anyone else. /endRant I need to stop reading these threads before coffee.

                        Cheers, Mike Fidler "I intend to live forever - so far, so good." Steven Wright "I almost had a psychic girlfriend but she left me before we met." Also Steven Wright "I'm addicted to placebos. I could quit, but it wouldn't matter." Steven Wright yet again.

                        1 Reply Last reply
                        0
                        • M Member 9167057

                          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 Offline
                          H Offline
                          honey the codewitch
                          wrote on last edited by
                          #66

                          well i am an instrumentalist "what's real is what's useful" and by real, i mean what exists in any meaningful sense i am pretty much a hardliner about it maybe, if you'd consider that hardline.

                          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
                          • U User 11230442

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

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

                            me either. but it was either that or require a dependency in the generated output that i didn't need (it's part of a code generator)

                            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.

                              P Offline
                              P Offline
                              patbob
                              wrote on last edited by
                              #68

                              codewitch honey crisis wrote:

                              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

                              There's an easy cure for this.. work on a project with a lot of devs that has a too-tight schedule and do as you want (i.e. shamelessly refactor all their code to your liking) until you wake up one day and realize that you're the one that needs to be duct taped to their chair so the product can ship on schedule. Ok, I'm half serious about that answer. The real answer is that you need to realize you can't do everybody else's job for them, and accept that, while they won't do things the way you would, the things will get done well enough to not matter.

                              I live in Oregon, and I'm an engineer.

                              H 1 Reply Last reply
                              0
                              • P patbob

                                codewitch honey crisis wrote:

                                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

                                There's an easy cure for this.. work on a project with a lot of devs that has a too-tight schedule and do as you want (i.e. shamelessly refactor all their code to your liking) until you wake up one day and realize that you're the one that needs to be duct taped to their chair so the product can ship on schedule. Ok, I'm half serious about that answer. The real answer is that you need to realize you can't do everybody else's job for them, and accept that, while they won't do things the way you would, the things will get done well enough to not matter.

                                I live in Oregon, and I'm an engineer.

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

                                I have. I used to PM even. Code review is good, but if deadlines get squeezed a lot of stuff goes by the wayside, including reviews, and quality control in general

                                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.

                                  S Offline
                                  S Offline
                                  SeattleC
                                  wrote on last edited by
                                  #70

                                  Some companies put code through a pretty-printer as part of the check-in process. You could try that. But you have to be the first developer... Boy...constants on the left...I haven't seen that in awhile. I've been accused of having an "idiosyncratic" coding style because I like to add spaces to visually line up parts of my C++ class definitions. I don't worry about it. It's my practice, and I do what I want. If someone wants to change it, they can. If the coding standard actually says not to do it, then I don't. Speaking of which, I once had a colleague edit my C++ code to change all the C++-style // comments into C-style /\*...\*/ comments. If you're reading this, "Whatever, dude."

                                  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.

                                    H Offline
                                    H Offline
                                    hpcoder2
                                    wrote on last edited by
                                    #71

                                    My own experience was 1 year of working with very strict coding style guidelines, out of many years where things are much more laissez faire. Literally hundreds of formal rules, plus as many unstated informal one that everyone was supposed to know. Code reviews ended up being a bitch fest where 90% of the argy bargy was about code style. It literally slowed productivity and momentum to a crawl. On all my other team projects, productivity was much higher, and not necessarily any worse technical debt-wise. Code reviews were simpler and much more productive/pleasant. There are some things one simply should not do (eg exception unsafe code, unnecessary pass-by-value) - everything else, just let it go man. I got quite tolerant of Hungarian notation, for example, just ignoring it as white noise (as it effectively is). You can tell instantly who wrote a piece of code from its style, so any questions, you know who to ask, if they're still around.

                                    H 1 Reply Last reply
                                    0
                                    • H hpcoder2

                                      My own experience was 1 year of working with very strict coding style guidelines, out of many years where things are much more laissez faire. Literally hundreds of formal rules, plus as many unstated informal one that everyone was supposed to know. Code reviews ended up being a bitch fest where 90% of the argy bargy was about code style. It literally slowed productivity and momentum to a crawl. On all my other team projects, productivity was much higher, and not necessarily any worse technical debt-wise. Code reviews were simpler and much more productive/pleasant. There are some things one simply should not do (eg exception unsafe code, unnecessary pass-by-value) - everything else, just let it go man. I got quite tolerant of Hungarian notation, for example, just ignoring it as white noise (as it effectively is). You can tell instantly who wrote a piece of code from its style, so any questions, you know who to ask, if they're still around.

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

                                      > You can tell instantly who wrote a piece of code from its style, so any questions, you know who to ask, if they're still around. You make an excellent point. It's as good as a ID card sometimes. For awhile I worked reversing worm code for a security outfit that was doing IT forensics, to find common authors of the code. Even reversed from machine code, devs leave their mark. I dropped hungarian notion Right now in C++ I use a hybrid of different styles depending on what framework(s) I'm working with. I don't like to do it, but the alternative is worse.

                                      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

                                        Plus, any self-respecting compiler released in the last 20 years issues a warning for "assignment in conditional expression".

                                        Software Zen: delete this;

                                        J Offline
                                        J Offline
                                        Jeroen_R
                                        wrote on last edited by
                                        #73

                                        :thumbsup: This. This is my main problem with style guides: sometimes technology catches up and the rule isn't needed anymore.

                                        1 Reply Last reply
                                        0
                                        • R Ravi Bhavnani

                                          Don't want to sound philosophical, but a couple of years ago I experienced a back injury that made it impossible to sit or walk normally for 3 months, which meant I couldn't do what I love doing most - i.e. writing code and building software.  During that time I was forced to work from home (standing up, with much difficulty) and participate in meetings remotely.  It was during those meetings, many of which included animated discussions (and strong feelings) about coding standards, unit testing and other software development related processes, that I realized what was really important.  Yes, of course, I'm talking about one's health.  It seems as if I had to experience that injury in order to get my priorities right. I'm still (very) passionate about my craft, but I seemed to have grown a large pair of ears.  Today, I tend to be much more sensitive to other people's opinions than ever before.  My only regret is, I wish I'd come to this realization earlier.  I would've learned so much more from my (much smarter) colleagues. :) /ravi

                                          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                                          T Offline
                                          T Offline
                                          Tui Alexandre
                                          wrote on last edited by
                                          #74

                                          Thanks for sharing :thumbsup:

                                          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