Writing High Quality Code

35
Writing a high quality code

description

Jozef Sakalos at ModUX 2013 http://moduxcon.com

Transcript of Writing High Quality Code

Page 1: Writing High Quality Code

Writing a high quality code

Page 2: Writing High Quality Code

SakiJozef Sakáloš

• provide project consultancy and supervision

• on-line consultancy, code review, extensions

• deliver Sencha Ext and Touch Courses

Page 3: Writing High Quality Code

Contact

[email protected], [email protected]

• Facebook: jsakalos

• Skype: jsakalos

• Sencha Forums: jsakalos

Page 4: Writing High Quality Code

Code Quality

Page 5: Writing High Quality Code

Code must work, but

• fixing a bug introduces (many) new bugs

• a new developer cannot (easily) comprehend the code

• implementing changes/features is (extremely) difficult

• no, or not up-to-date documentation

• cross browser problems

Page 6: Writing High Quality Code

if(anyOfAbove === “yes”) {

codeQuality !== “high enough”;

}

Page 7: Writing High Quality Code

Quality

1. is degree of perfection of a product

2. is the standard of something as measured against other things of a similar kind

Page 8: Writing High Quality Code

High quality code is

1. pleasant to read and easy to grasp

2. abide by standards

3. modular

4. bug-free

Page 9: Writing High Quality Code

High quality code is

5. finished

6. clean

7. documented

8. working

Page 10: Writing High Quality Code

The code must be pleasant to read and

easy to grasp

Page 11: Writing High Quality Code

Write the code for another person

Page 12: Writing High Quality Code

Ugly code

Page 13: Writing High Quality Code

Ugliest code

Page 14: Writing High Quality Code

Beautiful code

Page 15: Writing High Quality Code

The code must abide by standards

Page 16: Writing High Quality Code

Two kind of standards

• JavaScript standards

• your coding conventions

Page 17: Writing High Quality Code

http://jslint.com

Page 18: Writing High Quality Code

Do you have a written Code Style Guide?

Page 19: Writing High Quality Code

Style Guide

• naming conventions

• spaces, indenting, commas

• how to write docs

• how to write file header footer

• ... and others

Page 20: Writing High Quality Code

Sencha recommends naming conventions in The Class System

guide

Page 21: Writing High Quality Code
Page 22: Writing High Quality Code

Code must be modular

Page 23: Writing High Quality Code

Example

Page 24: Writing High Quality Code

Task #1:Split the app into small modules.

Page 25: Writing High Quality Code

Rule #1: Define and then abide by API of

modules

Page 26: Writing High Quality Code

Corollaries

• controller must not know view internals

• view must fire custom events

• dynamic view must expose an API

• view must not access another view

Page 27: Writing High Quality Code

Don’t do it like this

Controller

ViewButton

ListenHide/Show

View

StoreRecord/Field

Page 28: Writing High Quality Code

...but like thisController

View

Button

View

Store

setVisible

handler

custom event

updateRecord

Page 30: Writing High Quality Code

The code must be bug-free

Page 31: Writing High Quality Code

The code must be finished

Finished === there is nothing more to be done on it

if(code.indexOf(“@todo”) !== -1) { code !== “finished”;}

Page 32: Writing High Quality Code

The code must be documented

see http://github.com/senchalabs/jsduck

Page 33: Writing High Quality Code

And, of course, the code must WORK!

Page 34: Writing High Quality Code

Questions?

Page 35: Writing High Quality Code

Happy quality coding!