Code Crime Scene pawel klimczyk
-
Upload
pawel-klimczyk -
Category
Software
-
view
45 -
download
1
Transcript of Code Crime Scene pawel klimczyk
![Page 1: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/1.jpg)
Code Crime Sceneversion 1.1
Paweł KlimczykGemotial 2016
![Page 2: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/2.jpg)
About me• Software engineer• Running Gemotial Software Studio • Co-organizer of WrocNET• Blog: http://blog.klimczyk.pl• Contact:• Twitter @pwlklm• Mail: [email protected]
![Page 3: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/3.jpg)
What is a crime scene? (1)
• Duplicate Code• Long Method• Comments• Long Parameter List• Large Class• Switch Statements• Parallel Inheritance
Hierarchies• Conditional Complexity• Combinitorial Explosion• Uncommunicative Name• Dead Code• Inconsistent Names• Temporary Field
![Page 4: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/4.jpg)
What is a crime scene? (2)• Alternative Classes with
Different Interfaces• Primitive ObsessionData
Class• Data Clumps• Refused Bequest• Inappropriate Intimacy• Indecent Exposure• Feature Envy
• Lazy Class• Message Chains• Middle Man• Divergent Change• Shotgun Surgery • Parallel Inheritance
Hierarchies• Incomplete Library Class• Solution Sprawl
![Page 5: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/5.jpg)
Crime scene samples – code level
![Page 6: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/6.jpg)
Crime scene samples – class level
![Page 7: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/7.jpg)
Crime scene samples – SOLID violation
![Page 8: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/8.jpg)
Crime scene samples – multiple test assertions
![Page 9: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/9.jpg)
SmartStore.NET introduction
https://github.com/smartstoreag/SmartStoreNET
SmartStore.NET is a free, open source, full-featured e-commerce solution for companies of any size. It is web standards compliant and incorporates the newest Microsoft web technology stack.
SmartStore.NET includes all essential features to create multilingual and multi-currency stores targeting desktop or mobile devices and enabling SEO optimized rich product catalogs with support for an unlimited number of products and categories, variants, bundles, datasheets, ESD, discounts, coupons and many more.
The state-of-the-art architecture of SmartStore.NET - with ASP.NET 4.5 + MVC 5, Entity Framework 6 and Domain Driven Design approach - makes it easy to extend, extremely flexible and essentially fun to work with ;-)
![Page 10: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/10.jpg)
SmartStore.NET production deployments
• http://2stonedshop.de/• http://indo-divers.de/• http://www.adr-shop.com/• http://www.mobilesat.co.uk/
trendspro.builtwith.com +500 online stores
![Page 11: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/11.jpg)
SmartStore.NET Screen (1)
![Page 12: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/12.jpg)
SmartStore.NET Screen (2)
![Page 13: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/13.jpg)
SmartStore.NET Screen (3)
![Page 14: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/14.jpg)
CodeBase Stats (June 2016)
![Page 15: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/15.jpg)
Finding the crime
How to find code crime in project ?
![Page 16: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/16.jpg)
Code crime scene (Ndepend)
• Dependency graph• Dependency matrix• LINQ queries• Code quality metrics (+custom)• More…
![Page 17: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/17.jpg)
NDepend – Project overview
![Page 18: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/18.jpg)
NDepend – Dependency diagram
![Page 19: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/19.jpg)
NDepend – Dependency matrix
![Page 20: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/20.jpg)
NDepend – Metricts
![Page 21: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/21.jpg)
NDepend – Cyclomatic complexity
![Page 22: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/22.jpg)
NDepend – SOLID violation (S)
![Page 23: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/23.jpg)
NDepend – SOLID violation (I)
![Page 24: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/24.jpg)
NDepend – Code coverage
![Page 25: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/25.jpg)
NDepend – Coupling
![Page 26: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/26.jpg)
NDepend – GC.Collect
![Page 27: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/27.jpg)
June – October 2016 compare
![Page 28: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/28.jpg)
Source control systems – measure behavior* 1a660f0 | (HEAD -> master, origin/master, origin/HEAD) dd (Fri May 13 17:03:40 2016)
[User1]* dfcd431 | screenshots attepmt 2 (Fri May 13 16:59:35 2016) [User1]* f29f63e | Apropriate screenshotting added (Fri May 13 16:54:46 2016) [User1]* 9203bdb | disabled native events for IE (Fri May 13 16:38:44 2016) [User1]* 45a6f12 | More setting for screenshots (Fri May 13 15:13:36 2016) [User1]* 690180c | IE only (Fri May 13 15:01:22 2016) [User1]* b687d21 | ScreenShots added (Fri May 13 15:00:51 2016) [User1]* f98748f | Added waiting for page fully loaded (Fri May 13 14:44:48 2016) [User1]* 2f15015 | Wait till page fully loaded for IE (Fri May 13 11:46:25 2016) [User1]* 46dafc1 | Enabled IE and Chrome (Fri May 13 11:23:21 2016) [User1]* 4faa96c | eliminated reposting form twice (Fri May 13 11:13:15 2016) [User1]* ea6e879 | Improved user profile edit tests (Fri May 13 10:53:38 2016) [User1]* 83f2f28 | removed retry for TestLauncher (Fri May 13 10:32:31 2016) [User1]* ff0e1ff | Changed retry count and added message text for asserts (Fri May 13 10:25:13 2016) [User1]* 2f27e2a | Temporary disabled most of the tests to (Fri May 13 10:08:46 2016) [User1]* b6dcb02 | FireFox enabled for tests (Thu May 12 14:02:29 2016) [User1]* 04c5596 | Better Handling of an alerts missing situations (Thu May 12 14:00:41 2016) [User1]
![Page 29: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/29.jpg)
Code maat - introduction
Features:• Analize GIT/SVN
history• Command line tool• Various analizers• CSV output• Open source
Work flow:• Git log….• Parse log with code maat• Generate graph from csv
![Page 30: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/30.jpg)
Code maat – sample
entity,n-authors,n-revssrc/Presentation/SmartStore.Web/Controllers/ShoppingCartController.cs,4,14src/Plugins/SmartStore.PayPal/Providers/PayPalExpressProvider.cs,4,6src/Libraries/SmartStore.Services/Catalog/Importer/ProductImporter.cs,3,48src/Presentation/SmartStore.Web/Administration/Controllers/ImportController.cs,3,38src/Libraries/SmartStore.Services/Catalog/Importer/CategoryImporter.cs,3,35src/Presentation/SmartStore.Web/Administration/Controllers/ExportController.cs,3,31src/Libraries/SmartStore.Data/Migrations/201601262000441_ImportFramework1.cs,3,30src/Libraries/SmartStore.Services/Customers/Importer/CustomerImporter.cs,3,29
java -jar code-maat-0.8.5-standalone.jar -l log_file.log -c git -a authors
![Page 31: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/31.jpg)
Code maat – hot filesentity n.authors n.revs
src/Libraries/SmartStore.Services/Catalog/Importer/ProductImporter.cs 3 48src/Presentation/SmartStore.Web/Administration/Controllers/ImportController.cs 3 38src/Libraries/SmartStore.Services/Catalog/Importer/CategoryImporter.cs 3 35src/Presentation/SmartStore.Web/Administration/Controllers/ExportController.cs 3 31src/Libraries/SmartStore.Data/Migrations/201601262000441_ImportFramework1.cs 3 30src/Libraries/SmartStore.Services/Customers/Importer/CustomerImporter.cs 3 29src/Libraries/SmartStore.Data/Migrations/201512151526290_ImportFramework.cs 2 28src/Libraries/SmartStore.Data/Migrations/201603121451066_ThirdPartyEmailHandOver.cs 2 21src/Plugins/SmartStore.PayPal/Localization/resources.en-us.xml 3 20src/Plugins/SmartStore.PayPal/Localization/resources.de-de.xml 3 20src/Plugins/SmartStore.PayPal/Services/PayPalService.cs 1 20src/Libraries/SmartStore.Services/DataExchange/Export/DataExporter.cs 3 19src/Libraries/SmartStore.Services/DataExchange/Import/DataImporter.cs 3 19src/Libraries/SmartStore.Services/DataExchange/Import/ImportRow.cs 3 18src/Presentation/SmartStore.Web/Administration/Views/Import/_ColumnMappings.cshtml 3 18src/Presentation/SmartStore.Web/Administration/Views/Import/_CreateOrUpdate.cshtml 1 18src/Presentation/SmartStore.Web/Administration/Controllers/ProductController.cs 2 16src/Presentation/SmartStore.Web/Administration/Models/DataExchange/ImportProfileModel.cs 2 16src/Presentation/SmartStore.Web/Controllers/CommonController.cs 2 15src/Presentation/SmartStore.Web/Scripts/smartstore.entityPicker.js 2 15
![Page 32: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/32.jpg)
Code maat – Author importance
Christian Oliff James Bright Marcus Gesing Michael Herzog Murat Cakir0
20000
40000
60000
80000
100000
120000
Authors importance 2016
added deleted diff
![Page 33: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/33.jpg)
Code maat – module ownership
Marcus Gesing
Murat Cakir
Michael Herzog
0% 10% 20% 30% 40% 50% 60% 70% 80% 90% 100%
5956 2449
226
6
10053
3747
32
7040
1604
0
90351
3662
src/Plugins/SmartStore.AmazonPay src/Plugins/SmartStore.Clickatell src/Plugins/SmartStore.DevToolssrc/Plugins/SmartStore.DiscountRules src/Plugins/SmartStore.FacebookAuth src/Plugins/SmartStore.GoogleAnalyticssrc/Plugins/SmartStore.GoogleMerchantCenter src/Plugins/SmartStore.OfflinePayment src/Plugins/SmartStore.Shippingsrc/Plugins/SmartStore.ShippingByWeight src/Plugins/SmartStore.Tax src/Plugins/SmartStore.WebApisrc/Libraries/SmartStore.Core src/Libraries/SmartStore.Data src/Libraries/SmartStore.Servicessrc/Libraries/SmartStore.Services/Catalog src/Libraries/SmartStore.Services/Common src/Libraries/SmartStore.Services/DataExchangesrc/Libraries/SmartStore.Services/Localization src/Libraries/SmartStore.Services/Messages src/Libraries/SmartStore.Services/Orderssrc/Libraries/SmartStore.Services/Payments src/Libraries/SmartStore.Services/Shipping src/Libraries/SmartStore.Services/Taskssrc/Libraries/SmartStore.Services/Customers src/Libraries/SmartStore.Services/Configuration src/Libraries/SmartStore.Core/Utilitiessrc/Libraries/SmartStore.Core/Logging src/Libraries/SmartStore.Core/Extensions src/Libraries/SmartStore.Core/Domainsrc/Tests/SmartStore.Services.Tests src/Tests/SmartStore.Web.MVC.Tests src/Presentation/SmartStore.Websrc/Presentation/SmartStore.Web.Framework
![Page 34: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/34.jpg)
Code maat – module ownership core
s r c/ P
r es e n ta
t i on / S
ma r tS
tor e
.We b
s r c/ L
ibr a
r i es / S
m a r tSto
r e.S
e r vi ce s
s r c/ L
ibr a
r i es / S
m a r tSto
r e.S
e r vi ce s /D
a taE x change
s r c/ L
ibr a
r ies / S
m a r tSto
r e.S
e r vi ce s / C
a tal o
g
s r c/ P
r es e n ta
t i on / S
ma r tS
tor e
.We b .Fr a
mewo r k
s r c/ L
i br a
r ies / S
m a r tSto
r e.S
e r vi ce s / C
u s tom e r s
s r c/ L
ibr a
r ies / S
m a r tSto
r e.C
o r e
s r c/ L
ibr a
r ies / S
m a r tSto
r e.D
a ta
s r c/ L
ibr a
r i es / S
m a r tSto
r e.S
e r vi ce s / T
a s ks
s r c/ P
l ug in
s / Sma r tS
tor e
.Sh ip
p ing
14266
100537040
1097
234
535699
2449
23
595690351
37471604
1138
723
472396
226
200
1443662 32 0 0 44 0 6 6 0 22Marcus Gesing Murat Cakir Michael Herzog
![Page 35: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/35.jpg)
Code maat – code relations
A B C
Functional codeTests code
![Page 36: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/36.jpg)
Other tools
•FxCop•StyleCop•R#
![Page 37: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/37.jpg)
Arguments for boss
Hard data provided by engineering tools speaks for
itself
![Page 38: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/38.jpg)
Key outcome
•Everything can be measured•Use suitable tools•Provide hard data•Programming triangle: correctness, readability, performance
![Page 39: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/39.jpg)
References
• NDepend http://www.ndepend.com/ • Code Maat https://github.com/adamtornhill/code-maat• Book https://pragprog.com/book/atcrime/your-code-as-a-
crime-scene• FxCop
https://msdn.microsoft.com/en-us/library/bb429476(v=vs.80).aspx• R# https://www.jetbrains.com/resharper/ (and other similar
VS plugins)
![Page 40: Code Crime Scene pawel klimczyk](https://reader035.fdocuments.us/reader035/viewer/2022062904/58752d6f1a28abe7728b4d75/html5/thumbnails/40.jpg)
Thank you!