write code for the future you - tulsa techfest 2016

68
Tulsa TechFest 2016 | Fri, Aug 5 th , 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions! Please help us! Thank our Sponsors:

Upload: paul-gower

Post on 22-Feb-2017

131 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

Please help us!Thank our Sponsors:

Page 2: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

Write Code For The Future You

Paul GowerPrincipal Consultant / OwnerLunamark

Page 3: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Full Disclosure…

Page 4: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Full Disclosure…Summer 2000

Page 5: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Full Disclosure…Summer 2000

Obfuscated Perl Contest

Page 6: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Full Disclosure…Summer 2000

Obfuscated Perl Contest

Mentality was to write “elite code” that was hard to understand

Page 7: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Trajectory Shift

Page 8: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Trajectory ShiftFirst job out of college, 2001

Page 9: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Trajectory ShiftFirst job out of college, 2001Alltel Client/Server University

Page 10: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Trajectory ShiftFirst job out of college, 2001Alltel Client/Server University

Textbook: Code CompleteDaily Lectures, Labs, and Code Reviews

Page 11: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Real World Learning

Page 12: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Real World Learning

Added to project towards end of development

Page 13: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Real World Learning

Added to project towards end of developmentFixing bugs in code you didn’t write

Page 14: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Real World Learning

Added to project towards end of developmentFixing bugs in code you didn’t writeThe Mythical Man Month by Fred Brooks

Page 15: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Maintenance? Not me…

Page 16: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Maintenance? Not me…

Creating Code30%

Maintaining Code70%

Page 17: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Who reads code? Not me…

Page 18: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Who reads code? Not me…Writing Code

10%

Reading Code90%

Page 19: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Why write code for the reader?

Page 20: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Sept 1991, Comp.lang.c++ newsgroup discussion

Why write code for the reader?

Page 21: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Sept 1991, Comp.lang.c++ newsgroup discussionWhy not use comma more?

Why write code for the reader?

Page 22: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Sept 1991, Comp.lang.c++ newsgroup discussionWhy not use comma more?Like this:

if (condition)var = value, anothervar = anothervalue;

Why write code for the reader?

Page 23: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Sept 1991, Comp.lang.c++ newsgroup discussionWhy not use comma more?Like this:

if (condition)var = value, anothervar = anothervalue;

However consider this:if (condition)var = value; anothervar = anothervalue;

Why write code for the reader?

Page 24: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live”

John F. Woods

Page 25: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

How To Write Better Code?

@paulmgower

Page 26: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

How To Write Better Code?Code Complete published in 1993, 2004

@paulmgower

Page 27: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

How To Write Better Code?Code Complete published in 1993, 2004

Agile Manifesto signed 2001

@paulmgower

Page 28: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

How To Write Better Code?Code Complete published in 1993, 2004

Agile Manifesto signed 2001

Clean Code book published in 2009

@paulmgower

Page 29: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Power in Variable Names

Describe the entity it represents

Page 30: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Power in Variable Names

Describe the entity it represents

Easy to understand and read

Page 31: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Power in Variable Names

Describe the entity it represents

Easy to understand and read

Be specific as possible

Page 32: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Variable Name Examples

Bad Namestotal, ct, checks, CHKTTLvelt, tv, traincd, current, c, datelpp, lines

Good NamesrunningTotal, checkTotaltrainVelocity, velocityInMphcurrentDate, todaysDatelinesPerPage

Page 33: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Magic Numbers

Page 34: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Magic Numbers == BADDon’t use magic numbers

Page 35: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Magic Numbers == BADDon’t use magic numbers

Instead use constants, enums or config

Page 36: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Magic Numbers == BADDon’t use magic numbers

Instead use constants, enums, or config

Makes code more readable / self documenting

Page 37: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Don’t Do Thispublic void setPassword(String password){ // don't do this if (password.length() > 7) { throw newInvalidArgumentException("password"); } }

Page 38: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

public void setPassword(String password){ const int MAX_PASSWORD_SIZE = 7; if (password.length() > MAX_PASSWORD_SIZE) { throw new InvalidArgumentException("password"); }}

Use Constants or Configuration

Page 39: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

D.R.Y.

Page 40: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

D.R.Y. (Don’t Repeat Yourself)

Duplication leads to maintenance issues

Page 41: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

D.R.Y. (Don’t Repeat Yourself)

Duplication leads to maintenance issues

Y2K Culprit?

Page 42: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

D.R.Y. (Don’t Repeat Yourself)

Duplication leads to maintenance issues

Y2K Culprit?

“Every piece of knowledge must have a single, unambiguous, authoritative representation within a system”

Page 43: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Classes: Do One Thing Well

Page 44: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Classes: Do One Thing Well

Each responsibility is an axis of change

Page 45: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Classes: Do One Thing Well

Each responsibility is an axis of change

Change is going to happen

Page 46: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Classes: Do One Thing Well

Each responsibility is an axis of change

Change is going to happen

Loose Coupling

Page 47: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

More than 1 Responsibility

Page 48: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Single Responsibility

Page 49: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Stop Writing Legacy Code

Page 50: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Stop Writing Legacy Code

Legacy Code = Code without Tests

Page 51: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Stop Writing Legacy Code

Legacy Code = Code without Tests

Great Step-by-step guide

Page 52: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Stop Writing Legacy Code

Legacy Code = Code without Tests

Great Step-by-step guide

Write unit tests as you use legacy code

Page 53: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Code Reviews

Author + 2 Reviewers

Page 54: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Code Reviews

Author + 2 Reviewers

Using “peer pressure”

Page 55: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Code Reviews

Author + 2 Reviewers

Using “peer pressure”

Encourages collaboration

Page 56: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Code Reviews Tips

Keep a positive attitude

Page 57: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Code Reviews Tips

Keep a positive attitudeCheck your ego

Page 58: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Code Reviews Tips

Keep a positive attitudeCheck your egoReview all code

Page 59: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Code Reviews Tips

Keep a positive attitudeCheck your egoReview all codeCode Review early and often

Page 60: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Final Review

Page 61: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Final ReviewGive better variable names

Page 62: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Final ReviewGive better variable namesDon’t use magic numbers

Page 63: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Final ReviewGive better variable namesDon’t use magic numbersKeep your code DRY

Page 64: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Final ReviewGive better variable namesDon’t use magic numbersKeep your code DRYClasses should do one thing

Page 65: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Final ReviewGive better variable namesDon’t use magic numbersKeep your code DRYClasses should do one thingWrite Unit Tests

Page 66: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Final ReviewGive better variable namesDon’t use magic numbersKeep your code DRYClasses should do one thingWrite Unit TestsHave regular Code Reviews

Page 67: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

Questions?

http://lunamark.com

http://bit.ly/ttf2016-wcfy

Page 68: Write Code For The Future You - Tulsa TechFest 2016

Tulsa TechFest 2016 | Fri, Aug 5th, 2016 | OSU - Tulsa | 70+ Speakers, 20+ Tracks & 85+ Sessions!

@paulmgower

ResourcesThe Mythical Man Month by Frederick P. Brooks Jr (http://www.amazon.com/The-Mythical-Man-Month-Engineering-Anniversary/dp/0201835959) Code Complete by Steve McConnell (http://www.amazon.com/Code-Complete-Practical-Handbook-Construction/dp/0735619670) Clean Code by Robert C. Martin (http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882) Working Effectively with Legacy Code by Michael Feathers (http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052) FogCreek Software Blog

Effective Code Reviews - 9 Tips from a Converted Skeptic (http://blog.fogcreek.com/effective-code-reviews-9-tips-from-a-converted-skeptic/) Stop More Bugs with our Code Review Checklist (http://blog.fogcreek.com/increase-defect-detection-with-our-code-review-checklist-example/)