habits of a responsible programmer
TRANSCRIPT
Habits of a Responsible Programmer
Anders Janmyr@andersjanmyr
http://anders.janmyr.com
Outline
• Definitions
• Programming
• Project
• Life, the Universe and Everything
• Summary
Definitions
Habit
An acquired behavior pattern, regularly followed,
until it has become almost involuntary
— dictionary.com
The Conscious BrainSequential and Slow
The Unconscious BrainParallel and Fast
Habits
Creating Habits
Outsourcing to our
unconscious
Responsible
Accountable for somethingwithin one's power or control
— dictionary.com
Why Be Responsible?
Programming
TypingAnd as for this
non-college bullshit I got two words for that:learn to fuckin' type!
— Mr. Pink
Write Clear Code
Consistent
• Follow Conventions
• Constants: SCREAMING_SNAKE_CASE
• HTML Attributes: dash-er-ized
• API: Naming, Ordering, etc.
Don’t Quick Fix
Short Classes, Functions, Parameter Lists
Short Classes, Functions, Parameter Lists
Separate Commands from Queries
Separate Commands from Queries
External Dependencies
• Use as few as practical
• Learn it well
• Wrap them
Refactor Mercilessly
• When understanding changes
• Prevents bugs and frustration
• Don’t ask for permission!
Balance
Prefer Explicit
ExplicitSpecific
ConcreteDirect
ImplicitGenericAbstractIndirect
function helloWorld() { console.log(‘Hello World’);}
function helloWorld() { hello(‘World’);}
function hello(thing) { var m = ‘Hello ’+ thing; console.log(m);}
Learn Basic Techniques
• Iteration and Recursion
• Conditional Code
• Functions and Closures
• Classes, Objects, Immutability
Simple vs. Easy
SimpleSingular
Does one thingIs made of one thing
EasyClose at hand
Familiar
Learn Advanced Techniques
• Meta-objects and Reflection
• Monads and Continuations
• Events, Contracts, ...
• Actors, Message Queues, ...
Testing
The Scientific MethodTheory
Prediction
Experiment
Observation
What to Unit Test?Query Command
Assertresult
Assert direct publicside e!ects
Ignore Expect to send
Incoming
Type
@sandimetz Apr 2013
Message
IgnoreSent to Self
Outgoing
Origin
Saturday, April 27, 13
Documentation
README
• Description
• Installation Instructions
• Usage Instructions
• Examples
• Pointers to more documentation
An Overview
System Overview
DrawingMap
DescriptionA few pages
ServersDatabases
External services
Domain Overview
DrawingMap
DescriptionA few pages
Bounded ContextCore Objects
Main supporting domains
CommentsASSUMPTION:
TODO:
As Few As Possible
WTF:
Anything else
Tools
• The Editor
• The Version Control System
• The Command Line
• A scripting language
• Anything you use on a daily basis
The Editor
Version Control System
CV, legacy
CV, modern
http://commitlogsfromlastnight.com/
A Good Commit Message
Command Line
sudo lsof -nPi | grep LISTEN |awk '{printf "%-20s%8s%20s\n",$1,$2,$9}'| sort | uniq
Scripting
What to script?Alias
DeploymentVerification
Code Generation
Watch scripts
Setup Machines
Editor Macros
A bash function (≈alias)
Deploy new Server
Go away,or I will replace you with a very small shell script!
Environments
All Environments
• Setup with ONE command
• Scripts are continuously maintained
Production
• All configuration, dependencies
• Optimized for speed
• Configured for monitoring
Development
• As similar as possible to production
• Optimized for development speed
• Short feedback cycle
• Watchers, live reloading, auto testing
Test
• Test Fixtures
• Mock services
• Recorded API interactions
Project
Compromise
Critique
Own It!
Why? Why? Why?
Estimation
It is better to ask for
forgiveness than to ask for
permission!-- Grace Hopper
Flow
Focus
Know what makes you happy!
Silva’s 4 rules of happiness
1. If you like something, enjoy it!
2. If you don’t like something, avoid it!
3. If you don’t like something and can’t avoid it, change it!
4. If you can’t or choose not to avoid or change it, change your perception of it!
Not Important Important
Not Urgent
Urgent
✖ ✔
✔
Urgent ≠ Important
Relax
Summary
• Write clean code
• Test
• Script everything
• Learn your tools by heart
• Optimize for flow
Proud!
Habits of a Responsible Programmer
Anders Janmyr@andersjanmyr
References http://anders.janmyr.com