coding-standards

Enforce Attribute Decoration of Classes/Methods

Following on from my recent question on Large, Complex Objects as a Web Service Result. I have been thinking about how I can ensure all future child classes are serializable to XML. Now, obviously I could implement the IXmlSerializable interface and then chuck a reader/writer to it but I would like to avoid that since it then means I ne...

What's your/a good limit for cyclomatic complexity?

Our customers have begun to impose cyclomatic complexity requirements on the software within our products, and our internal process "improvement" group has decided to make cyclomatic complexity part of our coding standards. Both the customer and our internal group have set their (recommendation for an) upper limit at 10. I've argued that...

PHP includes vs OOP

I would like to have a reference for the pros and cons of using include files vs objects(classes) when developing PHP applications. I know I would benefit from having one place to go for this answer...I have a few opinions of my own but I look forward to hearing others. A Simple Example: Certain pages on my site are only accessible to ...

When do you use the "this" keyword?

This may be a silly question, but I was curious how other people use the this keyword. I tend to use it in constructors but may also use it throughout the class in other methods. Some examples: In Constructor: public Light(Vector v) { this.dir = new Vector(v); } Elsewhere public void SomeMethod() { Vector vec = new Vector(...

Enforcing web standards

The HTML standard defines a clear separation of concerns between CSS (presentation) and HTML (semantics or structure). Does anyone use a coding standards document for CSS and XHTML that has clauses which help to maintain this separation? What would be good clauses to include in such a coding standards document? ...

How many constructor arguments is too many?

Let's say you have a class called Customer, which contains the following fields: UserName Email First Name Last Name Let's also say that according to your business logic, all Customer objects must have these four properties defined. Now, we can do this pretty easily by forcing the constructor to specify each of these properties. Bu...

When should one use a project reference opposed to a binary reference?

My company has a common code library which consists of many class libary projects along with supporting test projects. Each class library project outputs a single binary, e.g. Company.Common.Serialization.dll. Since we own the compiled, tested binaries as well as the source code, there's debate as to whether our consuming applications sh...

Standards Document

I am with writing a coding standards document for a team of about 15 with a load of between 10 and 15 projects a year. Amongst other sections (which I may post here as I get to them) I am writing a section on code formatting. So to start with, I think it wise that, for whatever reason, we establish some basic, consistent code formatting/...

What is a magic number, and why is it bad?

What is a magic number? Why should it be avoided? Are there cases where it's appropriate? ...

Are there any good automated frameworks for applying coding standards in Perl?

One I am aware of is Perl::Critic And my googling has resulted in no results on multiple attempts so far. :-( Does anyone have any recommendations here? Any resources to configure Perl::Critic as per our coding standards and run it on code base would be appreciated. ...

Should you use international identifiers in Java/C#?

C# and Java allow almost any character in class names, method names, local variables, etc.. Is it bad practice to use non-ASCII characters, testing the boundaries of poor editors and analysis tools and making it difficult for some people to read, or is American arrogance the only argument against? ...

Is inline code in your aspx pages a good practice?

If I use the following code I lose the ability to right click on variables in the code behind and refactor (rename in this case) them <a href='<%# "/Admin/Content/EditResource.aspx?ResourceId=" + Eval("Id").ToString() %>'>Edit</a> I see this practice everywhere but it seems weird to me as I no longer am able to get compile time errors...

A free tool to check C/C++ source code against a set of coding standards?

It looks quite easy to find such a tool for Java (Checkstyle, JCSC), but I can't seem to find one for C/C++. I am not looking for a lint-like static code analyzer, I only would like to check against coding standards like variable naming, capitalization, spacing, identation, bracket placement, and so on. ...

Code formatting: is lining up similar lines ok?

I recently discovered that our company has a set of coding guidelines (hidden away in a document management system where no one can find it). It generally seems pretty sensible, and keeps away from the usual religious wars about where to put '{'s and whether to use hard tabs. However, it does suggest that "lines SHOULD NOT contain embedd...

Can FxCop/StyleCop be limited to only analyze selected methods from with Visual Studio?

I am taking on a maintenance team and would like to introduce tools like FxCop and StyleCop to help improve the code and introduce the developers to better programming techniques and standards. Since we are maintaining code and not making significant enhancements, we will probably only deal with a couple of methods/routines at a time whe...

Conditional logging with minimal cyclomatic complexity

After reading "What’s your/a good limit for cyclomatic complexity?", I realize many of my colleagues were quite annoyed with this new QA policy on our project: no more 10 cyclomatic complexity per function. Meaning: no more than 10 'if', 'else', 'try', 'catch' and other code workflow branching statement. Right. As I explained in 'Do you...

Is there a valid reason for enforcing a maximum width of 80 characters in a code file, this day and age?

Seriously. On a 22" monitor, it only covers maybe a quarter of the screen. I need some ammo to axe down this rule. Edit: I'm not saying that there shouldn't be a limit; I'm just saying, 80 characters is very small. ...

What kind of prefix do you use for member variables?

No doubt, it's essential for understanding code to give member variables a prefix so that they can easily be distinguished from "normal" variables. But what kind of prefix do you use? I have been working on projects where we used m_ as prefix, on other projects we used an underscore only (which I personally don't like, because an under...

What are Code Smells? What is the best way to correct them?

OK, so I know what a code smell is, and the Wikipedia Article is pretty clear in its definition: In computer programming, code smell is any symptom in the source code of a computer program that indicates something may be wrong. It generally indicates that the code should be refactored or the overall design should be reexa...

Should you enforce coding practice on your third party development team?

I've written up a number of guidlines on codeing practice for a third party developer. One such practice is that no vb file should build up HTML in the code behind. Any HTML should appear in ASCX or ASPX files (so our web designers don't have to learn vb). Every time they release code it contains numerous stringbuilders. How can enforce ...