Wednesday, April 26, 2006

Coding Standards

Well, since the Web Illustrations project came together so fast we never really took the time to hammer out any good coding standards for our new .NET code, as well as HTML, scripts, etc. Now that the dust is settling a bit I'm going back and trying to clean up and comment some of my code. We now have Delphi.NET, C#, JavaScript, HTML, CSS, and XML files just to name a few. We do have documentation on Win32 Delphi coding standards, albeit a bit old.

For our C# code we should follow the Microsoft recommendations. It can be found on MSDN at:

Design Guidelines for Class Library Developers

Would it also make sense for our Delphi.NET code to follow this standard as well? Or should it follow closer to the Win32 Delphi standards we currently use? Perhaps Rich or Steve could speak as to what they've been doing in the .NET code sections.

I did some looking but could not find an authoritative JavaScript coding standard. There were several mentions to a document on the Netscape developers site but it appears to be gone. The Mozilla project doesn't seem to have anything similar. It appears to me that most sites (including Microsoft) appear to use Camel Case for most of their JavaScript variables and methods. I've tried to follow suit.

HTML, CSS and XML standards are sort of a whole other animal and perhaps would be worthy of a thread all their own if anyone is interested.

So I pose it to the group, what are your thoughts/feelings/recommendations on new and improved standards? Perhaps some of the new people have experience from their previous lives?

2 comments:

Brad said...

Here are a few things that immediately come to mind.

Camel Case: This is what I see (and used in the past) in 95% of samples. We capitalize the first letter of each "sub" word in an identifier, but there's no reason to do that with the first letter, e.g. "boboLovesCake" is just as readable as "BoboLovesCake" and the former is slightly easier to type. It's a minor distinction, but pennies add up.
This applies to variables, methods, and parameters; not type names. This is slightly different from this page of the spec - it recommends Pascal case for methods.

T for Type: I've never understood this anyway, and I've read at least one Delphi authority (Dr. Bob) recommend discontinuing it's use in the .Net world. I for interface is still useful since interfaces are a different animal from types.

Brad said...

A few articles for perspective:
Neal Ford - see "Eating Sacred Hamburger".
Making Wrong Code Look Wrong.