C# Code convention

626 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
626
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

C# Code convention

  1. 1. Kerry Jiang
  2. 2. <ul><li>Importance of Good Code Convention </li></ul><ul><li>Game: Finding Faults </li></ul><ul><li>Principle of Good Code Convention </li></ul><ul><li>How to write C# code with Good Code Convention? </li></ul><ul><li>XAML Code Convention </li></ul><ul><li>Discussion </li></ul>
  3. 3. <ul><li>Good code convention is a basic factor of high quality software </li></ul><ul><ul><li>Good code convention can reduce maintenance cost (Demo) </li></ul></ul><ul><ul><li>Good code convention can add value on your software </li></ul></ul><ul><ul><li>Improve code convention is easiest way to improve code quality </li></ul></ul><ul><li>Bad code convention interfere team developing </li></ul><ul><ul><li>Bad code convention may introduce bugs (directly or indirectly) </li></ul></ul><ul><ul><li>Bad code convention discourage other developers in your team </li></ul></ul><ul><ul><li>Bad code convention waste developing/testing time </li></ul></ul><ul><ul><li> (Fix convention issue, checkout/check in code require time, whether report QA to test changes?) </li></ul></ul>
  4. 4. <ul><li>Demo Code </li></ul>
  5. 5. <ul><li>Consistent (consistent scale: class, project, solution, product, company) </li></ul><ul><ul><li>Consistent space, indent rules </li></ul></ul><ul><ul><li>Consistent newline rule </li></ul></ul><ul><ul><li>Consistent name convention </li></ul></ul><ul><ul><li>etc. </li></ul></ul><ul><li>Convenient </li></ul><ul><ul><li>Convenient for writing (simple, needn’t do more things , follow English text writing style) </li></ul></ul><ul><ul><li>Convenient for identification (keep spaces and new lines properly) </li></ul></ul><ul><ul><li>Convenient for comparing Convenient for comprehension </li></ul></ul><ul><ul><ul><ul><li>(No matter how well you document your code, the best way to document your code is still: </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Good class name, </li></ul></ul></ul></ul><ul><ul><ul><ul><li>good function name, </li></ul></ul></ul></ul><ul><ul><ul><ul><li>good variable name, </li></ul></ul></ul></ul><ul><ul><ul><ul><li>good filename. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>The rule of thumb is: Give it a name to describe what it does!) </li></ul></ul></ul></ul><ul><li>Clear </li></ul><ul><ul><li>Clear, organized appearance </li></ul></ul><ul><ul><li>Clear logic structure </li></ul></ul>
  6. 6. <ul><li>Consistent IDE and IDE Setting </li></ul><ul><ul><li>Different IDE have different default code styles (e.g. tab in Notepad and VS) </li></ul></ul><ul><ul><li>Same IDE have different setting also may have different code style (e.g. tab size and indent size in VS setting) </li></ul></ul><ul><ul><li>IDE setting must match your company’s code convention </li></ul></ul><ul><li>Let IDE format your code automatically </li></ul><ul><ul><li>Don’t turn off automatically formatting feature of IDE </li></ul></ul><ul><ul><li>IDE can fix your most of code convention issues automatically </li></ul></ul><ul><li>Take advantage of the IDE’s functions to format your code </li></ul><ul><ul><li>Format document: CTRL + E, D / CTRL + K, D </li></ul></ul><ul><ul><li>Format Selection: CTRL + E, F / CTRL + K, F </li></ul></ul><ul><ul><li>View Whitespaces: Ctrl+E, S (checking spaces and tabs before and after line) </li></ul></ul><ul><ul><li>Organize Usings </li></ul></ul><ul><ul><li>etc. </li></ul></ul>
  7. 7. <ul><li>Follow your company’s code convention strictly, don’t do innovation </li></ul><ul><ul><li>If your company’s code convention does not match with IDE’s setting, adjustment your IDE’s setting </li></ul></ul><ul><ul><li>ASP.NET MVC: http://aspnet.codeplex.com/SourceControl/changeset/view/55373#338569 </li></ul></ul><ul><li>Review the code on code convention periodically </li></ul><ul><li>Learn good code convention from other successful projects </li></ul><ul><li>EntLib: http://entlib.codeplex.com/SourceControl/list/changesets </li></ul><ul><li>WPF Toolkit: http:// wpf.codeplex.com/SourceControl/list/changesets </li></ul>
  8. 8. <ul><li>Consistent </li></ul><ul><li>Indent & Aligning </li></ul><ul><li>Bad example: See demo </li></ul><ul><li>Good example: </li></ul><ul><li>http://wpf.codeplex.com/SourceControl/changeset/view/57274#1142515 </li></ul><ul><li>http://wpf.codeplex.com/SourceControl/changeset/view/57274#564021 </li></ul>
  9. 9. <ul><li>Other languages Code Convention </li></ul><ul><li>Q & A </li></ul>Discussion

×