Upload
kosala-nuwan-perera
View
567
Download
0
Embed Size (px)
Citation preview
Develop Best PracticesThe secret sauce for coding modern software
Kosala Nuwan Perera@kosalanuwan
Peter Falk told to Paul Reiser…
get some paperput it in a typewritertype FADE IN ... and keep typing.
Problem, solution, and solve…
Biggest mistake of all time is jump straight to “Solve”.
People really don’t get this!
Every feature is a commitment, a financial debt, even if its not used.
Did you know that you arewoefully stuck in the Appland?Well, now you know
Things that teams literally struggle- More granular tracing and auditing- User telemetry- Support for flexible DevOps- Modularization- Hybrid could opportunities- End-to-end message security- Powerful API for Public and Private- Asynchronous UX- Support for Multiplicity of clients- More efficient background processing
Things that teams literally struggle- More granular tracing and auditing- User telemetry- Support for flexible DevOps- Modularization- Hybrid could opportunities- End-to-end message security- Powerful API for Public and Private- Asynchronous UX- Support for Multiplicity of clients- More efficient background processing
Things that teams literally struggle- More granular tracing and auditing- User telemetry- Support for flexible DevOps- Modularization- Hybrid could opportunities- End-to-end message security- Powerful API for Public and Private- Asynchronous UX- Support for Multiplicity of clients- More efficient background processing
A computer program is the most complicated thing on
earth, second to a woman's brain. I just told this and she second it
How do you make things so complicated? - Rigid Small change causing cascade changes.
- Fragile Breaks in many places due to a single change.
- Immobility Cannot reuse in other projects due to risks/high efforts.
- Design debt Technical debt by taking shortcuts?
- Environment debt Technical debt by not running build, test, and other tasks.
- Needless complexity- Needless repetition- Opacity Cannot/hard to understand. Requires reengineering.
How do you make things so complicated? - Rigid Small change causing cascade changes.
- Fragile Breaks in many places due to a single change.
- Immobility Cannot reuse in other projects due to risks/high efforts.
- Design debt Technical debt by taking shortcuts?
- Environment debt Technical debt by not running build, test, and other tasks.
- Needless complexity- Needless repetition- Opacity Cannot/hard to understand. Requires reengineering.
How do you make things so complicated? - Rigid Small change causing cascade changes.
- Fragile Breaks in many places due to a single change.
- Immobility Cannot reuse in other projects due to risks/high efforts.
- Design debt Technical debt by taking shortcuts?
- Environment debt Technical debt by not running build, test, and other tasks.
- Needless complexity- Needless repetition- Opacity Cannot/hard to understand. Requires reengineering.
How do you make things so complicated? - Rigid Small change causing cascade changes.
- Fragile Breaks in many places due to a single change.
- Immobility Cannot reuse in other projects due to risks/high efforts.
- Design debt Technical debt by taking shortcuts?
- Environment debt Technical debt by not running build, test, and other tasks.
- Needless complexity- Needless repetition- Opacity Cannot/hard to understand. Requires reengineering.
Why would you care? - Respond to change- Cost of change- Financial debt
You have a limited number ofkeystrokes left in your hands before you “die”.
What can you try Today? - Naming conventions- Methods- Design principles- Dependency injection- Encapsulate conditionals- Polymorphism to If/Else or
Switch/Case- Exception over return codes
Read more at Crockford's guidelines for JavaScript and Google guidelines for JavaScript
Convention ExampleApp Root PascalCase ApprovelyFiles camelCased autoComplete.controller.j
sConstructors PascalCase WebRequestNamespaces camelCased but it’s unusual to
have two parts in one word though
Approvely.widgets
Functions camelCased toStringNon-constant variables including params
camelCased
Constants but ES5 has no constants
Capitalized or PascalCase CLICK_EVENT, Events.Click
Enums but ES5 has no enums
Capitalized or PascalCase. Singular for non-flags and plural for flags
HTTP_STATUS_CODE, HttpStatusCode, BindingFlags
What can you try Today? - Naming conventions- Methods- Design principles- Dependency injection- Encapsulate conditionals- Polymorphism to If/Else or
Switch/Case- Exception over return codes
What can you try Today? - Naming conventions- Methods- Design principles- Dependency injection- Encapsulate conditionals- Polymorphism to If/Else or
Switch/Case- Exception over return codes
class Sword{ public void Hit(string target) { ... }}
class Samurai{ private Sword sword; public Samurai() { sword = new Sword(); } public void Attack(string target) { sword.Hit(target); }}
Usage:Samurai warrior = new Samurai();warrior.Attack("the evildoers");
interface IWeapon{ void Hit(string target);}
class Sword : IWeapon{ public void Hit(string target) { ... }}
class Shuriken : IWeapon{ public void Hit(string target) { ... }}
class Samurai{ public Samurai(IWeapon w) { ... } public void Attack(string target) { ... }}
Usage:Shuriken weap1 = new Shuriken();Samurai warrior1 = new Samurai(weap1);warrior1.Attack("the evildoers");
Sword weap2 = new Sword();Samurai warrior2 = new Samurai(weap2);warrior2.Attack("the evildoers");
What can you try Today? - Naming conventions- Methods- Design principles- Dependency injection- Encapsulate conditionals- Polymorphism to If/Else or
Switch/Case- Exception over return codes
if (navigator.appName == "Microsoft Internet Explorer") { var flag = true; $(".js-right-arrow").click(function () { if (flag) { $(".js-slider-frame").animate({ left: "-130px" }, 1000); flag = false; } else { $(".js-slider-frame").animate({ left: "236px" }, 1000); flag = true; } return false; });} else { var flag = true; $(".js-right-arrow").click(function () { if (flag) { move(".js-slider-frame").set("left", -130).duration("1s").end(); flag = false; } else { move(".js-slider-frame").set("left", 236).duration("1s").end(); flag = true; } return false; });}
if (navigator.appName == "Microsoft Internet Explorer") { var flag = true; $(".js-right-arrow").click(function () { if (flag) { $(".js-slider-frame").animate({ left: "-130px" }, 1000); flag = false; } else { $(".js-slider-frame").animate({ left: "236px" }, 1000); flag = true; } return false; });} else { var flag = true; $(".js-right-arrow").click(function () { if (flag) { move(".js-slider-frame").set("left", -130).duration("1s").end(); flag = false; } else { move(".js-slider-frame").set("left", 236).duration("1s").end(); flag = true; } return false; });}
if (navigator.appName == "Microsoft Internet Explorer") { var flag = true; $(".js-right-arrow").click(function () { if (flag) { $(".js-slider-frame").animate({ left: "-130px" }, 1000); flag = false; } else { $(".js-slider-frame").animate({ left: "236px" }, 1000); flag = true; } return false; });} else { var flag = true; $(".js-right-arrow").click(function () { if (flag) { move(".js-slider-frame").set("left", -130).duration("1s").end(); flag = false; } else { move(".js-slider-frame").set("left", 236).duration("1s").end(); flag = true; } return false; });}
var flag = true, isIE = navigator.appName == "Microsoft Internet Explorer";
$(".js-right-arrow").click(function () { if (isIE) { $(".js-slider-frame").animate({ left: flag ? "-130px" : "236px" }, 1000); } else { move(".js-slider-frame").set("left", flag ? -130 : 236).duration("1s"); } flag = !flag; return false;});
What can you try Today? - Naming conventions- Methods- Design principles- Dependency injection- Encapsulate conditionals- Polymorphism to If/Else or
Switch/Case- Exception over return codes
When you are matured with these
principles and patterns, it will become difficult for you to think without those.
Where to begin?- Good Editor- Static analysis tools- Builds- Test automation tools- Source control- Continuous integration
What other things that go with it? - Open source- Code kata- Pair programming- Design/Code reviews- Peer reviews
I swear to write software, more useful software and nothing but well-crafted
softwareso help me God!
- The Software Craftsmanship Oath
Happy Coding
Kosala Nuwan Perera@kosalanuwan