Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Coding style discussion


  • Please log in to reply
17 replies to this topic

#1 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 23 January 2011 - 02:44 PM

Edit: Actually there is one other thing, what is DDD?: this http://www.gnu.org/software/ddd/?


my guess was this: http://en.wikipedia....n-driven_design

... i've added it to my extensive list of things to read about.

#2 Brandon G

Brandon G

    Advanced Member

  • Members
  • PipPipPip
  • 92 posts
  • LocationVancouver BC, Canada

Posted 23 January 2011 - 05:12 PM

Yes Domain Driven Design, read eric evans and Jimmy Nillson, they changed everything

#3 Luke Cummings

Luke Cummings

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationCalgary, AB

Posted 27 January 2011 - 04:07 PM

Move your _coefficients.Length statement to it's own local variable, before you loop and then reference that. It's much faster in netMF than referencing the property.

Also, underscores are against most best practices for .Net :)


Hey Mark, good catch i didn't even notice I did that. Also the _privateMember or m_privateMember is apart of most c# coding standards I've seen.
Cheap, Fast, Good... Pick two

#4 Brandon G

Brandon G

    Advanced Member

  • Members
  • PipPipPip
  • 92 posts
  • LocationVancouver BC, Canada

Posted 27 January 2011 - 04:21 PM

lol on the underscores, there's alot of things i do that arent in ms' best practises. I'd say 80% of the community uses the same naming practises as above. Going to research the IL to see your other suggestion

#5 Chris Seto

Chris Seto

    Advanced Member

  • Members
  • PipPipPip
  • 405 posts

Posted 27 January 2011 - 04:55 PM

Chris, you may want to avoid being a dbag too many times in a row. It makes it very difficult to read the thread.


It's generally not a great idea to say not nice things someone who has at least hundreds of hours of experience in just the project you are embarking on. :)

As for the code issues that Mark pointed out, you may want to read the C# .NET best practices here is a good presentation on it: http://www.google.co...AlvSJxQ&cad=rja

(warning, that's a Powerpoint)

Also: http://blogs.msdn.co.../26/361363.aspx
And... http://msdn.microsof...y/ms229042.aspx

#6 Brandon G

Brandon G

    Advanced Member

  • Members
  • PipPipPip
  • 92 posts
  • LocationVancouver BC, Canada

Posted 27 January 2011 - 05:04 PM

•Do not use Hungarian notation •Do not use a prefix for member variables (_, m_, s_, etc.). If you want to distinguish between local and member variables you should use “this.” in C# and “Me.” in VB.NET. •Do use camelCasing for member variables •Do use camelCasing for parameters •Do use camelCasing for local variables •Do use PascalCasing for function, property, event, and class names •Do prefix interfaces names with “I” •Do not prefix enums, classes, or delegates with any letter Me and the rest of the community disagree with this, i understand why its stated as it is, but i disagree. using this. is ugly and redundant (resharper agrees) Its just a style, i've worked with a few of the top guys over the years and we all use this style, at beginning of projects we agree on a naming convention and this is the one we have consistently agreed upon

#7 Chris Seto

Chris Seto

    Advanced Member

  • Members
  • PipPipPip
  • 405 posts

Posted 27 January 2011 - 05:10 PM

Hmm, now that I look at it, some of those are wrong •Do prefix interfaces names with “I” That one in particular along with some of the others. OK, well, scratch that blog article.

#8 Brandon G

Brandon G

    Advanced Member

  • Members
  • PipPipPip
  • 92 posts
  • LocationVancouver BC, Canada

Posted 27 January 2011 - 05:22 PM

yea its counterintuitive I is used for Interface and I want to know that straight up at the beginning if i'm dealing with an interface. I think at the end of there are slight variations in coding style, i like to know whether i'm private or public or a const or a Public Member and interface a factory a handler a delegate an event, just by looking at the variable name, i used to be even more explicit than this but the big guys jumped all over me. Its just a readability thing for me and as long as all parties agree at beginning of project you're solid. And Chris / Luke, never do i burn a bridge, but cut me some slack, we're all just trying to do neat stuff and have fun or work, how we post is not a big deal, if i get excited about something sometimes i'll throw a few posts down in a row, its an iterative process and sometimes a stream of thought happens, there's no egos or etiquette, its just code. We are all a community and need each others help at certain points in the process, so I would hope to be able to lean on anyone that has more experience than I especially in this specific project, hopefully one day you can lean on me for parts of your projects.

#9 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 27 January 2011 - 06:47 PM

lol on the underscores, there's alot of things i do that arent in ms' best practises. I'd say 80% of the community uses the same naming practises as above. Going to research the IL to see your other suggestion


We've used _ and m_. If I remember right, Microsoft's source code is full of both :)

We're looking at standardizing on m_, but mostly to appease the best-practices post-processor as we aren't concerned about private variables starting with _ needing to be exposed publicly to other .NET languages.

Chris

#10 Brandon G

Brandon G

    Advanced Member

  • Members
  • PipPipPip
  • 92 posts
  • LocationVancouver BC, Canada

Posted 27 January 2011 - 06:54 PM

Resharper is my best practises post processor :)

#11 Mark H

Mark H

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts
  • LocationPerth, Western Australia

Posted 28 January 2011 - 03:34 AM

_ and m_ are all well and good for C/C++ however for C# they are redundant with the IDE making everything extremely visible. There is a reason for microsoft's best practices, I'd be happy to go through them all if you wish, however it's going to be a huge post and this thread is not the right place for it. Microsoft's best practices, or some very close semblance of are used in almost every company that develops C# software that I have seen/worked with/worked at. The only people I don't see following them are: Recent converts from C/C++, Amateurs following other amateurs bad examples, total beginners who are porting tArduino code over verbatim, and finally, people who think it makes them look cool/experienced to write code like you would in C/C++.If you're basing your best practices on a forum full of (no offence intended to anyone) relatively beginner/amateur developers with only a few professionals.. well, that's up to you I guess. Most code I've seen around Netduino/GHI/netmf and especially the SFE/Arduino forums would get you reprimanded in a corporate/company environment. Just because other people do it badly (mostly through ignorance as they are beginners) is absolutely no reason to as well. Having written best practices for companies in the past, and having reviewed hundreds of best practice documents I can confidently say that Microsoft's best practices are well adhered to in the corporate world. I've looked a Philips, GE, several mining companies, banks and many other large organisations, as well as dozens of smaller companies. Best practices are there for code readability, usability, ease of maintenance and the fact that most of it is common sense. To anyone who wants to know more about C# coding conventions, I highly recommend you pick up a copy of Framework Design Guidelines, by Krzysztof Cwalina and Brad Abrams. This is an exceptional book that is very insightful on design libraries, classes, interfaces, naming patters, etc.

#12 Brandon G

Brandon G

    Advanced Member

  • Members
  • PipPipPip
  • 92 posts
  • LocationVancouver BC, Canada

Posted 28 January 2011 - 04:04 AM

Mark, Thank you for your comments, this forum has truly tested my ability to hold my tongue and be professional. I will try to make a point of not posting questions that expose you to my "amateur / ignorant" coding techniques shared by ms mvps and the ms clr team. Great community we have here.

#13 Mark H

Mark H

    Advanced Member

  • Members
  • PipPipPip
  • 70 posts
  • LocationPerth, Western Australia

Posted 28 January 2011 - 04:51 AM

Mark,
Thank you for your comments, this forum has truly tested my ability to hold my tongue and be professional.
I will try to make a point of not posting questions that expose you to my "amateur / ignorant" coding techniques shared by ms mvps and the ms clr team.


Great community we have here.

Brandon, I think you're reading my comments in the wrong tone - i meant them as a general comment, not targeted at anyone specific. I'm an Aussie, we're pretty layed back and chill - if in doubt, just read my post as a layed back view point :)

Please feel free to take a look at these links:
IDesign have an exceptional coding standard for C#, which a lot of companies I know of base their standards on. These are basically an expansion of Microsoft's:
http://www.idesign.n...ng Standard.zip - zip with PDF.


This is what Microsoft use internally: http://blogs.msdn.co.../26/361363.aspx

The guideline for creating class libraries is a rather informative read: http://msdn.microsof...y/ms229042.aspx

And this is the book I mentioned (which I recommend every developer - professional, amatuer and enthisuast alike read) - http://www.amazon.com/dp/0321545613/ - on on Book Depository if you're not in the USA (free shipping! woo) http://www.bookdepos...sign-Guidelines

#14 Luke Cummings

Luke Cummings

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationCalgary, AB

Posted 28 January 2011 - 11:08 PM

Brandon, I think you're reading my comments in the wrong tone - i meant them as a general comment, not targeted at anyone specific. I'm an Aussie, we're pretty layed back and chill - if in doubt, just read my post as a layed back view point :)

Please feel free to take a look at these links:
IDesign have an exceptional coding standard for C#, which a lot of companies I know of base their standards on. These are basically an expansion of Microsoft's:
http://www.idesign.n...ng Standard.zip - zip with PDF.


This is what Microsoft use internally: http://blogs.msdn.co.../26/361363.aspx

The guideline for creating class libraries is a rather informative read: http://msdn.microsof...y/ms229042.aspx

And this is the book I mentioned (which I recommend every developer - professional, amatuer and enthisuast alike read) - http://www.amazon.com/dp/0321545613/ - on on Book Depository if you're not in the USA (free shipping! woo) http://www.bookdepos...sign-Guidelines



IDesigns C# standards (my personal favourite), section 1 point 4:

Prefix member variables with m_. Use Pascal casing for the rest of a member
variable name following the m_.
public class SomeClass
{
   private int m_Number;
}

Cheap, Fast, Good... Pick two

#15 bill.french

bill.french

    Advanced Member

  • Members
  • PipPipPip
  • 260 posts
  • LocationPrinceton, NJ

Posted 28 January 2011 - 11:39 PM

i vote Chris Walker deletes all posts in this thread (including this one) that do not contribute to (or at least encourage) the achievement of safe netmf quardoflight.

#16 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 January 2011 - 11:49 PM

i vote Chris Walker deletes all posts in this thread (including this one) that do not contribute to (or at least encourage) the achievement of safe netmf quardoflight.


Hey Bill,

We're very much against censorship (with a few exceptions like vulgarity). But we should probably keep things on topic, and we do want to build a community of friends here...

I've gone ahead and "split" all coding style discussions to this new thread.

Everyone...thanks in advance for both being polite and sharing your knowledge. I didn't realize that Microsoft's coding styles had become so standardized since .NET was introduced. A learning experience for all I suppose...

Chris

#17 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 29 January 2011 - 07:56 AM

Prefixes are a bit sensitive in style regi, I guess. Things like m_, g_ and IInterface are variations or leftovers from Hungarian notation and therefor should be banned. However as many publications notes, things like class members are also in a sense 'global variables'. It is therefor worth alienating them with prefix m_ (and thereby make you choke when reading). Notations such as 'this.' is not sufficient as it is not enforced by the compiler. Meh.

#18 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 29 January 2011 - 08:02 AM

Publications such as Code Complete will tell you to use the m_ btw. Even in .NET.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.