33
Develop Best Practices The secret sauce for coding modern software Kosala Nuwan Perera @kosalanuwan

Developer Best Practices - The secret sauce for coding modern software

Embed Size (px)

Citation preview

Page 1: Developer Best Practices - The secret sauce for coding modern software

Develop Best PracticesThe secret sauce for coding modern software

Kosala Nuwan Perera@kosalanuwan

Page 2: Developer Best Practices - The secret sauce for coding modern software

Peter Falk told to Paul Reiser…

get some paperput it in a typewritertype FADE IN ... and keep typing.

Page 3: Developer Best Practices - The secret sauce for coding modern software

Problem, solution, and solve…

Biggest mistake of all time is jump straight to “Solve”.

Page 4: Developer Best Practices - The secret sauce for coding modern software

People really don’t get this!

Every feature is a commitment, a financial debt, even if its not used.

Page 5: Developer Best Practices - The secret sauce for coding modern software

Did you know that you arewoefully stuck in the Appland?Well, now you know

Page 6: Developer Best Practices - The secret sauce for coding modern software

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

Page 7: Developer Best Practices - The secret sauce for coding modern software

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

Page 8: Developer Best Practices - The secret sauce for coding modern software

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

Page 9: Developer Best Practices - The secret sauce for coding modern software

A computer program is the most complicated thing on

earth, second to a woman's brain. I just told this and she second it

Page 10: Developer Best Practices - The secret sauce for coding modern software

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.

Page 11: Developer Best Practices - The secret sauce for coding modern software

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.

Page 12: Developer Best Practices - The secret sauce for coding modern software

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.

Page 13: Developer Best Practices - The secret sauce for coding modern software

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.

Page 14: Developer Best Practices - The secret sauce for coding modern software

Why would you care? - Respond to change- Cost of change- Financial debt

Page 15: Developer Best Practices - The secret sauce for coding modern software

You have a limited number ofkeystrokes left in your hands before you “die”.

Page 16: Developer Best Practices - The secret sauce for coding modern software

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

Page 17: Developer Best Practices - The secret sauce for coding modern software

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

Page 18: Developer Best Practices - The secret sauce for coding modern software

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

Page 19: Developer Best Practices - The secret sauce for coding modern software

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

Page 20: Developer Best Practices - The secret sauce for coding modern software

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");

Page 21: Developer Best Practices - The secret sauce for coding modern software

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");

Page 22: Developer Best Practices - The secret sauce for coding modern software

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

Page 23: Developer Best Practices - The secret sauce for coding modern software

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; });}

Page 24: Developer Best Practices - The secret sauce for coding modern software

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; });}

Page 25: Developer Best Practices - The secret sauce for coding modern software

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; });}

Page 26: Developer Best Practices - The secret sauce for coding modern software

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;});

Page 27: Developer Best Practices - The secret sauce for coding modern software

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

Page 28: Developer Best Practices - The secret sauce for coding modern software

When you are matured with these

principles and patterns, it will become difficult for you to think without those.

Page 29: Developer Best Practices - The secret sauce for coding modern software

Where to begin?- Good Editor- Static analysis tools- Builds- Test automation tools- Source control- Continuous integration

Page 30: Developer Best Practices - The secret sauce for coding modern software

What other things that go with it? - Open source- Code kata- Pair programming- Design/Code reviews- Peer reviews

Page 31: Developer Best Practices - The secret sauce for coding modern software
Page 32: Developer Best Practices - The secret sauce for coding modern software

I swear to write software, more useful software and nothing but well-crafted

softwareso help me God!

- The Software Craftsmanship Oath

Page 33: Developer Best Practices - The secret sauce for coding modern software

Happy Coding

Kosala Nuwan Perera@kosalanuwan