Clean Application Development
Adam Culp @adamculp
https://joind.in/9284
Clean Application Development – About me

● About
●
●
●
●
●
●

2

me

PHP 5.3 Certified
Consultant at Zend Technologies
Or...
Clean Application Development – Iteration

● HUGE
●

fan of iteration

Skills require iteration to do well:
●

●

Training...
Clean Application Development – Learning

● Clean

application development cannot be taught quickly.

●

●

Leave the code...
Clean Application Development – Parts

● Parts

of clean application development.

●

●

Documentation

●

Source Control
...
Clean Application Development – Communication

Communication

6
Clean Application Development – Comm. Policy

● Team

Commication Policy:

●

●

Should be clear.

●

Should be expected.
...
Clean Application Development – Comm. Levels

● Communication
●

Levels

Instant (5 minutes to 1 hour)
●

●

●

Instant Me...
Clean Application Development – Behavior

● Desired

behaviour

●

●

Alert early.

●

Share information.

●

Be on time f...
Clean Application Development – Documentation

Documentation

10
Clean Application Development – Doc. Practices

● Document
●

EVERYTHING!

Write down everything.
●

You WILL want it late...
Clean Application Development – Doc. How

● How
●

to document.

Meeting notes, architecture decisions, design changes, bu...
Clean Application Development – Requirements

Requirements

13
Clean Application Development – What are they

● What

are requirements:

●

●

Business owners vision.

●

Expected behav...
Clean Application Development – How to create

● User

story format works well.

●

●

Create persona of target user.

●

...
Clean Application Development – Req. = Important

● Key
●

things about requirements:

Do not start coding without them.
●...
Clean Application Development – Time Estimating

Time Estimating

17
Clean Application Development – Wrong way!

● Guessing,

then multiplying by 2 or 3 is WRONG!

●

●

18

Sometimes accurat...
Clean Application Development – Why is it wrong?

● Guessing

is wrong because:

●

Still a guess.

●

Lacks requirements....
Clean Application Development – Now thats better!

●A

better way:

●

Gather requirements.

●

Plan application.
●

●

Ho...
Clean Application Development – Get paid!

● Freelancers,

ensure you get paid for the estimate!

●

It's hard work to pla...
Clean Application Development – Issue Tracking

Issue Tracking

22
Clean Application Development – Why track?

● Why

track issues/requests:

●

●

Ensures ideas are not lost.

●

User perc...
Clean Application Development – Tracking Tools

● Use
●

tools.

Many software packages available.
●

●

Should be simple....
Clean Application Development – Tracking Reports

● Useful
●

report examples.

Average time spent per ticket.
●

●

By se...
Clean Application Development – Time Management

Time Management

26
Clean Application Development – Key Elements

● Key
●

Track everything!
●

●

elements
Build habits.

Use applications.
●...
Clean Application Development – Service Level
Agreement

SLA – Service Level Agreement

28
Clean Application Development – Agreement

● Definition
●

and acceptance.

Determine acceptable response levels.
●

Get a...
Clean Application Development – Responsiveness

● Response

Times.

●

●

Urgent = someone can't work – 3 to 4 hour respon...
Clean Application Development – Response

● Response

Contents.

●

●

Acknowledge understanding. (re-state problem)

●

P...
Clean Application Development – Dev Tools

Dev Tools

32
Clean Application Development – Using an IDE

● Modern

IDE

●

Pick one, learn it WELL!

●

Features:
●

●

Code completi...
Clean Application Development – Basic Editor

● Basic

Editor

●

Pick one, learn it WELL!

●

Features:
●

●

Able to han...
Clean Application Development – Vi / Vim

● Vim

Editor

●

●

Exists on most Linux and Unix servers.

●

35

Must know at...
Clean Application Development – PHPCloud

● phpcloud.com
●

●

Development environment hosting (not production)

●

Deploy...
Clean Application Development – Vagrant

● Vagrant

for virtualized development

●

Vagrantup.com

●

Vagrantbox.es

●

Co...
Clean Application Development – Vagrant
Automated
● Vagrant

automated

●

●

38

http://puphpet.com For Puppet manifests....
Clean Application Development – Using frameworks

● Frameworks

help keep things in line

●

Using a framework helps keep ...
Clean Application Development – Frameworks

● Dos
●

●

Dabble with others secondary.

●

Get certified.

●

●

Pick one, ...
Clean Application Development – Debugging Proxy

● Debugging

Proxy

●

●

Exists on most Linux and Unix servers.

●

41

...
Clean Application Development – Zend Server

● Zend

Server

●

●

Debugging and profiling.

●

Code tracing.

●

Monitori...
Clean Application Development – PHP QA Tools

● PHP
●

QA tools

http://phpqatools.org
●

●

PHP CPD (copy/paste detector)...
Clean Application Development – XHProf

● XHProf
●

●

Hierarchical profiler.

●

44

Pecl package.

'How to' on my blog. ...
Clean Application Development – XDebug

● XDebug
●

●

Can be installed via Pecl, or using phpize or manual compiling.

●
...
Clean Application Development – Composer

● getcomposer.org
●

●

Not a package manager.

●

It is a PHP application in co...
Clean Application Development – Composer Usage

● Using

Composer

●

●

Issue commands to the composer.phar.

●

47

Used...
Clean Application Development – Packagist

● Packagist.org
●

Composer package repository.

●

Archivist of PHP libraries....
Clean Application Development – Packagist Search

● Just

49

search!
Clean Application Development – Database

Datebase

50
Clean Application Development – Data Conventions

● Database
●

should be clean as well

Stick to conventions. (defined by...
Clean Application Development – Right Database

● Choose
●

the right database for the job

Many to choose from:
●

●

Mon...
Clean Application Development – Source Control

Source Control

53
Clean Application Development – Baby steps

● Learning
●

to code, like walking, takes time

We fall down...alot!
●

●

Sc...
Clean Application Development – Pick-up

● Source
●

Control

Helps us get back up!
●

●

Blame.

●

Rollback.

●

Audit t...
Clean Application Development – Characteristics

● Key

characteristics of source control

●

●

Keep history.

●

Be avai...
Clean Application Development – Subversion

● Subversion

style SCM workflow

Shared Repository

Developer

57

Developer
...
Clean Application Development – Integration Mgr.

● Integration

manager SCM workflow

Blessed
Repository

Integration
Man...
Clean Application Development –
Dictator/Lieutenant
● Dictator

and lieutenants SCM workflow
Blessed
Repository

Dictator
...
Clean Application Development – Workflow

Workflow

60
Clean Application Development – Agile

● Project

Iteration

●

Average sprint is 2 weeks.

●

At the end of the sprint EV...
Clean Application Development – Team Workflow

● Team

development workflow

●

Developer is assigned task.

●

Checks out...
Clean Application Development – Team Workflow

● Team
●

development workflow

After coding is completed developer tests c...
Clean Application Development – Team Workflow

● Team
●

development workflow

When all tests pass, developer pushes code ...
Clean Application Development – Team Workflow

● Team

QA workflow

●

QA testing in development branch.

●

If bugs, retu...
Clean Application Development – Team Workflow

● Team

deployment manager workflow

●

Regression test in staging branch.
...
Clean Application Development – Team Workflow

● Team

deployment manager workflow

●

If pass, merge to master branch.

●...
Clean Application Development – Team Workflow

● Single

developer workflow

●

Pretty similar, but no staging.

●

Still ...
Clean Application Development – The Code

The Code

69
Clean Application Development – Resources

● Resource

on clean coding practices.

Clean Code
By Robert C. Martin
70
Clean Application Development – Drivers

● Disasters

happen, resulting in bad code...

●

●

Short deadlines.

●

Lazines...
Clean Application Development – Defend the code

● It

is our responsibility to say “NO“ and provide good code

●

●

Our ...
Clean Application Development – Result of bad
code
● We

have all seen bad code

●

●

Causes bugs.

●

Excessive debuggin...
Clean Application Development – Dirty Code
Results

74
Clean Application Development – Dirty Code
Results

Time Waste

75
Clean Application Development – Dirty Code
Results

Time Waste

76
Clean Application Development – Dirty Code
Results

Time Waste

77

Creates Bugs
Clean Application Development – Dirty Code
Results

Time Waste

78

Creates Bugs
Clean Application Development – Dirty Code
Results

Time Waste

79

Creates Bugs

Debugging
Clean Application Development – Dirty Code
Results

Time Waste

80

Creates Bugs

Debugging
Clean Application Development – Dirty Code
Results

Time Waste

Procrastination
81

Creates Bugs

Debugging
Clean Application Development – Dirty Code
Results

Time Waste

Procrastination
82

Creates Bugs

Debugging
Clean Application Development – Dirty Code
Results

Time Waste

Procrastination
83

Creates Bugs

Late Projects

Debugging
Clean Application Development – Dirty Code
Results

Time Waste

Procrastination
84

Creates Bugs

Late Projects

Debugging
Clean Application Development – Dirty Code
Results

Time Waste

Debugging

Procrastination
85

Creates Bugs

Late Projects...
Clean Application Development – How we cause it?

● Bad

code starts innocently

● Hire

a new professional/developer

●

...
Clean Application Development – The aftermath

● How

do we handle this?

●

●

Hide.

●

Become defensive.

●

Blame othe...
Clean Application Development – You are judged

● Others

judge us on our code

●

We are @authors.

●

Others read our co...
Clean Application Development – Coding standards

● Coding

Standards save time

●

Choosing a standard gives direction on...
Clean Application Development – Clear names

● Names
●

should be clear

Functions and variables should tell a story.

Bad...
Clean Application Development – No confusion

● Shy
●

away from variations of the same name

To ensure names are differen...
Clean Application Development – Bad characters

● Certain

characters are hard to understand

Bad
Lower case L
Uppercase O...
Clean Application Development – Name grammar

● Use

technical names to help developers, since developers will be
reading ...
Clean Application Development – Common sense

● With

all of these problems, clean code makes sense

●

●

On-boarding of ...
Clean Application Development – Rewrite problems

● The
●

problem with a rewrite

Reasons NOT to rewrite:
●

Budget.

●

...
Clean Application Development – Clean code

● More
●

on Clean Code

Functions are pretty much what we expected. No surpri...
Clean Application Development – Code comments

● Comments

can also be a bad “smell“

●

●

97

Comments are often used to...
Clean Application Development – Design Patterns

● Standard

and quick solutions to common coding problems

●

Provide sta...
Clean Application Development – Peer code reviews

● Peer

code review great learning tool

●

●

Fresh set of eyes.

●

9...
Clean Application Development – Refactoring

Refactoring

100
Clean Application Development – Resources

● Great

refactoring resource.

Refactoring
By Martin Fowler
Companion PHP code...
Clean Application Development – Definition

● What
●

is refactoring?

...process of changing a computer program's source ...
Clean Application Development – Two Hats

● Two

hats

●

●

Refactoring hat

●

103

Adding functionality hat

We add fun...
Clean Application Development – Why Refactory

● Why

refactor?

●

●

Poor design.

●

Preserve design.

●

Reduce duplic...
Clean Application Development – Code Smells

● Code
●

smells

What are smells?
●

●

Not conclusive.

●

105

Indications...
Clean Application Development – Smells of bad
code
● Smells

list

●

Duplicate code.

●

Large class.

●

Long methods (f...
Clean Application Development – Smells of bad
code
● Smells

list (cont'd.)

●

●

Lazy class – class not doing much, just...
Clean Application Development – Code sniffer

● Let

PHP CodeSniffer detect bad smells

●

●

Run during commits in versio...
Clean Application Development – When to refactor

● When

to refactor?

●

No special time, do in short bursts.

●

Don't ...
Clean Application Development – How to start

● First
●

steps

Use source control (Git, SVN, etc.)
●

●

●

Record each s...
Clean Application Development – Tests

● Tests
●

Cannot properly refactor without tests.
●

●

and refactoring

To gauge ...
Clean Application Development – Refactoring

112
Clean Application Development – Refactoring

Not if Broken

113
Clean Application Development – Refactoring

Not if Broken

114
Clean Application Development – Refactoring

Not if Broken

115

Create Tests
Clean Application Development – Refactoring

Not if Broken

116

Create Tests
Clean Application Development – Refactoring

Not if Broken

117

Create Tests

Detect Smells
Clean Application Development – Refactoring

Not if Broken

118

Create Tests

Detect Smells
Clean Application Development – Refactoring

Not if Broken

Different Hats
119

Create Tests

Detect Smells
Clean Application Development – Refactoring

Not if Broken

Different Hats
120

Create Tests

Detect Smells
Clean Application Development – Refactoring

Not if Broken

Different Hats
121

Create Tests

Improve Code

Detect Smells
Clean Application Development – Refactoring

Not if Broken

Different Hats
122

Create Tests

Improve Code

Detect Smells
Clean Application Development – Refactoring

Not if Broken

Detect Smells

Different Hats
123

Create Tests

Improve Code
...
Clean Application Development – Architecture

Architecture

124
Clean Application Development – Clear architecture

● We

can tell pretty simply this “looks“ like a library. (bookshelves...
Clean Application Development – Simple overview

● With

cars driving through and shelves on the sides we can guess
this i...
Clean Application Development – Obvious purpose

● These

127

are pretty obvious without any explanation.
Clean Application Development – MVC
architecture?
● This

128

would take a bit more digging to figure out.
Clean Application Development – Future challenges

● Shouldn't

“Architecure“ be
cleaner/clearer/simpler?

129
Clean Application Development – Testing

Testing

130
Clean Application Development – Selenium IDE

● Selenium

IDE

●

●

Automates human steps.

●

131

Integrated into brows...
Clean Application Development – Behavior Driven

● Behat
●

●

For PHP 5.3 and 5.4.

●

132

Open source.

Human-readable ...
Clean Application Development – Unit Testing

● Unit

testing (our parachute) ensures we write clean code

●

●

Function ...
Clean Application Development – TDD

● Unit
●

134

testing is important, so should be done first

Write failing tests fir...
Clean Application Development – Tests = QA

● If

tests are trusted, they become QA process

●

If tests are good, QA find...
Clean Application Development – QA and unit tests

● Put

QA at the begining of the process, instead of the end

●

QA has...
Clean Application Development – Continuous Int.

Continuous Integration

137
Clean Application Development – Phing

● PHing

Is Not GNU make.

●

Based on Apache Ant.

●

Uses simple XML build files ...
Clean Application Development – Zend Deployment

● Zend

Deployment

●

●

Create ZPK of project in Zend Studio.

●

Uploa...
Clean Application Development – Jenkins

● Jenkins
●

●

Built with Java.

●

789 plugins.

●

Runs PHPUnit.

●

Runs Code...
Clean Application Development – Jenkins Results

● Jenkins

141

Results
Clean Application Development – Professional

Be Professional Grade!

142
Clean Application Development – Human resources

● Our
●

●

Professionals are trusted to do a good job, give good estimat...
Clean Application Development – Close

● Clean

application development is:

●

●

Clear architecture.

●

Coding standard...
● Resources
●

Adam Culp @adamculp and http://geekyboy.com

●

Book: “Clean Code“ by Robert C. Martin

●

Book: “Refactori...
Upcoming SlideShare
Loading in...5
×

Clean application development tutorial

5,611

Published on

No matter what level of development we are at in our careers we all face a daily battle to write good code for ourselves and others, deliver finished applications fast to satisfy business, and ensure everything is tested to prevent end-user fails.

In this session we will discuss what clean application development is, and how it can help us win those battles. It will provide practical and usable examples and tools to take with you, integrate into your workflow, and continue to grow into good habits.

(Topics: Version control, refactoring, coding standards, frameworks, architecture, automation, time management, and more.)

Published in: Technology, Business
1 Comment
15 Likes
Statistics
Notes
  • He, Unfortunatuly I havent been able to make it to the conference but I went through your slides and I must say that I like it very much. A lot of usefull and important information put together.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
5,611
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
12
Comments
1
Likes
15
Embeds 0
No embeds

No notes for slide

Clean application development tutorial

  1. 1. Clean Application Development Adam Culp @adamculp https://joind.in/9284
  2. 2. Clean Application Development – About me ● About ● ● ● ● ● ● 2 me PHP 5.3 Certified Consultant at Zend Technologies Organizer of SoFloPHP (South Florida) Organizer of SunshinePHP (Miami) Long distance (ultramarathon) runner Judo black belt instructor
  3. 3. Clean Application Development – Iteration ● HUGE ● fan of iteration Skills require iteration to do well: ● ● Training to run. ● Evading project managers. ● Writing clean code. ● Refactoring. ● 3 Learning to walk. Testing.
  4. 4. Clean Application Development – Learning ● Clean application development cannot be taught quickly. ● ● Leave the code better than you found it. ● Always watch for new techniques. ● Want to do better. ● No “silver bullet“. ● 4 Practice, Practice, Practice. Oh, and practice.
  5. 5. Clean Application Development – Parts ● Parts of clean application development. ● ● Documentation ● Source Control ● Workflow ● Time Estimation ● Requirements Gathering ● Issue Tracking ● Time Management ● Dev Tools ● Databases ● Code ● Refactoring ● Testing ● 5 Communication Continuous Integration
  6. 6. Clean Application Development – Communication Communication 6
  7. 7. Clean Application Development – Comm. Policy ● Team Commication Policy: ● ● Should be clear. ● Should be expected. ● 7 Should be agreed upon by team. Should be enforced.
  8. 8. Clean Application Development – Comm. Levels ● Communication ● Levels Instant (5 minutes to 1 hour) ● ● ● Instant Messages (Skype, AOL) Chat (IRC) Intermediate (2 to 4 hours) ● ● ● Phone Call, text message Voicemail Slow (6 to 8 hours) ● ● ● Email Issue Tracking Casual (days) ● ● 8 Forum Meeting
  9. 9. Clean Application Development – Behavior ● Desired behaviour ● ● Alert early. ● Share information. ● Be on time for meetings. ● ● Openly discuss problems. Attention! Bad behaviour ● ● Hoarding info. ● Bringing attitude to meetings. ● 9 Hiding. Interrupting others.
  10. 10. Clean Application Development – Documentation Documentation 10
  11. 11. Clean Application Development – Doc. Practices ● Document ● EVERYTHING! Write down everything. ● You WILL want it later. ● ● Architecture decisions. ● Changes in design. ● Business logic. ● 11 Meeting notes. Everything!
  12. 12. Clean Application Development – Doc. How ● How ● to document. Meeting notes, architecture decisions, design changes, business logic. ● Keep a notebook. Never throw pages away again. ● ● ● Composition Book. Evernote/Google keep. In code. ● Class Docblocks: business logic description. ● ● Ticket System. ● Source control comments. ● PHP Documentor. ● White papers. ● 12 Wiki. Everywhere!
  13. 13. Clean Application Development – Requirements Requirements 13
  14. 14. Clean Application Development – What are they ● What are requirements: ● ● Business owners vision. ● Expected behaviour of application. ● Application reaction to business logic. ● 14 End-user dreams. Specific needs.
  15. 15. Clean Application Development – How to create ● User story format works well. ● ● Create persona of target user. ● Create goals of what is desired. ● Create benefit that goals help obtain. ● Now create a story to make it real. ● 15 Create roles of potential users. Insist on specificity!
  16. 16. Clean Application Development – Req. = Important ● Key ● things about requirements: Do not start coding without them. ● ● ● Hold their hand to get them started. Even if the project is your own. Use a tool to organize them. ● ● Get sign-off from stakeholder. ● 16 Reqharbor.com No sign-off = scope creep later
  17. 17. Clean Application Development – Time Estimating Time Estimating 17
  18. 18. Clean Application Development – Wrong way! ● Guessing, then multiplying by 2 or 3 is WRONG! ● ● 18 Sometimes accurate, but still a guess. What if guess is wrong?
  19. 19. Clean Application Development – Why is it wrong? ● Guessing is wrong because: ● Still a guess. ● Lacks requirements. ● If requirements are completed, why guess? ● Welcomes scope creep. ● Application lacks design. ● Causes bad practices: ● ● ● Shortcut tests. Increases code smells. Prevents honest answers later. ● 19 How's it going????
  20. 20. Clean Application Development – Now thats better! ●A better way: ● Gather requirements. ● Plan application. ● ● How many actions in each * average hours per. ● ● How many controllers * average hours per. How many models/entities * average hours per. Include meetings. ● 15 minutes per day (daily scrum) ● 2 hours per sprint for planning. ● 1 hour per sprint for show. ● ● Include time for DBA, graphic designer. ● 20 Plan resources/developers and QA/QC testers, and tests for each action. Include time for estimating each sprint.
  21. 21. Clean Application Development – Get paid! ● Freelancers, ensure you get paid for the estimate! ● It's hard work to plan an application. ● It takes time: (time == money) ● ● Gathering requirements > 40 hours. ● Wireframes, images > 40 hours. ● Creating an accurate estimate. ● Documenting technologies. ● 21 Interview > 5 hours. Etc.
  22. 22. Clean Application Development – Issue Tracking Issue Tracking 22
  23. 23. Clean Application Development – Why track? ● Why track issues/requests: ● ● Ensures ideas are not lost. ● User perception highlighted. ● Bugs not forgotten. ● Ownership for users. ● Auditable. ● Scheduling. ● 23 Helps create documentation later. Track effort.
  24. 24. Clean Application Development – Tracking Tools ● Use ● tools. Many software packages available. ● ● Should be simple. ● Should compliment workflow. ● Connected with source control. ● Must enhance communication. ● 24 Agreed upon by team. Customizable. (not just appearance)
  25. 25. Clean Application Development – Tracking Reports ● Useful ● report examples. Average time spent per ticket. ● ● By severity. ● ● By category. By developer. % Deadlines met on time. (SLA) ● ● ● Total. By Developer. Avg. # failed fixes by QA. ● ● Count per category assigned. ● 25 By developer. By Developer.
  26. 26. Clean Application Development – Time Management Time Management 26
  27. 27. Clean Application Development – Key Elements ● Key ● Track everything! ● ● elements Build habits. Use applications. ● ● ● Hamster. Freshbooks. Keep it simple. ● Easy input. ● Basic reports. ● 27 Future estimates.
  28. 28. Clean Application Development – Service Level Agreement SLA – Service Level Agreement 28
  29. 29. Clean Application Development – Agreement ● Definition ● and acceptance. Determine acceptable response levels. ● Get agreement from stakeholders. ● ● Based on ticket severity. ● 29 Make them public. Must manage user perception.
  30. 30. Clean Application Development – Responsiveness ● Response Times. ● ● Urgent = someone can't work – 3 to 4 hour response ● High = customer inconvenienced – 8 hour or 1 day response ● Medium = employee annoyance – 2 days to 1 week response ● Low = nice to have – 1 to 2 week response ● 30 Blocker = business stopped – 1 hour response Wish = no response, but perhaps a friendly thank you email
  31. 31. Clean Application Development – Response ● Response Contents. ● ● Acknowledge understanding. (re-state problem) ● Provide “real“ time estimate of work. ● Define when work will start. (for higher priority items) ● 31 Thank user. Give idea of when work will start for low priority items.
  32. 32. Clean Application Development – Dev Tools Dev Tools 32
  33. 33. Clean Application Development – Using an IDE ● Modern IDE ● Pick one, learn it WELL! ● Features: ● ● Code completion. ● Source control integration. ● Issue tracking integration. ● DB management. ● Deployment. ● Testing. ● Console. ● 33 Syntax highlighting. Debugging.
  34. 34. Clean Application Development – Basic Editor ● Basic Editor ● Pick one, learn it WELL! ● Features: ● ● Able to handle large files. ● Opens fast. ● Saves quickly. ● 34 Syntax highlighting. Closes error free.
  35. 35. Clean Application Development – Vi / Vim ● Vim Editor ● ● Exists on most Linux and Unix servers. ● 35 Must know at least basic usage. Don't fear it.
  36. 36. Clean Application Development – PHPCloud ● phpcloud.com ● ● Development environment hosting (not production) ● Deploy to any cloud provider when ready to go LIVE! ● Zend Server. ● Zend Framework. ● Zend Debugger. ● 36 Git hosting. FREE!!!
  37. 37. Clean Application Development – Vagrant ● Vagrant for virtualized development ● Vagrantup.com ● Vagrantbox.es ● Command line tool. ● Uses: ● VirtualBox ● VMWare ● AWS ● Others... ● ● 37 Can use Puppet or Chef. Free and open source.
  38. 38. Clean Application Development – Vagrant Automated ● Vagrant automated ● ● 38 http://puphpet.com For Puppet manifests. http://rove.io For Chef recipes.
  39. 39. Clean Application Development – Using frameworks ● Frameworks help keep things in line ● Using a framework helps keep your code light, simpler. ● Heavy lifting and complexity within core. ● Most modern frameworks are MVC ● ● 39 View – GUI, Presentation ● ● Model – Business logic, Data Controller – Directs, Commands Generally have a naming convention and coding standard.
  40. 40. Clean Application Development – Frameworks ● Dos ● ● Dabble with others secondary. ● Get certified. ● ● Pick one, and learn it best. Create your own. Don'ts ● ● Edit framework core. ● Rebuild functionality. ● 40 Roll your own for large projects. Fall behind. (learn more)
  41. 41. Clean Application Development – Debugging Proxy ● Debugging Proxy ● ● Exists on most Linux and Unix servers. ● 41 Must know at least basic usage. Don't fear them.
  42. 42. Clean Application Development – Zend Server ● Zend Server ● ● Debugging and profiling. ● Code tracing. ● Monitoring. ● Bytecode caching. ● Session clustering. ● Page caching. ● On many cloud providers. ● Available at ServerGrove! ● 42 Deployment and rollback. IDE Integration.
  43. 43. Clean Application Development – PHP QA Tools ● PHP ● QA tools http://phpqatools.org ● ● PHP CPD (copy/paste detector) ● PHP Loc (lines of code) ● PHP MD (mess detector) ● PHP Codesniffer ● PHP Depend ● Jenkins PHP ● 43 PHP Unit More....
  44. 44. Clean Application Development – XHProf ● XHProf ● ● Hierarchical profiler. ● 44 Pecl package. 'How to' on my blog. (http://geekyboy.com)
  45. 45. Clean Application Development – XDebug ● XDebug ● ● Can be installed via Pecl, or using phpize or manual compiling. ● Allows debugging of PHP code. ● 45 An extension for PHP. IDE integration.
  46. 46. Clean Application Development – Composer ● getcomposer.org ● ● Not a package manager. ● It is a PHP application in composer.phar. ● 46 Dependency manager for PHP. Configured by using composer.json file.
  47. 47. Clean Application Development – Composer Usage ● Using Composer ● ● Issue commands to the composer.phar. ● 47 Used via command line. Packages get downloaded, WITH dependencies.
  48. 48. Clean Application Development – Packagist ● Packagist.org ● Composer package repository. ● Archivist of PHP libraries. ● 14,505 packages listed! ● 47,316 versions. ● 52,034,902 packages installed since 2012-04-13. ● How to use: ● ● Copy/paste the required line to composer.json. ● 48 Search for desired package. Run 'composer install' (or update).
  49. 49. Clean Application Development – Packagist Search ● Just 49 search!
  50. 50. Clean Application Development – Database Datebase 50
  51. 51. Clean Application Development – Data Conventions ● Database ● should be clean as well Stick to conventions. (defined by project) ● ● ID field ● Foreign field names {table}_id ● 51 Table names Timestamps for created/modified
  52. 52. Clean Application Development – Right Database ● Choose ● the right database for the job Many to choose from: ● ● MongoDB ● MSSQL ● DB2 ● Postgres ● Oracle ● SQLite ● 52 MySQL Text file
  53. 53. Clean Application Development – Source Control Source Control 53
  54. 54. Clean Application Development – Baby steps ● Learning ● to code, like walking, takes time We fall down...alot! ● ● Scope changes. ● Bugs. ● 54 Learning new methods. Refactoring.
  55. 55. Clean Application Development – Pick-up ● Source ● Control Helps us get back up! ● ● Blame. ● Rollback. ● Audit trail. ● 55 Diff. Link back to tickets.
  56. 56. Clean Application Development – Characteristics ● Key characteristics of source control ● ● Keep history. ● Be available. ● Easy to use. ● Secure. ● Allow multi-user. ● 56 Track changes. Able to merge changes.
  57. 57. Clean Application Development – Subversion ● Subversion style SCM workflow Shared Repository Developer 57 Developer Developer
  58. 58. Clean Application Development – Integration Mgr. ● Integration manager SCM workflow Blessed Repository Integration Manager 58 Developer Public Developer Public Developer Private Developer Private
  59. 59. Clean Application Development – Dictator/Lieutenant ● Dictator and lieutenants SCM workflow Blessed Repository Dictator Lieutenant Lieutenant Developer 59 Developer Developer Developer
  60. 60. Clean Application Development – Workflow Workflow 60
  61. 61. Clean Application Development – Agile ● Project Iteration ● Average sprint is 2 weeks. ● At the end of the sprint EVERYTHING is “done“. ● ● ● Development. ● ● Tests. Documentation. Velocity charts are very important, put them up! Burn down chart must go on the wall to let everyone know just how “screwed“ they really are. ● ● Allows business to recover. ● 61 Agile = hope killer. *joking* Lack of charts prevent graceful recovery.
  62. 62. Clean Application Development – Team Workflow ● Team development workflow ● Developer is assigned task. ● Checks out code to private development branch. ● Developer adds functionality. Project assigned 62 Checkout dev. to private {user}-development Coding
  63. 63. Clean Application Development – Team Workflow ● Team ● development workflow After coding is completed developer tests code. Project assigned 63 Checkout dev. to private {user}-development Coding Testing
  64. 64. Clean Application Development – Team Workflow ● Team ● development workflow When all tests pass, developer pushes code to public development branch. Project assigned Tests pass 64 Checkout dev. to private {user}-development Merge changes to development Coding Testing
  65. 65. Clean Application Development – Team Workflow ● Team QA workflow ● QA testing in development branch. ● If bugs, return to developer. ● If pass, merge with staging branch. Return to developer flow no Testing assigned 65 Testing from development Test passed yes Merge to staging
  66. 66. Clean Application Development – Team Workflow ● Team deployment manager workflow ● Regression test in staging branch. ● If failed, create temp branch for bug fix. Bug fixed Temp branch created no Deploy assigned 66 Regression testing In staging Test passed
  67. 67. Clean Application Development – Team Workflow ● Team deployment manager workflow ● If pass, merge to master branch. ● Create tag for new version. Bug fixed Temp branch created no Deploy assigned Regression testing In staging Test passed yes Tag created 67 Merge to master
  68. 68. Clean Application Development – Team Workflow ● Single developer workflow ● Pretty similar, but no staging. ● Still use a private development branch. 68 {user}-development Test passed Merge to development Tag created Project assigned Merge to master Regression test
  69. 69. Clean Application Development – The Code The Code 69
  70. 70. Clean Application Development – Resources ● Resource on clean coding practices. Clean Code By Robert C. Martin 70
  71. 71. Clean Application Development – Drivers ● Disasters happen, resulting in bad code... ● ● Short deadlines. ● Laziness. ● Lack of “how-to“. ● Coupled application. ● Impatient boss. ● Bored of same ol' app. ● Come back and clean later. ● We are the cause! ● 71 Writing dirty code is easy. Why did we write it!?!
  72. 72. Clean Application Development – Defend the code ● It is our responsibility to say “NO“ and provide good code ● ● Our job = defend the code. ● 72 Managers job = defend schedule and features. Managers cave to realistic reasons and explanations.
  73. 73. Clean Application Development – Result of bad code ● We have all seen bad code ● ● Causes bugs. ● Excessive debugging ● Causes procrastination. ● Missed deadlines. ● Technical debt. ● Financial losses. ● Company killer. ● 73 Time waster. I didn't write it!!!
  74. 74. Clean Application Development – Dirty Code Results 74
  75. 75. Clean Application Development – Dirty Code Results Time Waste 75
  76. 76. Clean Application Development – Dirty Code Results Time Waste 76
  77. 77. Clean Application Development – Dirty Code Results Time Waste 77 Creates Bugs
  78. 78. Clean Application Development – Dirty Code Results Time Waste 78 Creates Bugs
  79. 79. Clean Application Development – Dirty Code Results Time Waste 79 Creates Bugs Debugging
  80. 80. Clean Application Development – Dirty Code Results Time Waste 80 Creates Bugs Debugging
  81. 81. Clean Application Development – Dirty Code Results Time Waste Procrastination 81 Creates Bugs Debugging
  82. 82. Clean Application Development – Dirty Code Results Time Waste Procrastination 82 Creates Bugs Debugging
  83. 83. Clean Application Development – Dirty Code Results Time Waste Procrastination 83 Creates Bugs Late Projects Debugging
  84. 84. Clean Application Development – Dirty Code Results Time Waste Procrastination 84 Creates Bugs Late Projects Debugging
  85. 85. Clean Application Development – Dirty Code Results Time Waste Debugging Procrastination 85 Creates Bugs Late Projects $$$ Loss
  86. 86. Clean Application Development – How we cause it? ● Bad code starts innocently ● Hire a new professional/developer ● Clean slate, no expectations. ● Start ● a new project Initial code output is quick, setting expectation. ● ● Bug introduction increases. ● Over-coupled system. ● Complexity increases. ● Completion time...unknown. ● 86 Slows down over time. Domino effect.
  87. 87. Clean Application Development – The aftermath ● How do we handle this? ● ● Hide. ● Become defensive. ● Blame others/requirements. ● Add more developers to increase productivity. ● New developers break the system, because they don't “know“ it. ● Change jobs. ● 87 Severely padded estimates. Rewrite!
  88. 88. Clean Application Development – You are judged ● Others judge us on our code ● We are @authors. ● Others read our code regularly. ● And they talk about it! ● How developers talk about us = “CRED“. And they talk about it! 88
  89. 89. Clean Application Development – Coding standards ● Coding Standards save time ● Choosing a standard gives direction on best practices. ● PHP Framework Interoperability Group (https://www.php-fig.org). ● PSR-0 Autoloader. ● PSR-1 Basic Coding Standard. ● PSR-2 Coding Style Guide. ● PSR-3 Logging ● ● Zend Framework (helped with PSR). ● Symfony2 (helped with PSR). ● CakePHP (helped with PSR. ● Lithium (helped with PSR). ● 89 PEAR (helped with PSR). Many more (helped with PSR).
  90. 90. Clean Application Development – Clear names ● Names ● should be clear Functions and variables should tell a story. Bad $elapsed; $createdDays; $modifiedDays; $age; 90 Good $elapsedTimeInDays; $daysSinceCreation; $daysSinceModified; $fileAgeInDays;
  91. 91. Clean Application Development – No confusion ● Shy ● away from variations of the same name To ensure names are different enough to portray difference. What is the difference between these? $product $productInfo $productData $productDescription 91
  92. 92. Clean Application Development – Bad characters ● Certain characters are hard to understand Bad Lower case L Uppercase O (oh) Uppercase I (eye) 92
  93. 93. Clean Application Development – Name grammar ● Use technical names to help developers, since developers will be reading the code. Leave non-technical terms for client documentation. ● Class names should be nouns ● They describe. ● Ex. - Customer, Account, Product, Company. ● Method names should be verbs ● Take action. ● Ex. - getCustomer, closeAccount, updateProduct, addCompany. ● Pick a set of keywords and stick with them. ● 93 Ex. - fetch, get, add, update, remove, delete
  94. 94. Clean Application Development – Common sense ● With all of these problems, clean code makes sense ● ● On-boarding of developers easier. ● Less bugs. ● Happier end-users. ● Predictable schedules. ● 94 Shortens development time. It's the professional thing to do.
  95. 95. Clean Application Development – Rewrite problems ● The ● problem with a rewrite Reasons NOT to rewrite: ● Budget. ● Time. ● Retain business logic. ● ● Refactoring = best teacher. ● 95 Rewrite is the lazy way out. (perceived) Circle of HELL!
  96. 96. Clean Application Development – Clean code ● More ● on Clean Code Functions are pretty much what we expected. No surprises. ● ● ● Small and well named. Code makes language look simple. Recognizing bad code doesn't mean we know how to write clean code. ● ● ● ● 96 We know if a song is good/bad, but we are not song writers. Knowing code is bad doesn't mean we know how to clean it up. Clean code is written by someone who cares, and it can't really be changed much. Does not require many, if any, comments.
  97. 97. Clean Application Development – Code comments ● Comments can also be a bad “smell“ ● ● 97 Comments are often used to cover up bad code. Code should be self-documenting
  98. 98. Clean Application Development – Design Patterns ● Standard and quick solutions to common coding problems ● Provide standard ways of dealing with common code problems. ● “Guide to PHP Design Patterns“ by Jason Sweat. ● 98 “Design Patterns, Elements of Reusable Object-Oriented Software“ by Gang of four
  99. 99. Clean Application Development – Peer code reviews ● Peer code review great learning tool ● ● Fresh set of eyes. ● 99 Peers help train each other on strong points. Builds better teams.
  100. 100. Clean Application Development – Refactoring Refactoring 100
  101. 101. Clean Application Development – Resources ● Great refactoring resource. Refactoring By Martin Fowler Companion PHP code at: https://github.com/adamculp/refactoring101 101
  102. 102. Clean Application Development – Definition ● What ● is refactoring? ...process of changing a computer program's source code without modifying its external functional behavior... en.wikipedia.org/wiki/Refactoring ● ● Improve code readability. ● Simplify code. ● 102 Should not add functionality. Not optimizing.
  103. 103. Clean Application Development – Two Hats ● Two hats ● ● Refactoring hat ● 103 Adding functionality hat We add functionality, then refactor, then add more functionality ...
  104. 104. Clean Application Development – Why Refactory ● Why refactor? ● ● Poor design. ● Preserve design. ● Reduce duplication. ● Improve maintainability. ● Help code faster. ● Locate bugs. ● Code smells. ● 104 Prevent code decay. It's professional.
  105. 105. Clean Application Development – Code Smells ● Code ● smells What are smells? ● ● Not conclusive. ● 105 Indications of spoiled code nearby. Smell is not bad code, but hints of potential problems.
  106. 106. Clean Application Development – Smells of bad code ● Smells list ● Duplicate code. ● Large class. ● Long methods (functions). ● Long parameter (argument) list. ● Divergent change – cascade change to accommodate one. ● Shotgun surgery – change ripples as bugs throughout. ● Feature envy – method uses many parts from other class. ● Data clumps – data items accomplany one another. ● ● 106 Primitive Obsession – using primitive objects to represent various concepts in places they don't actually fit. (string vs integer, integer vs float, string vs date) Switch statements – often not alone, and sacrifice polymorphism.
  107. 107. Clean Application Development – Smells of bad code ● Smells list (cont'd.) ● ● Lazy class – class not doing much, just to be a class. ● Speculative generality – something built for possible future. ● Temporary field/variable. ● Message chains – object asking object asking object, etc. ● Middle man – directors in place but serve no real purpose. ● Inappropriate intimacy – classes should not share private parts. ● Data class – getters and/or setters, but nothing else. ● 107 Parellel inheritance hierarchies – forced to subclass due to another subclass. Comments – where comments explain bad code.
  108. 108. Clean Application Development – Code sniffer ● Let PHP CodeSniffer detect bad smells ● ● Run during commits in version control. ● 108 Set rules to detect if coding standard is not followed. IDE integration.
  109. 109. Clean Application Development – When to refactor ● When to refactor? ● No special time, do in short bursts. ● Don't decide to refactor, do it to gain something. ● Prior to adding functionality. ● ● ● Highlights code to modify. Fix code preventing addition. When fixing a bug. ● ● ● Makes code understandable. Highlights the bug. During code review. ● ● 109 Fresh eyes see things differently. More concrete results.
  110. 110. Clean Application Development – How to start ● First ● steps Use source control (Git, SVN, etc.) ● ● ● Record each step, and provides rollback points. Prove we did/didn't break it. We MUST FIRST GET IT WORKING! ● Do NOT refactor a broken application. ● ● 110 Pre-load database or create fixtures for consistent results. Create tests on working application.
  111. 111. Clean Application Development – Tests ● Tests ● Cannot properly refactor without tests. ● ● and refactoring To gauge success/failure. Basic refactor steps: ● Ensure tests pass. ● Plan refactor. ● Implement. ● Ensure tests still pass. ● Updating tests if needed. Only needed if structure changed. Add more tests to cover newly discovered items. ● ● ● 111 Repeat!
  112. 112. Clean Application Development – Refactoring 112
  113. 113. Clean Application Development – Refactoring Not if Broken 113
  114. 114. Clean Application Development – Refactoring Not if Broken 114
  115. 115. Clean Application Development – Refactoring Not if Broken 115 Create Tests
  116. 116. Clean Application Development – Refactoring Not if Broken 116 Create Tests
  117. 117. Clean Application Development – Refactoring Not if Broken 117 Create Tests Detect Smells
  118. 118. Clean Application Development – Refactoring Not if Broken 118 Create Tests Detect Smells
  119. 119. Clean Application Development – Refactoring Not if Broken Different Hats 119 Create Tests Detect Smells
  120. 120. Clean Application Development – Refactoring Not if Broken Different Hats 120 Create Tests Detect Smells
  121. 121. Clean Application Development – Refactoring Not if Broken Different Hats 121 Create Tests Improve Code Detect Smells
  122. 122. Clean Application Development – Refactoring Not if Broken Different Hats 122 Create Tests Improve Code Detect Smells
  123. 123. Clean Application Development – Refactoring Not if Broken Detect Smells Different Hats 123 Create Tests Improve Code No Change
  124. 124. Clean Application Development – Architecture Architecture 124
  125. 125. Clean Application Development – Clear architecture ● We can tell pretty simply this “looks“ like a library. (bookshelves, computers, book categories) 125
  126. 126. Clean Application Development – Simple overview ● With cars driving through and shelves on the sides we can guess this is a drive through. 126
  127. 127. Clean Application Development – Obvious purpose ● These 127 are pretty obvious without any explanation.
  128. 128. Clean Application Development – MVC architecture? ● This 128 would take a bit more digging to figure out.
  129. 129. Clean Application Development – Future challenges ● Shouldn't “Architecure“ be cleaner/clearer/simpler? 129
  130. 130. Clean Application Development – Testing Testing 130
  131. 131. Clean Application Development – Selenium IDE ● Selenium IDE ● ● Automates human steps. ● 131 Integrated into browsers. Customizable.
  132. 132. Clean Application Development – Behavior Driven ● Behat ● ● For PHP 5.3 and 5.4. ● 132 Open source. Human-readable sentences describing feature.
  133. 133. Clean Application Development – Unit Testing ● Unit testing (our parachute) ensures we write clean code ● ● Function should only do one thing, making them short. ● Testing ensures system is functioning as expected. ● 133 A unit test should only test one thing, a function may need multiple tests. Helps make refactoring and cleaning easier.
  134. 134. Clean Application Development – TDD ● Unit ● 134 testing is important, so should be done first Write failing tests first, then write the code required to make it pass.
  135. 135. Clean Application Development – Tests = QA ● If tests are trusted, they become QA process ● If tests are good, QA finds no issues. ● If QA finds an issue, write a test for it. ● Tests cover requirements. ● Tests = requirements. ● QA to write automated tests that fail. ● 135 Developers execute tests during development till they pass.
  136. 136. Clean Application Development – QA and unit tests ● Put QA at the begining of the process, instead of the end ● QA has a terrible job, waiting for code to test. ● If they write unit tests they jump to the front. ● Developers write code to pass tests. ● 136 The end is not so bad now.
  137. 137. Clean Application Development – Continuous Int. Continuous Integration 137
  138. 138. Clean Application Development – Phing ● PHing Is Not GNU make. ● Based on Apache Ant. ● Uses simple XML build files and extensible PHP 'task' classes. ● ● File transformations ● File system operations. ● Interactive build support. ● SQL execution. ● SCM operations. ● Documentation generation. ● 138 Runs unit tests. More....
  139. 139. Clean Application Development – Zend Deployment ● Zend Deployment ● ● Create ZPK of project in Zend Studio. ● Upload to Zend Server. ● 139 Built into Zend Server. Deploy!
  140. 140. Clean Application Development – Jenkins ● Jenkins ● ● Built with Java. ● 789 plugins. ● Runs PHPUnit. ● Runs CodeSniffer. ● Runs PHP QA Tools. ● 140 Formerly known as Hudson. Deploys.
  141. 141. Clean Application Development – Jenkins Results ● Jenkins 141 Results
  142. 142. Clean Application Development – Professional Be Professional Grade! 142
  143. 143. Clean Application Development – Human resources ● Our ● ● Professionals are trusted to do a good job, give good estimate, and provide quality. Professionals are fairly easily replaced, depending on availability. ● ● 143 clients hired a professional, they should get one Replaceable = Promotable (and you can take vacation easily) Shouldn't need to start from scratch.
  144. 144. Clean Application Development – Close ● Clean application development is: ● ● Clear architecture. ● Coding standards and styles. ● Framework and best practices. ● Testing. ● Agile. ● Learning to say “NO“, and defend the code. ● 144 Learning, repetition, practice. Living up to the title “Professional“.
  145. 145. ● Resources ● Adam Culp @adamculp and http://geekyboy.com ● Book: “Clean Code“ by Robert C. Martin ● Book: “Refactoring“ by Martin Fowler ● Book: “Guide to PHP Design Patterns“ by Jason Sweat ● Book: “Design Patterns“ by Gang of four ● http://www.php-fig.org ● http://www.phpunit.de ● http://www.soflophp.org Thank You! https://joind.in/9284

×