Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Coding Standards

  • 30-07-2009 9:56am
    #1
    Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭


    Just looking for opinions on coding standards and wondering if anyone has any recommended reading on the subject?

    I've done some work in the area over the years and unfortunately it is by and large the most overlooked area of programming by most developers I've encountered.

    I personally feel it is probably the most important part of any development project, decent coding standards, I'm not just talking about the obvious naming of variables, methods etc. here but consistent approaches to problem solving and consistent usage of the same techniques across members of a development team.

    Do you have problems with coding standards within your own teams?

    I wonder if there could be some way for IDEs to validate against some sort of predefined standards and generate compile time warnings against them? Does this functionality exist in other systems (I'm familiar with .NET and Xcode primarily) that I am unaware of?


Comments

  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    This is just something you need to agree between each other and have code reviews about.

    We don't have coding standards where I work and it shows. I could post many things on thedailywtf.com


  • Registered Users, Registered Users 2 Posts: 2,800 ✭✭✭voxpop


    Def go for some sort of standards. Once the standards are in place it make everything easier in the long run.


    Design patterns (gang of four) - is the something every developer should be at least familiar with. You can research most of the patterns on the net without buying the book.


    Also I would recommend using something like Maven for you builds - it promotes standardisation in project layout and dependencies.


    EDIT - this is coming from a mainly Java developer


  • Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


    voxpop wrote: »
    Def go for some sort of standards. Once the standards are in place it make everything easier in the long run.


    Design patterns (gang of four) - is the something every developer should be at least familiar with. You can research most of the patterns on the net without buying the book.


    Also I would recommend using something like Maven for you builds - it promotes standardisation in project layout and dependencies.

    I found the Gang of Four book one of the hardest reads ever so basically used it as a reference in the end.

    Will take a look at Maven, thanks.

    I don't agree with the "let's just agree between us" attitude as when new developers join a company or old ones leave, the agreement becomes diluted. Also, I feel any graduate developers joining a company are entitled to the benefit of a coding standards document to follow and learn from.


  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    Draupnir wrote: »
    I don't agree with the "let's just agree between us" attitude as when new developers join a company or old ones leave, the agreement becomes diluted. Also, I feel any graduate developers joining a company are entitled to the benefit of a coding standards document to follow and learn from.

    Now now, I didn't mean just have a nudge and a wink and we'll all code the same. I meant senior developers should establish the coding standards and document them and others should stick to them.

    Books like the gang of four design patterns book and code complete should be used as reference, not a template for how one should do everything.


  • Registered Users, Registered Users 2 Posts: 2,800 ✭✭✭voxpop


    Draupnir wrote: »
    I don't agree with the "let's just agree between us" attitude as when new developers join a company or old ones leave, the agreement becomes diluted. Also, I feel any graduate developers joining a company are entitled to the benefit of a coding standards document to follow and learn from.

    I do think there should be an "official" set of standards for the company, but those standards must also adapt and change (in an organised way). There is nothing worse than sticking rigidly to a particular methodology solely because its in a document


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 3,548 ✭✭✭Draupnir


    fasty wrote: »
    Now now, I didn't mean just have a nudge and a wink and we'll all code the same. I meant senior developers should establish the coding standards and document them and others should stick to them.

    Books like the gang of four design patterns book and code complete should be used as reference, not a template for how one should do everything.

    Ok, I understand your point more now, it seemed more informal originally. I am coming at this as someone who has been in the role of pseudo Senior developer with responsiblity for coding standards by the way.


  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    I don't envy that position. Coding standards can be as religious as indent styles. I guess the best place to start would be how code is split into files, compiler settings, how things like event handlers or callbacks should be managed, what way data structures should be used, if paradigms like MVC should be enforced etc etc.

    It sort of depends on the languages and API you guys use also, as much as it shouldn't. I'm primarily a C++/Win32 dev but lately have been doing a lot of .Net and things like partial classes have prompted me to split out a lot of my C++ classes over a few files where before I'd rarely bother.

    I actually don't think I'd be qualified to do such a job, I just read books, imitate what I consider to be "good" coding practices and review old stuff as I learn new stuff.


  • Registered Users, Registered Users 2 Posts: 2,800 ✭✭✭voxpop


    Coding standards can be as religious as indent styles.

    Thats the main reason for the standards to be official standards. Ppl always have their own way of doing things and I find its much more difficult to change someones coding practices when the standards are not seen as official.

    If I were you Draupnir - I would avoid the lower nitty gritty and focus on good design principles, maintainability and re-usability. Get everyone programming in a good object orientated way with some automated testing and decent build management (CI) and you will go along way to having decent software.


  • Registered Users, Registered Users 2 Posts: 15,065 ✭✭✭✭Malice


    Stackoverflow.com has a few discussions on coding standards that might be of some use.


  • Registered Users, Registered Users 2 Posts: 2,164 ✭✭✭hobochris


    I thought coding standards were drilled into all programmers at college.

    things like:

    -naming practices(variables and methods should have meaningful self explanatory names)

    -indentation: code should be easy to read.

    - comments: useful comments should be added to explain what a class/method is for including date of creation and creator name.

    - code should be reusable, not one huge method.

    The list goes on, but they're the main ones I thought Everyone knew leaving college.

    But with some of the code I've seen, obviously everyone doesn't know or is to lazy to adhere.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 15,065 ✭✭✭✭Malice


    hobochris wrote: »
    I thought coding standards were drilled into all programmers at college.

    things like:

    -naming practices(variables and methods should have meaningful self explanatory names)

    -indentation: code should be easy to read.

    - comments: useful comments should be added to explain what a class/method is for including date of creation and creator name.

    - code should be reusable, not one huge method.

    The list goes on, but they're the main ones I thought Everyone knew leaving college.

    But with some of the code I've seen, obviously everyone doesn't know or is to lazy to adhere.
    You're right to a certain extent. The points you've listed are should be adhered to by any decent developer but personal preference will start to blur the lines a bit. Some people prefer naming conventions like some_function(), others SomeFunction(). Some people set their IDEs to have different tab lengths. As for comments giving creator name and time of creation, some people would leave that information in the source control tool (assuming there is one of course :) ).


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Draupnir wrote: »
    I personally feel it is probably the most important part of any development project, decent coding standards, I'm not just talking about the obvious naming of variables, methods etc. here but consistent approaches to problem solving and consistent usage of the same techniques across members of a development team.

    Do you have problems with coding standards within your own teams?

    I doubt there's a team out there which doesn't have "a problem" with coding standards, personally. Ultimately, its like everything in development...perfection is generally unobtainable, and subjective to boot.

    I think its a significant player in the whole "total cost" picture for an application...but all too often developers / teams / companies look only at "cost to next release / milestone" and see the investment only as a cost.

    I'm not sure if I'd say its the most important aspect. I dunno that I could single out any one thing and say its the "most important". More likely, I'd have a list of between 5 and 10 "critical" factors, where I'd consider a project to be in (or headed for) deep **** if it had more then 2 items on the list missing.
    I wonder if there could be some way for IDEs to validate against some sort of predefined standards and generate compile time warnings against them? Does this functionality exist in other systems (I'm familiar with .NET and Xcode primarily) that I am unaware of?
    In the Java world, Checkstyle for eclipse does this quite well...for as far as it goes.

    Trying to force consistent use of a technique to solve particular problems isn't really possible (IMHO), but basic-to-middling coding style compliance is well covered.

    Metrics can also be somewhat useful...analysing inter-package calls for example, to see if there's hidden package/library dependencies...or looking for code which falls well outside (2+ standard deviations) some norms of code/comment density, average procedure length, etc.

    My current pet hate in coding standards is SQL. There seems to be something about SQL which encourages people to discard all notions of commenting, code-structure, and every other good coding practice I can think of.


  • Registered Users, Registered Users 2 Posts: 640 ✭✭✭Kernel32


    Draupnir wrote: »
    Just looking for opinions on coding standards and wondering if anyone has any recommended reading on the subject?

    I've done some work in the area over the years and unfortunately it is by and large the most overlooked area of programming by most developers I've encountered.

    I personally feel it is probably the most important part of any development project, decent coding standards, I'm not just talking about the obvious naming of variables, methods etc. here but consistent approaches to problem solving and consistent usage of the same techniques across members of a development team.

    Do you have problems with coding standards within your own teams?

    I wonder if there could be some way for IDEs to validate against some sort of predefined standards and generate compile time warnings against them? Does this functionality exist in other systems (I'm familiar with .NET and Xcode primarily) that I am unaware of?

    I think your mixing up naming conventions with design standards and rolling them into code standards.

    Naming conventions are very important and easily enforceable by using tools correctly. As an example if you combine FxCop for .net with an automated build server like cruisecontrol or TeamCity you can allow senior developers to manage the convention and have the process control the enforcement.

    Design standards are different. This is strongly related to design patterns and principles. If you don't understand design patterns and only use for reference you shouldn't be designing software, you can code software but it would be very bad practise to have you designing. Design standards start at the top level around an agreed approach, are you going to enforce dependency injection, what level of coupling is allowed, are you going to use class interface versioning etc. And then down a level into the use of different patterns which is often dictated by technology because tool support has become so important.


  • Registered Users, Registered Users 2 Posts: 5,618 ✭✭✭Civilian_Target


    hobochris wrote: »
    I thought coding standards were drilled into all programmers at college.

    things like:

    -naming practices(variables and methods should have meaningful self explanatory names)

    -indentation: code should be easy to read.

    - comments: useful comments should be added to explain what a class/method is for including date of creation and creator name.

    - code should be reusable, not one huge method.

    The list goes on, but they're the main ones I thought Everyone knew leaving college.

    But with some of the code I've seen, obviously everyone doesn't know or is to lazy to adhere.

    Exactly. There's two simple ways of dealing with this:

    - Code review is mandatory before any check-in. Including unit tests. If you have someone else definitely reading your code, and who can give you abuse on the subject, for sure you'll be more careful, and you'll learn from them. And how do you make this mandatory? Easy, the reviewer has to check in the code. The author tag is mandatory (must exist, with a date) and the review tag is auto-set by your source control.

    - Simple source control imposed rules. You have to have the support of a senior developer to check in a source file of more than 600 lines, a method or more than 60 lines, or a component of more than 2000 files.


  • Registered Users, Registered Users 2 Posts: 1,821 ✭✭✭Skud


    coding conventions here on sun site might help a little: http://java.sun.com/docs/codeconv/

    Gang of four/design patterns are more design decisions and are different to coding convetions, how you layout your code and name your variables etc. Some people ignore these or form their own over time which can make it hard to read for others.


  • Closed Accounts Posts: 5,082 ✭✭✭Pygmalion


    The IDE KDevelop has (or at least it had, it's pretty much been entirely re-written and new version isn't officially out yet) a menu you can choose coding styles, either preset ones or make your own (Choose indent style, whether braces go on new line in different situations, whether braces are used for one liners and whether switch statement were treated the same I think, maybe more, maybe less).

    It of course didn't do anything but the indenting for you automatically as you code (imagine braces just appearing out of nowhere and how annoying it may be), but for example it had a button to add a new class and used your coding style for that perfectly (You name the class and it's functions and variables and it generates the header and blank functions and names the files).
    There was also a "Clean up code..." button in the tools menu that would go through all the code in the project and apply your coding style.


  • Registered Users, Registered Users 2 Posts: 163 ✭✭stephenlane80


    fasty wrote: »
    I could post many things on thedailywtf.com

    Ha ha sorry to go off on a tangent but that site is hilarious, look what i just found:
    http://thedailywtf.com/Articles/Self-Modifying-VBA.aspx

    Why didn’t i think of self modifying code !! so many possibilities !


Advertisement