Do you have any good advice/links to a set of coding standards or best practices to follow?

前端 未结 20 2236
再見小時候
再見小時候 2021-02-01 10:40

For those of us that have programmed enough I’m sure we have come across many different flavours of coding standards that you can use when it comes to programming.

e.g.

相关标签:
20条回答
  • 2021-02-01 11:06

    What's in the standard doesn't really matter all that much. What matters is that you have one, and that your developers follow it.

    0 讨论(0)
  • 2021-02-01 11:07

    Mono Coding Guidelines

    0 讨论(0)
  • 2021-02-01 11:09
    • Sun Java Code Conventions
    • Python Style Guide
    • Zend Coding Standard for PHP
    0 讨论(0)
  • 2021-02-01 11:09

    It doesn't quite answer the question, but it's worth a mention...

    I read Steve McConnell's Code Complete. Whilst it doesn't give you a pre-baked set of coding standards it does set out a lot of good arguments for the various approaches. It'll make you think about things you'd not thought of before.

    It changed my little world for the better.

    0 讨论(0)
  • 2021-02-01 11:09

    Coding standards themselves are great and all, but what I think is much, much, MUCH more important is keeping with the style of whatever code you're maintaining. I've seen people add a function to some class written one way and forcing their coding standard on just that function. It's inconsistent, it sticks out, and, in my opinion, it makes it harder to enjoy the class "as a whole".

    Whenever you're maintaining code, look at the code around it. See what the style is. K&R braces? Capital Camel Case methods? Hungarian? Double-line comment blocks between every function? Whatever it is, you should do it too in that specific area.

    Before I leave, one thing I'd like to note that's related - naming files. I'm mainly a C++ guy, so this may not apply to whatever else, but basically it goes _.h or .cpp. So, Foo::Bar would be in Foo_Bar.h. Common things (i.e. a precompiled header) for the Foo namespace would be in Foo_common.h (note the lowercase common). Of course, that's a taste thing, but everybody who has worked with this has come out in favor of this.

    0 讨论(0)
  • 2021-02-01 11:10

    My best advice regarding coding standards: don't let them get in the way when trying to get work done.

    A big bureaucracy might actually hinder progress in projects instead of helping to achieve better team work. When people complain about not following coding standards instead of the actual quality of the code, then it is too much regulation.

    Other than that, pick one from the many suggestions and try to stick with it for as long as possible to build a code base following a single standard that you are used to.

    0 讨论(0)
提交回复
热议问题