SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Matiar Rahman
Project Manager
Binary Quest Limited
Agenda
What are Coding Standards?
Benefits of Automation
Standards Automation Tools
Use of StyleCop and FxCop
What are Coding Standards?
A set of rules or guidelines used when writing the
source code of a computer program.
Generally dictates:
Safety mandates to avoid introducing errors.
Style mandates to increase maintainability.
Security mandates to avoid vulnerabilities.
Efficiency mandates to help increase performance.
Standards may be enforced through code reviews or
may simply be “suggestions”.
Standards: Like or Dislike?
But, Isn’t Programming Art?
This always has been an interesting point of
contention.
On one extreme development can be thought of as a
work of art and any source that reaches a logically
correct result is acceptable and everything else is just
“style.”
The other extreme believes that programming is purely
a mechanical process and there is only a limited
number of correct answers.
Which is correct?
Reality Lies In Between
It may be more accurate to say developers are more
like artisans (crafters) than artists, though containing
elements of both.
An artist has a wide range of forms they can adhere to
and much is dependent on the interpretation of the
viewer.
In contrast, artisans tend to construct or design for a
purpose, and while there are some elements of style in
construction, if it fails to achieve its purpose
effectively, it is a failure.
The “Art” of Sorting
Take sorting, for example.
Both Bubble sort and Quick sort are valid sorts on a set
of data.
Bubble sort has a complexity of O(n2
) and Quick sort is
O(n log n).
Assuming sorting 1 million elements and each check
takes 1 µs, roughly this would be:
 Bubble Sort: 11 days
 Quick Sort: 19 seconds
Both sort data, but one is clearly more useful.
Standardizing an “Art”
While there are many ways to solve a given problem,
there should be guidelines for effective construction.
These guidelines are similar to building codes used in
building construction to ensure safety and quality.
These guidelines form the basis for coding standards
and are best compiled from group consensus and
industry best practices.
Enforcing Standards
Standards should be enforced to promote safety,
efficiency, and maintainability.
Standards can be enforced through Code Reviews, but
these tend to be applied with varying levels of
adherence.
It’s much better to attempt to automate as much of
your standards as possible so that the code is judged
more objectively.
Benefits of Automation
Standards are applied objectively since only analyzes
the source or assembly.
Just plain faster than trying to catch standards
violations manually.
Code authors don’t feel personally attacked.
Frees more reviewer time since won’t have to waste as
much time in code reviews.
Frees more time for developers since code spends less
time and iterations in review.
Standards Automation Tools
There are two primary tools from Microsoft:
StyleCop – Analyzes source files to determine if source
code is correctly formatted.
FxCop (Static Code Analysis)– Analyzes assemblies to
determine if code is constructed safely and optimally.
These tools overlap in some of their base rules but
both have their strengths.
Other third party and Microsoft tools exist, but
beyond this presentation’s scope.
FxCop, VS Code Analysis
Static analysis
Analyzes compiled assembly (dll, exe)
Finds violations of programming and design rules
 http://msdn.microsoft.com/en-us/library/3z0aeatx.aspx
Gendarme
Static analysis
Analyzes compiled assembly (dll, exe)
Finds violations of programming and design rules
 http://mono-project.com/Gendarme
NDepend
Analyses compiled assembly (dll, exe)
Measure, visualize and query source code quality
 http://www.ndepend.com/
Pex
Dynamic analysis
Analyzes code branches at runtime
Generates inputs to achieve max coverage
Generates test cases
 http://research.microsoft.com/en-us/projects/pex/
Code Contracts
Static checker
Analyzes compiled assembly (dll, exe)
Reports formal contract violations
 http://research.microsoft.com/en-us/projects/contracts/
FsCheck
Randomly generates test inputs
Generates test cases based on program specifications
Port of Haskell's QuickCheck
 http://fscheck.codeplex.com/
Simian
Analyzes source code
Detects duplication
http://www.harukizaemon.com/simian/index.ht
ml
StyleCop
Analyzes source files and not compiled code.
Great for checking elements such as:
Spacing
Comments
File composition
Naming
Cannot easily check type hierarchies or program
structure.
Available at http://stylecop.codeplex.com/
Configuring StyleCop
If you have StyleCop installed, you can have
Settings.StyleCop files for each project if you want to
vary styles per project.
Will take the first Settings.StyleCop file it finds from
working directory on up the path.
Default will be the Settings.StyleCop file in
c:program filesMicrosoft StyleCop…
Various configurations can make harder to enforce
uniform rules, though, so use with caution.
Configuring StyleCop
You can configure which base rules you want active by
using StyleCopSettingsEditor.exe.
Let’s take a minute to look at the rules…
Configuring StyleCop
You can also get to StyleCop settings in Visual Studio
directly by right-clicking a project.
This creates local copy of rules, use cautiously.
Running StyleCop
You can run StyleCop from VS or MSBuild.
Has no native command-line interface, but one exists
at sourceforge called StyleCopCmd.
StyleCop Results
Shows in Error List window, can turn on “Warnings as
Errors” in VS if you want to break builds on violations.
Suppressing a Rule
Most rules are good all the time, sometimes not.
On Suppressing Rules
It’s better to keep a rule even if it only applies 95% of
the time and force developers to suppress the rule for
the one-off exceptions.
This puts a SuppressMessage attribute in code
which must be justified and prevents viewing the
exception to the rule as a precedent for ignoring the
rule.
If code reviewer disagrees, can be debated.
Turning off rules should be avoided unless the rule is
invalid most or all of the time.
Custom StyleCop Rules
StyleCop rules are fairly easy to write.
Create class library that references the StyleCop
assemblies:
Located in c:program filesMicrosoft StyleCop…
 Microsoft.StyleCop.dll
 Microsoft.StyleCop.Csharp.dll
Add a CS (C# source file) for new analyzer.
Add an XML file for rule configuration.
Custom StyleCop Rules
In the CS file, create an analyzer that inherits from
SourceAnalyzer and has class attribute also named
SourceAnalyzer for C# files.s
Custom StyleCop Rules
In the CS file, override AnalyzeDocument and
perform your checks.
Custom StyleCop Rules
When you see your violation, call the method
AddViolation and give it a rule name and args:
Custom Style Cop Rules
Then, in the XML file, define the rule and message.
Make sure XML file has same name as class name and
is Embedded Resource.
Custom StyleCop Rules
Then, build the custom assembly.
Place custom assembly in:
C:Program FilesMicrosoft StyleCop …
You should now see custom rules in the
StyleCopSettingsEditor.
If you don’t see custom rules, check that the XML file:
Is an embedded resource
Has same filename as the class name (minus
extensions)
Let’s look at the code more closely…
StyleCop for ReSharper
JetBrains’s ReSharper is an Visual Studio IDE plug-in
that adds a lot of refactoring and aids.
StyleCop for ReSharper is a ReSharper plug-in that
allows for dynamic checking of StyleCop rules as you
type.
Will highlight rule violations with squiggle just like
other ReSharper hints.
http://stylecopforresharper.codeplex.com/
Let’s look at how this appears in the IDE.
FxCop (aka VS Code Analysis)
Great for checking elements such as:
Non-spacing style issues (naming, etc).
Code safety and performance issues
Type hierarchy issues
Analysis of database objects
Cannot check source style such as spacing.
Already baked into Visual Studio 2008/10.
Can also be used as a stand-alone.
Running FxCop Stand-Alone
Start  Programs Microsoft FxCop
Create new project, add targets, and Analyze!
Running FxCop From Visual Studio
Right click on project or solution and choose Run
Code Analysis:
Let’s look at an example analysis.
Suppressing FxCop Errors
Just like in StyleCop, you can suppress one-off
exceptions to the rules.
Can insert manually or automatically from the error
list in Visual Studio.
Custom FxCop Rules
Create a Class Library in Visual Studio.
Add references to FxCop assemblies:
From C:Program FilesMicrosoft FxCop…
 FxCopCommon.dll
 FxCopSdk.dll
 Microsoft.Cci.dll
 Microsoft.VisualStudio.CodeAnalysis
Add a CS file for the new rule.
Add an XML file for the rule definition.
Custom FxCop Rules
In CS file create class that inherits from
BaseIntrospectionRule:
Custom FxCop Rules
In CS File, override Check to check rule.
Custom FxCop Rule
XML file is Embedded and contains rule detail:
Remember filename must be same as passed to base
constructor of BaseIntrospectionRule.
Custom FxCop Rules
To use custom rule, use CTRL+R or Project  Add
Rules in FxCop.
You can verify by clicking on rules tab:
Summary
Automating code standards can be very useful for
getting rid of a lot of the “noise” in code reviews and
allowing reviewers to concentrate on logic bugs.
Automated code standards take the personal side out
of enforcing style, safety, and performance.
Custom rules can be used in FxCop and StyleCop to
allow for your own rules.

Weitere ähnliche Inhalte

Was ist angesagt?

Regular use of static code analysis in team development
Regular use of static code analysis in team developmentRegular use of static code analysis in team development
Regular use of static code analysis in team developmentPVS-Studio
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality ToolsOrest Ivasiv
 
Writing clean code in C# and .NET
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NETDror Helper
 
Programming practises and project management for professionnal software devel...
Programming practises and project management for professionnal software devel...Programming practises and project management for professionnal software devel...
Programming practises and project management for professionnal software devel...Geeks Anonymes
 
Beyond Static Analysis: Integrating .NET Static Analysis with Unit Testing a...
Beyond Static Analysis: Integrating .NET  Static Analysis with Unit Testing a...Beyond Static Analysis: Integrating .NET  Static Analysis with Unit Testing a...
Beyond Static Analysis: Integrating .NET Static Analysis with Unit Testing a...Erika Barron
 
Code Review
Code ReviewCode Review
Code ReviewDivante
 
Static code analysis
Static code analysisStatic code analysis
Static code analysisRune Sundling
 
Code Review
Code ReviewCode Review
Code Reviewrantav
 
Regular use of static code analysis in team development
Regular use of static code analysis in team developmentRegular use of static code analysis in team development
Regular use of static code analysis in team developmentPVS-Studio
 
Regular use of static code analysis in team development
Regular use of static code analysis in team developmentRegular use of static code analysis in team development
Regular use of static code analysis in team developmentAndrey Karpov
 
Software testing tools
Software testing toolsSoftware testing tools
Software testing toolsGaurav Paliwal
 
FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09Pyxis Technologies
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionPyxis Technologies
 
Code review for secure web applications
Code review for secure web applicationsCode review for secure web applications
Code review for secure web applicationssilviad74
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated TestingLee Englestone
 

Was ist angesagt? (19)

Regular use of static code analysis in team development
Regular use of static code analysis in team developmentRegular use of static code analysis in team development
Regular use of static code analysis in team development
 
Java Code Quality Tools
Java Code Quality ToolsJava Code Quality Tools
Java Code Quality Tools
 
Writing clean code in C# and .NET
Writing clean code in C# and .NETWriting clean code in C# and .NET
Writing clean code in C# and .NET
 
Programming practises and project management for professionnal software devel...
Programming practises and project management for professionnal software devel...Programming practises and project management for professionnal software devel...
Programming practises and project management for professionnal software devel...
 
Parasoft fda software compliance part2
Parasoft fda software compliance   part2Parasoft fda software compliance   part2
Parasoft fda software compliance part2
 
Beyond Static Analysis: Integrating .NET Static Analysis with Unit Testing a...
Beyond Static Analysis: Integrating .NET  Static Analysis with Unit Testing a...Beyond Static Analysis: Integrating .NET  Static Analysis with Unit Testing a...
Beyond Static Analysis: Integrating .NET Static Analysis with Unit Testing a...
 
Code Review
Code ReviewCode Review
Code Review
 
Static code analysis
Static code analysisStatic code analysis
Static code analysis
 
Code Review
Code ReviewCode Review
Code Review
 
Code Review
Code ReviewCode Review
Code Review
 
Regular use of static code analysis in team development
Regular use of static code analysis in team developmentRegular use of static code analysis in team development
Regular use of static code analysis in team development
 
Regular use of static code analysis in team development
Regular use of static code analysis in team developmentRegular use of static code analysis in team development
Regular use of static code analysis in team development
 
Software testing tools
Software testing toolsSoftware testing tools
Software testing tools
 
FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09FluentSelenium Presentation Code Camp09
FluentSelenium Presentation Code Camp09
 
Code Review
Code ReviewCode Review
Code Review
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and Adoption
 
09 coding standards_n_guidelines
09 coding standards_n_guidelines09 coding standards_n_guidelines
09 coding standards_n_guidelines
 
Code review for secure web applications
Code review for secure web applicationsCode review for secure web applications
Code review for secure web applications
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
 

Andere mochten auch

The Benefits of Automation - Digiday Programmatic Rome, 11/10/15
The Benefits of Automation - Digiday Programmatic Rome, 11/10/15The Benefits of Automation - Digiday Programmatic Rome, 11/10/15
The Benefits of Automation - Digiday Programmatic Rome, 11/10/15Digiday
 
Oojeema - SSC JPIA Benefits of Automation
Oojeema - SSC JPIA Benefits of AutomationOojeema - SSC JPIA Benefits of Automation
Oojeema - SSC JPIA Benefits of AutomationCid Systems
 
Automation Benefits and its future
Automation Benefits and its futureAutomation Benefits and its future
Automation Benefits and its futureRIA RUI Society
 
Presentation on automation
Presentation on automationPresentation on automation
Presentation on automationRangachary1222
 
Automation presentation
Automation presentationAutomation presentation
Automation presentationAKANSHA GURELE
 
Pragmatic Java Test Automation
Pragmatic Java Test AutomationPragmatic Java Test Automation
Pragmatic Java Test AutomationDmitry Buzdin
 
Introduction to automation ppt
Introduction to automation pptIntroduction to automation ppt
Introduction to automation pptHimani Harbola
 
Ppt on automation
Ppt on automation Ppt on automation
Ppt on automation harshaa
 

Andere mochten auch (8)

The Benefits of Automation - Digiday Programmatic Rome, 11/10/15
The Benefits of Automation - Digiday Programmatic Rome, 11/10/15The Benefits of Automation - Digiday Programmatic Rome, 11/10/15
The Benefits of Automation - Digiday Programmatic Rome, 11/10/15
 
Oojeema - SSC JPIA Benefits of Automation
Oojeema - SSC JPIA Benefits of AutomationOojeema - SSC JPIA Benefits of Automation
Oojeema - SSC JPIA Benefits of Automation
 
Automation Benefits and its future
Automation Benefits and its futureAutomation Benefits and its future
Automation Benefits and its future
 
Presentation on automation
Presentation on automationPresentation on automation
Presentation on automation
 
Automation presentation
Automation presentationAutomation presentation
Automation presentation
 
Pragmatic Java Test Automation
Pragmatic Java Test AutomationPragmatic Java Test Automation
Pragmatic Java Test Automation
 
Introduction to automation ppt
Introduction to automation pptIntroduction to automation ppt
Introduction to automation ppt
 
Ppt on automation
Ppt on automation Ppt on automation
Ppt on automation
 

Ähnlich wie Codingstandards matiar

Automating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopAutomating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopBlackRabbitCoder
 
Rhapsody Software
Rhapsody SoftwareRhapsody Software
Rhapsody SoftwareBill Duncan
 
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Søren Lund
 
Code Review
Code ReviewCode Review
Code ReviewRavi Raj
 
Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.DrupalCampDN
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016Søren Lund
 
APIs And SDKs Breaking Into And Succeeding In A Specialty Market
APIs And SDKs  Breaking Into And Succeeding In A Specialty MarketAPIs And SDKs  Breaking Into And Succeeding In A Specialty Market
APIs And SDKs Breaking Into And Succeeding In A Specialty MarketBill Dubie
 
Using HPC Resources to Exploit Big Data for Code Review Analytics
Using HPC Resources to Exploit Big Data for Code Review AnalyticsUsing HPC Resources to Exploit Big Data for Code Review Analytics
Using HPC Resources to Exploit Big Data for Code Review AnalyticsThe University of Adelaide
 
Anti Patterns Siddhesh Lecture1 Of3
Anti Patterns Siddhesh Lecture1 Of3Anti Patterns Siddhesh Lecture1 Of3
Anti Patterns Siddhesh Lecture1 Of3Siddhesh Bhobe
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applicationsChandra Sekhar Saripaka
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional ProgrammerDave Cross
 
Measuring Your Code
Measuring Your CodeMeasuring Your Code
Measuring Your CodeNate Abele
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure rupeshchanchal
 

Ähnlich wie Codingstandards matiar (20)

Automating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCopAutomating C# Coding Standards using StyleCop and FxCop
Automating C# Coding Standards using StyleCop and FxCop
 
Ensuring code quality
Ensuring code qualityEnsuring code quality
Ensuring code quality
 
Rhapsody Software
Rhapsody SoftwareRhapsody Software
Rhapsody Software
 
Unit iv
Unit ivUnit iv
Unit iv
 
Introducing fx cop
Introducing fx copIntroducing fx cop
Introducing fx cop
 
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016
 
Code Review
Code ReviewCode Review
Code Review
 
Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.Code Review Looking for a vulnerable code. Vlad Savitsky.
Code Review Looking for a vulnerable code. Vlad Savitsky.
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016
 
APIs And SDKs Breaking Into And Succeeding In A Specialty Market
APIs And SDKs  Breaking Into And Succeeding In A Specialty MarketAPIs And SDKs  Breaking Into And Succeeding In A Specialty Market
APIs And SDKs Breaking Into And Succeeding In A Specialty Market
 
Abcxyz
AbcxyzAbcxyz
Abcxyz
 
Using HPC Resources to Exploit Big Data for Code Review Analytics
Using HPC Resources to Exploit Big Data for Code Review AnalyticsUsing HPC Resources to Exploit Big Data for Code Review Analytics
Using HPC Resources to Exploit Big Data for Code Review Analytics
 
Anti Patterns Siddhesh Lecture1 Of3
Anti Patterns Siddhesh Lecture1 Of3Anti Patterns Siddhesh Lecture1 Of3
Anti Patterns Siddhesh Lecture1 Of3
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
 
07 fse implementation
07 fse implementation07 fse implementation
07 fse implementation
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
test
testtest
test
 
JS-formatter
JS-formatterJS-formatter
JS-formatter
 
Measuring Your Code
Measuring Your CodeMeasuring Your Code
Measuring Your Code
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
 

Kürzlich hochgeladen

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Kürzlich hochgeladen (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Codingstandards matiar

  • 2. Agenda What are Coding Standards? Benefits of Automation Standards Automation Tools Use of StyleCop and FxCop
  • 3. What are Coding Standards? A set of rules or guidelines used when writing the source code of a computer program. Generally dictates: Safety mandates to avoid introducing errors. Style mandates to increase maintainability. Security mandates to avoid vulnerabilities. Efficiency mandates to help increase performance. Standards may be enforced through code reviews or may simply be “suggestions”.
  • 5. But, Isn’t Programming Art? This always has been an interesting point of contention. On one extreme development can be thought of as a work of art and any source that reaches a logically correct result is acceptable and everything else is just “style.” The other extreme believes that programming is purely a mechanical process and there is only a limited number of correct answers. Which is correct?
  • 6. Reality Lies In Between It may be more accurate to say developers are more like artisans (crafters) than artists, though containing elements of both. An artist has a wide range of forms they can adhere to and much is dependent on the interpretation of the viewer. In contrast, artisans tend to construct or design for a purpose, and while there are some elements of style in construction, if it fails to achieve its purpose effectively, it is a failure.
  • 7. The “Art” of Sorting Take sorting, for example. Both Bubble sort and Quick sort are valid sorts on a set of data. Bubble sort has a complexity of O(n2 ) and Quick sort is O(n log n). Assuming sorting 1 million elements and each check takes 1 µs, roughly this would be:  Bubble Sort: 11 days  Quick Sort: 19 seconds Both sort data, but one is clearly more useful.
  • 8. Standardizing an “Art” While there are many ways to solve a given problem, there should be guidelines for effective construction. These guidelines are similar to building codes used in building construction to ensure safety and quality. These guidelines form the basis for coding standards and are best compiled from group consensus and industry best practices.
  • 9. Enforcing Standards Standards should be enforced to promote safety, efficiency, and maintainability. Standards can be enforced through Code Reviews, but these tend to be applied with varying levels of adherence. It’s much better to attempt to automate as much of your standards as possible so that the code is judged more objectively.
  • 10. Benefits of Automation Standards are applied objectively since only analyzes the source or assembly. Just plain faster than trying to catch standards violations manually. Code authors don’t feel personally attacked. Frees more reviewer time since won’t have to waste as much time in code reviews. Frees more time for developers since code spends less time and iterations in review.
  • 11. Standards Automation Tools There are two primary tools from Microsoft: StyleCop – Analyzes source files to determine if source code is correctly formatted. FxCop (Static Code Analysis)– Analyzes assemblies to determine if code is constructed safely and optimally. These tools overlap in some of their base rules but both have their strengths. Other third party and Microsoft tools exist, but beyond this presentation’s scope.
  • 12. FxCop, VS Code Analysis Static analysis Analyzes compiled assembly (dll, exe) Finds violations of programming and design rules  http://msdn.microsoft.com/en-us/library/3z0aeatx.aspx
  • 13. Gendarme Static analysis Analyzes compiled assembly (dll, exe) Finds violations of programming and design rules  http://mono-project.com/Gendarme
  • 14. NDepend Analyses compiled assembly (dll, exe) Measure, visualize and query source code quality  http://www.ndepend.com/
  • 15. Pex Dynamic analysis Analyzes code branches at runtime Generates inputs to achieve max coverage Generates test cases  http://research.microsoft.com/en-us/projects/pex/
  • 16. Code Contracts Static checker Analyzes compiled assembly (dll, exe) Reports formal contract violations  http://research.microsoft.com/en-us/projects/contracts/
  • 17. FsCheck Randomly generates test inputs Generates test cases based on program specifications Port of Haskell's QuickCheck  http://fscheck.codeplex.com/
  • 18. Simian Analyzes source code Detects duplication http://www.harukizaemon.com/simian/index.ht ml
  • 19. StyleCop Analyzes source files and not compiled code. Great for checking elements such as: Spacing Comments File composition Naming Cannot easily check type hierarchies or program structure. Available at http://stylecop.codeplex.com/
  • 20. Configuring StyleCop If you have StyleCop installed, you can have Settings.StyleCop files for each project if you want to vary styles per project. Will take the first Settings.StyleCop file it finds from working directory on up the path. Default will be the Settings.StyleCop file in c:program filesMicrosoft StyleCop… Various configurations can make harder to enforce uniform rules, though, so use with caution.
  • 21. Configuring StyleCop You can configure which base rules you want active by using StyleCopSettingsEditor.exe. Let’s take a minute to look at the rules…
  • 22. Configuring StyleCop You can also get to StyleCop settings in Visual Studio directly by right-clicking a project. This creates local copy of rules, use cautiously.
  • 23. Running StyleCop You can run StyleCop from VS or MSBuild. Has no native command-line interface, but one exists at sourceforge called StyleCopCmd.
  • 24. StyleCop Results Shows in Error List window, can turn on “Warnings as Errors” in VS if you want to break builds on violations.
  • 25. Suppressing a Rule Most rules are good all the time, sometimes not.
  • 26. On Suppressing Rules It’s better to keep a rule even if it only applies 95% of the time and force developers to suppress the rule for the one-off exceptions. This puts a SuppressMessage attribute in code which must be justified and prevents viewing the exception to the rule as a precedent for ignoring the rule. If code reviewer disagrees, can be debated. Turning off rules should be avoided unless the rule is invalid most or all of the time.
  • 27. Custom StyleCop Rules StyleCop rules are fairly easy to write. Create class library that references the StyleCop assemblies: Located in c:program filesMicrosoft StyleCop…  Microsoft.StyleCop.dll  Microsoft.StyleCop.Csharp.dll Add a CS (C# source file) for new analyzer. Add an XML file for rule configuration.
  • 28. Custom StyleCop Rules In the CS file, create an analyzer that inherits from SourceAnalyzer and has class attribute also named SourceAnalyzer for C# files.s
  • 29. Custom StyleCop Rules In the CS file, override AnalyzeDocument and perform your checks.
  • 30. Custom StyleCop Rules When you see your violation, call the method AddViolation and give it a rule name and args:
  • 31. Custom Style Cop Rules Then, in the XML file, define the rule and message. Make sure XML file has same name as class name and is Embedded Resource.
  • 32. Custom StyleCop Rules Then, build the custom assembly. Place custom assembly in: C:Program FilesMicrosoft StyleCop … You should now see custom rules in the StyleCopSettingsEditor. If you don’t see custom rules, check that the XML file: Is an embedded resource Has same filename as the class name (minus extensions) Let’s look at the code more closely…
  • 33. StyleCop for ReSharper JetBrains’s ReSharper is an Visual Studio IDE plug-in that adds a lot of refactoring and aids. StyleCop for ReSharper is a ReSharper plug-in that allows for dynamic checking of StyleCop rules as you type. Will highlight rule violations with squiggle just like other ReSharper hints. http://stylecopforresharper.codeplex.com/ Let’s look at how this appears in the IDE.
  • 34. FxCop (aka VS Code Analysis) Great for checking elements such as: Non-spacing style issues (naming, etc). Code safety and performance issues Type hierarchy issues Analysis of database objects Cannot check source style such as spacing. Already baked into Visual Studio 2008/10. Can also be used as a stand-alone.
  • 35. Running FxCop Stand-Alone Start  Programs Microsoft FxCop Create new project, add targets, and Analyze!
  • 36. Running FxCop From Visual Studio Right click on project or solution and choose Run Code Analysis: Let’s look at an example analysis.
  • 37. Suppressing FxCop Errors Just like in StyleCop, you can suppress one-off exceptions to the rules. Can insert manually or automatically from the error list in Visual Studio.
  • 38. Custom FxCop Rules Create a Class Library in Visual Studio. Add references to FxCop assemblies: From C:Program FilesMicrosoft FxCop…  FxCopCommon.dll  FxCopSdk.dll  Microsoft.Cci.dll  Microsoft.VisualStudio.CodeAnalysis Add a CS file for the new rule. Add an XML file for the rule definition.
  • 39. Custom FxCop Rules In CS file create class that inherits from BaseIntrospectionRule:
  • 40. Custom FxCop Rules In CS File, override Check to check rule.
  • 41. Custom FxCop Rule XML file is Embedded and contains rule detail: Remember filename must be same as passed to base constructor of BaseIntrospectionRule.
  • 42. Custom FxCop Rules To use custom rule, use CTRL+R or Project  Add Rules in FxCop. You can verify by clicking on rules tab:
  • 43. Summary Automating code standards can be very useful for getting rid of a lot of the “noise” in code reviews and allowing reviewers to concentrate on logic bugs. Automated code standards take the personal side out of enforcing style, safety, and performance. Custom rules can be used in FxCop and StyleCop to allow for your own rules.