Are there any suggestions for developing a C# codi

2019-01-03 11:33发布

I'm a recent AI graduate (circa 2 years) working for a modest operation. It has fallen to me (primarily as I'm the first 'adopter' in the department) to create a basic (read useful?) C# coding standards document.

I think I should explain that I'm probably the most junior software engineer going, but I'm looking forward to this task as hopefully I might actually be able to produce something half usable. I've done a pretty extensive search of the Internet and read articles on what a coding standards document should / should not contain. This seems like a good as place as any to ask for some suggestions.

I realise that I am potentially opening a door to a whole world of disagreement about 'the best way to do things'. I both understand and respect the undeniable fact that each programmer has a preferred method of solving each individual task, as a result I'm not looking to write anything so draconianly proscriptive as to stifle personal flair but to try and get a general methodology and agreed standards (e.g. naming conventions) to help make individuals code more readable.

So here goes .... any suggestions? Any at all?

26条回答
做个烂人
2楼-- · 2019-01-03 11:46

The other posters have pointed you at the baseline, all I would add is make your document short, sweet, and to the point, employing a heavy dose of Strunk and White to distinguish the "must haves" from the "it would be nice ifs".

The problem with coding standards documents is that nobody really reads them like they should, and when they do read them, they don't follow them. The likelihood of such a document being read and followed varies inversely with its length.

I agree FxCop is a good tool but too much of this can take all the fun right out of programming, so be careful.

查看更多
迷人小祖宗
3楼-- · 2019-01-03 11:47

I would add Code Complete 2 to the list (I know Jeff is kind of a fan here)... If you are a junior developer, the book comes in handy to set up your mind in a way that sets the foundation for the best code writing practices and software building there are.

I have to say that I came to it a bit late in my career, but it rules a lot of the ways I think about coding and framework development in my professional life.

It's worth checking out ;)

查看更多
Evening l夕情丶
4楼-- · 2019-01-03 11:47

The standard from Philips Medical Systems is well written, and mostly follows Microsoft guidelines: www.tiobe.com/content/paperinfo/gemrcsharpcs.pdf

My standards are based on this with a few tweaks, and some updates for .NET 2.0 (the Philips standard is written for .NET 1.x so is a bit dated).

查看更多
The star\"
5楼-- · 2019-01-03 11:48

We start with

and then document the differences from and additions to that baseline.

查看更多
冷血范
6楼-- · 2019-01-03 11:48

I would be tempted to enforce Microsoft's StyleCop as the standard. It can be enforced at the build time. but if you have legacy code then just enforce using StyleCop on new code.

http://code.msdn.microsoft.com/sourceanalysis

Eventually it will have a refactor option to cleanup code.

http://blogs.msdn.com/sourceanalysis/

查看更多
ら.Afraid
7楼-- · 2019-01-03 11:49

Microsoft's own rules are an excellent starting point. You can enforce them with FxCop.

查看更多
登录 后发表回答