C# Coding standards
#1
Posted 19 April 2011 - 11:49 AM
I came across this blog post with a nice set of C# coding standards at http://weblogs.asp.n...s-document.aspx
Now I am not advocating that this "standard" is better than any other standard, what I am suggesting is that the use of some standard is generally better than not having any standard ;-)
As a parenthetical note, remember that the great thing about standards is that you have so many to choose from!
Anyway for someone new to C# programming and Netduinos I would encourage you to read this standard as at a minimum it will cause you to think about the best way to do things, and thinking is always good. Once you have some experience then you can develop your own set of standards.
#2
Posted 19 April 2011 - 12:43 PM
Will be looking at it to add some Coding Standards to my Netduino Tutorial If I can get at it ... been trying ... ok got itI came across this blog post with a nice set of C# coding standards at http://weblogs.asp.n...s-document.aspx
#3
Posted 19 April 2011 - 12:52 PM
I have read that rules in the past, then not long ago, and I think they're very well done.
http://csharpguidelines.codeplex.com/
However, totally agree that the important is the readiness, instead of a bunch of useless rules.
Cheers
#4
Posted 19 April 2011 - 12:57 PM
Please, I do not want to open a can of worms here :-)
I'm not arguing. or trying to open the can anymore, however I will put in my two cents. One statement in the standards, I do Disagree with but only partially. It says DO NOT use Hungarian Notation! I will say if you give me a code snippet to help you out with something. and there are variables declared out of the current context. Hungarian Notation is very helpful. I don't know everything about your code so I have to make a guess as to the type. and My guess could be wrong making it take 3-4 Times as long to help you out. I come from a background where Hungarian Notation was used well strictly. However I have since grown lazy since I moved to c# from VB and VBScript. Intelisense takes care of most of that question for you. but a snippet well is just that. it is a small snapshot of a great meaning. So it just helps.
Terry Massey
#5
Posted 19 April 2011 - 12:59 PM
I'll check that one too !
I want to build a C# guidelines for .net MF code not a full blown .net, like a cheat sheet so thanks for the links !
#6
Posted 19 April 2011 - 01:52 PM
I'm not arguing. or trying to open the can anymore, however I will put in my two cents. One statement in the standards, I do Disagree with but only partially. It says DO NOT use Hungarian Notation! I will say if you give me a code snippet to help you out with something. and there are variables declared out of the current context. Hungarian Notation is very helpful. I don't know everything about your code so I have to make a guess as to the type. and My guess could be wrong making it take 3-4 Times as long to help you out. I come from a background where Hungarian Notation was used well strictly. However I have since grown lazy since I moved to c# from VB and VBScript. Intelisense takes care of most of that question for you. but a snippet well is just that. it is a small snapshot of a great meaning. So it just helps.
As an old 16 bit Windows C programmer, I used to be a big user of Hungarian Notation. You may wish to read http://www.joelonsof...cles/Wrong.html where Joel Spolsky talks about the difference between Apps Hungarian and Systems Hungarian. (Scroll to to the bottom of the post to find it).
I believe Apps Hungarian is extremely useful, but quite frankly today with managed code Systems Hungarian has lost much of its usefulness.
- Michel Trahan likes this
#7
Posted 19 April 2011 - 02:09 PM
As an old 16 bit Windows C programmer, I used to be a big user of Hungarian Notation. You may wish to read http://www.joelonsof...cles/Wrong.html where Joel Spolsky talks about the difference between Apps Hungarian and Systems Hungarian. (Scroll to to the bottom of the post to find it).
I believe Apps Hungarian is extremely useful, but quite frankly today with managed code Systems Hungarian has lost much of its usefulness.
very nice article...... I like where he says I use kind on purpose. type/kind... Well there is a difference. because if I used oSomeCustomObject... that is just useless... but then again the variable name should be descriptive. however if for instance you have a integer/double/long/decimal to me that is very important to differentiate. because precision changes things. Is this a whole number or a decimal value and how precise it is. however if I could easily see that the value is an integer because you put i in front well I know the amount of precision. and the number of bytes it is taking up. so if your having a out of memory issue well knowing the type is important. but yes I agree I really like the suggestion on the us an s.. I do tons of web programming and that is a nice way to handle that..... I might have to start doing that.
Terry Massey
#8
Posted 19 April 2011 - 04:15 PM
Wow ! I was doing it all wrong LOL ! I was mixing up both System and Apps Hungarian, and prefering the Apps one but tried to continue on the System one too and hating it ... been off programming for 7 years ... thanks, now I know what to do, keep the good and throw the bad and ugly system hungarian from my habitsYou may wish to read http://www.joelonsof...cles/Wrong.html where Joel Spolsky talks about the difference between Apps Hungarian and Systems Hungarian. (Scroll to to the bottom of the post to find it).
I believe Apps Hungarian is extremely useful, but quite frankly today with managed code Systems Hungarian has lost much of its usefulness.
A big thanks for the article you point at ! Boy do I love it here, I learn so much !
#9
Posted 19 April 2011 - 05:14 PM
#10
Posted 19 April 2011 - 05:20 PM
#11
Posted 19 April 2011 - 08:15 PM
#12
Posted 19 April 2011 - 10:57 PM
Going to have to disagree with most here. Hungarian is evil. Why? Because if you are writing code in which you need Hungarian Notation then your code is not well written, especially in C#.
The biggest question is about types. How do you know the type? Well any method should be a page or two at the most, as a general rule I define my types at the start of the method or in the method declaration. So that way people don't have to go looking all over for them.
Variables and Method names should be self-documenting by the names you use. Don't use b if you mean socketBuffer, or p1 if you mean outputPin1.
It should be that any person can sit down and read your code and now only know what the variables are doing but what you are trying to do. If you want to change the width for your PWM don't just write Width but write PWMChangeWidthOfPulse(int pulseWidth).
As long as you write code like that anyone will be able to understand it.
I've resisted posting here because one persons perfect "standard" is another persons nightmare. But what "theTroll" has said IMHO, hits the nail on the head.
A book for me that really changed how I write code is Refactoring - Improving the Design of Existing Code by Fowler. I now write much cleaner code, with well thought out variable and method names. And code that no longer needs comments.
I know comments are a polarizing issue, but I eschew code comments. Because in the end, code comments lie. Maybe not today, maybe not next week; but when the code is changed, the comments are almost never updated to reflect the new reality.
#13
Posted 20 April 2011 - 12:39 AM
Got that right lolcode comments lie. Maybe not today, maybe not next week; but when the code is changed, the comments are almost never updated to reflect the new reality.
#14
Posted 31 May 2011 - 03:41 AM
http://10rem.net/art...-best-practices
Hope it helps.
Pete
I work for Microsoft. Opinions expressed here are my own and do not necessarily reflect those of my employer,our partners or customers.
#15
Posted 31 May 2011 - 11:05 AM
Today LED's, tomorrow, the world!!! Well, OK, maybe servos.
#16
Posted 31 May 2011 - 06:21 PM
- Dan Morphis likes this
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users