SlideShare a Scribd company logo
Simplify writing code with
deliberate commits
March 2019
Joel Chippindale - CTO at Unmade - @joelchippindale
Joel
Chippindale
CTO at
Unmade
“If you can’t explain
it simply, you don’t
understand it well
enough.
- Albert Einstein (probably)
by Cory Doctorow (CC BY-SA)
Our work
requires us to
make changes
to complex
systems
@joelchippindale
We learn to break down
complex problems into
small, simple steps
by WOCinTech Chat (CC BY)
Great
developers are
really good at
doing this
@joelchippindale
This is hard
@joelchippindale
...and it takes discipline
and willpower
@joelchippindale
You know you are not
doing this when...
@joelchippindale
...you feel like you have to
keep track of lots of
things in your head.
@joelchippindale
...you have unstaged
changes in lots of files
and can't remember why.
@joelchippindale
...you are not sure if are
making progress or not.
@joelchippindale
We learn to employ a
wide variety of
techniques to help us
@joelchippindale
One tool we underuse is
our version control
system
@joelchippindale
The examples I will give
are for git but they apply
to other systems too
1. Plan your commits
2. Use single purpose branches
3. Make atomic commits
4. Write good commit messages
5. Rewrite your history to tell a story
(early and often)
by Alexander Baxevanis (CC BY)
Habit 1:
Plan your
commits
@joelchippindale
Make a plan for the
commits that you will
make
@joelchippindale
What if you don't know
enough yet to make a
plan?
@joelchippindale
What if the plan changes?
@joelchippindale
Plan your commits ahead
of time and re-plan when
you need to
Jon Bennet
Habit 2:
Use single
purpose
branches
@joelchippindale
Name your branch to
reflect it's (single)
purpose
@joelchippindale
Notice when you are
starting to work on
something else
@joelchippindale
Notice if a commit has
value independent of the
branch
@joelchippindale
...and if it does, then
'cherry pick' it onto
master
master
feature-a
$
A
B
C
D
master
feature-a
$ git checkout master
A
B
C
D
$ git checkout master
master
feature-a
A
B
C
D
$ git cherry-pick feature-a
master
feature-a
A
B
C
D
$ git cherry-pick feature-a
master
feature-a
A
B
C
D
D`
$ git checkout feature-a
master
feature-a
A
B
C
D
D`
$ git checkout feature-a
master
feature-a
A
B
C
D
D`
$ git rebase master
master
feature-a
A
B
C
D
D`
$ git rebase master
master
feature-a
A
B
D`
C`
@joelchippindale
Keep focussed by making
each development
branch single purpose
by lupusphotos (CC BY)
Habit 3:
Make atomic
commits
@joelchippindale
Decide the one change
you are going to make
and commit it
@joelchippindale
How big a change should
I make?
@joelchippindale
Minimum valuable
commit
@joelchippindale
Be suspicious of 'and' in
your commit
@joelchippindale
Notice when you start
doing something else and
stop
$ git add --patch
$ git add --patch
diff --git a/layout/models.py b/layout/models.py
index f2dd5a8..b4dd522 100644
--- a/layout/models.py
+++ b/layout/models.py
@@ -27,7 +27,7 @@ class Layout(models.Model):
def __str__(self):
if self.is_layplan:
- return "Layplan: {}".format(self.data.get("slug", self.code))
+ return "Layplan: {}".format(self.data.get("name", self.code))
else:
return "Layout: {}".format(self.code)
Stage this hunk [y,n,q,a,d,e,?]?
@joelchippindale
Make each step simple by
making atomic commits
by Ginny (CC BY-SA)
Habit 4:
Write good
commit
messages
2867d63 Final commit, ready for tagging
8cecffe foo
880f22c WTF
feb8cd1 More work on this
a8c9f94 WIP
46c4aa4 This will definitely work
79bbf47 This might work
9ccd522 Trying to fix it again
6eb4a7f Debug stuff
@joelchippindale
What does good look
like?
Short one line title
Longer description of what the change does (if
the title isn’t enough).
An explanation of why the change is being made.
Perhaps a discussion of context and/or
alternatives that were considered.
Short one line title
Longer description of what the change does
(if the title isn’t enough).
An explanation of why the change is being
made.
Perhaps a discussion of context and/or
alternatives that were considered.
Short one line title
Longer description of what the change does
(if the title isn’t enough).
An explanation of why the change is being
made.
Perhaps a discussion of context and/or
alternatives that were considered.
Short one line title
Longer description of what the change does
(if the title isn’t enough).
An explanation of why the change is being
made.
Perhaps a discussion of context and/or
alternatives that were considered.
Short one line title
Longer description of what the change does
(if the title isn’t enough).
An explanation of why the change is being
made.
Perhaps a discussion of context and/or
alternatives that were considered.
Correct the colour of FAQ link in course notice footer
PT: https://www.pivotaltracker.com/story/show/84753832
In some email clients the colour of the FAQ link in the
course notice footer was being displayed as blue instead of
white. The examples given in PT are all different versions of
Outlook. Outlook won't implement CSS changes that include `!
important` inline[1]. Therefore, since we were using it to
define the colour of that link, Outlook wasn't applying that
style and thus simply set its default style (blue, like in
most browsers). Removing that `!important` should fix the
problem.
[1] https://www.campaignmonitor.com/blog/post/3143/
outlook-2007-and-the-inline-important-declaration/
@joelchippindale
Clear space in your head
by writing good commit
messages
hoodedfang
Habit 5:
Rewrite your
history to tell a
simple story
(early and
often)
$ git rebase --interactive
@joelchippindale
Remove, reorder, edit,
merge and split commits
343eed2 Fix typo in foo
ba66794 Add bar
90328f9 Add foo
$ git rebase --interactive master
1 pick 90328f9 Add foo
2 pick ba66794 Add bar
3 pick 343eed2 Fix typo in foo
4
5 # Rebase c405e59..343eed2 onto c405e59 (3 commands)
6 #
7 # Commands:
8 # p, pick <commit> = use commit
9 # r, reword <commit> = use commit, but edit the commit message
10 # e, edit <commit> = use commit, but stop for amending
11 # s, squash <commit> = use commit, but meld into previous commit
12 # f, fixup <commit> = like "squash", but discard this commit's log message
13 # x, exec <command> = run command (the rest of the line) using shell
14 # b, break = stop here (continue rebase later with 'git rebase --continue')
15 # d, drop <commit> = remove commit
16 # l, label <label> = label current HEAD with a name
17 # t, reset <label> = reset HEAD to a label
1 pick 90328f9 Add foo
2 pick 343eed2 Fix typo in foo
3 pick ba66794 Add bar
4
5 # Rebase c405e59..343eed2 onto c405e59 (3 commands)
6 #
7 # Commands:
8 # p, pick <commit> = use commit
9 # r, reword <commit> = use commit, but edit the commit message
10 # e, edit <commit> = use commit, but stop for amending
11 # s, squash <commit> = use commit, but meld into previous commit
12 # f, fixup <commit> = like "squash", but discard this commit's log message
13 # x, exec <command> = run command (the rest of the line) using shell
14 # b, break = stop here (continue rebase later with 'git rebase --continue')
15 # d, drop <commit> = remove commit
16 # l, label <label> = label current HEAD with a name
17 # t, reset <label> = reset HEAD to a label
1 pick 90328f9 Add foo
2 fixup 343eed2 Fix typo in foo
3 pick ba66794 Add bar
4
5 # Rebase c405e59..343eed2 onto c405e59 (3 commands)
6 #
7 # Commands:
8 # p, pick <commit> = use commit
9 # r, reword <commit> = use commit, but edit the commit message
10 # e, edit <commit> = use commit, but stop for amending
11 # s, squash <commit> = use commit, but meld into previous commit
12 # f, fixup <commit> = like "squash", but discard this commit's log message
13 # x, exec <command> = run command (the rest of the line) using shell
14 # b, break = stop here (continue rebase later with 'git rebase --continue')
15 # d, drop <commit> = remove commit
16 # l, label <label> = label current HEAD with a name
17 # t, reset <label> = reset HEAD to a label
4a14d7b Add bar
c296093 Add foo
@joelchippindale
Make your progress clear
by rewriting your history
to tell a simple story
1. Plan your commits
2. Use single purpose branches
3. Make atomic commits
4. Write good commit messages
5. Rewrite your history to tell a story
(early and often)
$ git cherry-pick
$ git add --patch
$ git rebase --interactive
@joelchippindale
Following these 5 habits
will free up your brain...
@joelchippindale
...and have the added
bonus of providing an
explanation for your work
“Every line of code is
always documented
- Mislav Marohnić
https://mislav.net/2014/02/hidden-documentation/
@joelchippindale
Any questions?
Joel Chippindale - CTO at Unmade - @joelchippindale
We are hiring
https://www.unmade.com/careers/
@joelchippindale
Thank you
Joel Chippindale - CTO at Unmade - @joelchippindale
We are hiring
https://www.unmade.com/careers/

More Related Content

Similar to Simplify writing code with deliberate commits - London Python Meetup

Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010
Matt Gauger
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
alignan
 
Tool Time
Tool TimeTool Time
Tool Time
Ken Collins
 
Git in pills : git stash
Git in pills : git stashGit in pills : git stash
Git in pills : git stash
Federico Panini
 
Keep you GIT history clean
Keep you GIT history cleanKeep you GIT history clean
Keep you GIT history clean
tomasbro
 
Git Pro Tips
Git Pro TipsGit Pro Tips
Git Pro Tips
thehoagie
 
Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!
mold
 
Bedjango talk about Git & GitHub
Bedjango talk about Git & GitHubBedjango talk about Git & GitHub
Bedjango talk about Git & GitHub
BeDjango
 
Git, from the beginning
Git, from the beginningGit, from the beginning
Git, from the beginning
James Aylett
 
Sacándole jugo a git
Sacándole jugo a gitSacándole jugo a git
Sacándole jugo a git
Berny Cantos
 
A short guide to git's interactive rebase
A short guide to git's interactive rebaseA short guide to git's interactive rebase
A short guide to git's interactive rebase
Ombu Labs, The Lean Software Boutique
 
Git workshop
Git workshopGit workshop
Git workshop
Ray Toal
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
Nick Quaranto
 
Coder Presentation Boston
Coder Presentation BostonCoder Presentation Boston
Coder Presentation Boston
Doug Green
 
git session --interactive
git session --interactivegit session --interactive
git session --interactive
Marius Colacioiu
 
3 Git
3 Git3 Git
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
Jesús Miguel Benito Calzada
 
Bend time to your will with git
Bend time to your will with gitBend time to your will with git
Bend time to your will with git
Chris Tankersley
 
Becoming a Git Master
Becoming a Git MasterBecoming a Git Master
Becoming a Git Master
Nicola Paolucci
 
Nikolai Boiko "NodeJS Refactoring: How to kill a Dragon and stay alive"
Nikolai Boiko "NodeJS Refactoring: How to kill a Dragon and stay alive"Nikolai Boiko "NodeJS Refactoring: How to kill a Dragon and stay alive"
Nikolai Boiko "NodeJS Refactoring: How to kill a Dragon and stay alive"
NodeUkraine
 

Similar to Simplify writing code with deliberate commits - London Python Meetup (20)

Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
Tool Time
Tool TimeTool Time
Tool Time
 
Git in pills : git stash
Git in pills : git stashGit in pills : git stash
Git in pills : git stash
 
Keep you GIT history clean
Keep you GIT history cleanKeep you GIT history clean
Keep you GIT history clean
 
Git Pro Tips
Git Pro TipsGit Pro Tips
Git Pro Tips
 
Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!
 
Bedjango talk about Git & GitHub
Bedjango talk about Git & GitHubBedjango talk about Git & GitHub
Bedjango talk about Git & GitHub
 
Git, from the beginning
Git, from the beginningGit, from the beginning
Git, from the beginning
 
Sacándole jugo a git
Sacándole jugo a gitSacándole jugo a git
Sacándole jugo a git
 
A short guide to git's interactive rebase
A short guide to git's interactive rebaseA short guide to git's interactive rebase
A short guide to git's interactive rebase
 
Git workshop
Git workshopGit workshop
Git workshop
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Coder Presentation Boston
Coder Presentation BostonCoder Presentation Boston
Coder Presentation Boston
 
git session --interactive
git session --interactivegit session --interactive
git session --interactive
 
3 Git
3 Git3 Git
3 Git
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
 
Bend time to your will with git
Bend time to your will with gitBend time to your will with git
Bend time to your will with git
 
Becoming a Git Master
Becoming a Git MasterBecoming a Git Master
Becoming a Git Master
 
Nikolai Boiko "NodeJS Refactoring: How to kill a Dragon and stay alive"
Nikolai Boiko "NodeJS Refactoring: How to kill a Dragon and stay alive"Nikolai Boiko "NodeJS Refactoring: How to kill a Dragon and stay alive"
Nikolai Boiko "NodeJS Refactoring: How to kill a Dragon and stay alive"
 

Recently uploaded

Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 

Recently uploaded (20)

Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 

Simplify writing code with deliberate commits - London Python Meetup

  • 1. Simplify writing code with deliberate commits March 2019 Joel Chippindale - CTO at Unmade - @joelchippindale
  • 3. “If you can’t explain it simply, you don’t understand it well enough. - Albert Einstein (probably)
  • 4. by Cory Doctorow (CC BY-SA) Our work requires us to make changes to complex systems
  • 5. @joelchippindale We learn to break down complex problems into small, simple steps
  • 6. by WOCinTech Chat (CC BY) Great developers are really good at doing this
  • 8. @joelchippindale ...and it takes discipline and willpower
  • 9. @joelchippindale You know you are not doing this when...
  • 10. @joelchippindale ...you feel like you have to keep track of lots of things in your head.
  • 11. @joelchippindale ...you have unstaged changes in lots of files and can't remember why.
  • 12. @joelchippindale ...you are not sure if are making progress or not.
  • 13. @joelchippindale We learn to employ a wide variety of techniques to help us
  • 14. @joelchippindale One tool we underuse is our version control system
  • 15. @joelchippindale The examples I will give are for git but they apply to other systems too
  • 16. 1. Plan your commits 2. Use single purpose branches 3. Make atomic commits 4. Write good commit messages 5. Rewrite your history to tell a story (early and often)
  • 17. by Alexander Baxevanis (CC BY) Habit 1: Plan your commits
  • 18. @joelchippindale Make a plan for the commits that you will make
  • 19. @joelchippindale What if you don't know enough yet to make a plan?
  • 21. @joelchippindale Plan your commits ahead of time and re-plan when you need to
  • 22. Jon Bennet Habit 2: Use single purpose branches
  • 23. @joelchippindale Name your branch to reflect it's (single) purpose
  • 24. @joelchippindale Notice when you are starting to work on something else
  • 25. @joelchippindale Notice if a commit has value independent of the branch
  • 26. @joelchippindale ...and if it does, then 'cherry pick' it onto master
  • 29. $ git checkout master master feature-a A B C D
  • 30. $ git cherry-pick feature-a master feature-a A B C D
  • 31. $ git cherry-pick feature-a master feature-a A B C D D`
  • 32. $ git checkout feature-a master feature-a A B C D D`
  • 33. $ git checkout feature-a master feature-a A B C D D`
  • 34. $ git rebase master master feature-a A B C D D`
  • 35. $ git rebase master master feature-a A B D` C`
  • 36. @joelchippindale Keep focussed by making each development branch single purpose
  • 37. by lupusphotos (CC BY) Habit 3: Make atomic commits
  • 38. @joelchippindale Decide the one change you are going to make and commit it
  • 39. @joelchippindale How big a change should I make?
  • 41. @joelchippindale Be suspicious of 'and' in your commit
  • 42. @joelchippindale Notice when you start doing something else and stop
  • 43. $ git add --patch
  • 44. $ git add --patch diff --git a/layout/models.py b/layout/models.py index f2dd5a8..b4dd522 100644 --- a/layout/models.py +++ b/layout/models.py @@ -27,7 +27,7 @@ class Layout(models.Model): def __str__(self): if self.is_layplan: - return "Layplan: {}".format(self.data.get("slug", self.code)) + return "Layplan: {}".format(self.data.get("name", self.code)) else: return "Layout: {}".format(self.code) Stage this hunk [y,n,q,a,d,e,?]?
  • 45. @joelchippindale Make each step simple by making atomic commits
  • 46. by Ginny (CC BY-SA) Habit 4: Write good commit messages
  • 47. 2867d63 Final commit, ready for tagging 8cecffe foo 880f22c WTF feb8cd1 More work on this a8c9f94 WIP 46c4aa4 This will definitely work 79bbf47 This might work 9ccd522 Trying to fix it again 6eb4a7f Debug stuff
  • 49. Short one line title Longer description of what the change does (if the title isn’t enough). An explanation of why the change is being made. Perhaps a discussion of context and/or alternatives that were considered.
  • 50. Short one line title Longer description of what the change does (if the title isn’t enough). An explanation of why the change is being made. Perhaps a discussion of context and/or alternatives that were considered.
  • 51. Short one line title Longer description of what the change does (if the title isn’t enough). An explanation of why the change is being made. Perhaps a discussion of context and/or alternatives that were considered.
  • 52. Short one line title Longer description of what the change does (if the title isn’t enough). An explanation of why the change is being made. Perhaps a discussion of context and/or alternatives that were considered.
  • 53. Short one line title Longer description of what the change does (if the title isn’t enough). An explanation of why the change is being made. Perhaps a discussion of context and/or alternatives that were considered.
  • 54. Correct the colour of FAQ link in course notice footer PT: https://www.pivotaltracker.com/story/show/84753832 In some email clients the colour of the FAQ link in the course notice footer was being displayed as blue instead of white. The examples given in PT are all different versions of Outlook. Outlook won't implement CSS changes that include `! important` inline[1]. Therefore, since we were using it to define the colour of that link, Outlook wasn't applying that style and thus simply set its default style (blue, like in most browsers). Removing that `!important` should fix the problem. [1] https://www.campaignmonitor.com/blog/post/3143/ outlook-2007-and-the-inline-important-declaration/
  • 55. @joelchippindale Clear space in your head by writing good commit messages
  • 56. hoodedfang Habit 5: Rewrite your history to tell a simple story (early and often)
  • 57. $ git rebase --interactive
  • 59. 343eed2 Fix typo in foo ba66794 Add bar 90328f9 Add foo
  • 60. $ git rebase --interactive master
  • 61. 1 pick 90328f9 Add foo 2 pick ba66794 Add bar 3 pick 343eed2 Fix typo in foo 4 5 # Rebase c405e59..343eed2 onto c405e59 (3 commands) 6 # 7 # Commands: 8 # p, pick <commit> = use commit 9 # r, reword <commit> = use commit, but edit the commit message 10 # e, edit <commit> = use commit, but stop for amending 11 # s, squash <commit> = use commit, but meld into previous commit 12 # f, fixup <commit> = like "squash", but discard this commit's log message 13 # x, exec <command> = run command (the rest of the line) using shell 14 # b, break = stop here (continue rebase later with 'git rebase --continue') 15 # d, drop <commit> = remove commit 16 # l, label <label> = label current HEAD with a name 17 # t, reset <label> = reset HEAD to a label
  • 62. 1 pick 90328f9 Add foo 2 pick 343eed2 Fix typo in foo 3 pick ba66794 Add bar 4 5 # Rebase c405e59..343eed2 onto c405e59 (3 commands) 6 # 7 # Commands: 8 # p, pick <commit> = use commit 9 # r, reword <commit> = use commit, but edit the commit message 10 # e, edit <commit> = use commit, but stop for amending 11 # s, squash <commit> = use commit, but meld into previous commit 12 # f, fixup <commit> = like "squash", but discard this commit's log message 13 # x, exec <command> = run command (the rest of the line) using shell 14 # b, break = stop here (continue rebase later with 'git rebase --continue') 15 # d, drop <commit> = remove commit 16 # l, label <label> = label current HEAD with a name 17 # t, reset <label> = reset HEAD to a label
  • 63. 1 pick 90328f9 Add foo 2 fixup 343eed2 Fix typo in foo 3 pick ba66794 Add bar 4 5 # Rebase c405e59..343eed2 onto c405e59 (3 commands) 6 # 7 # Commands: 8 # p, pick <commit> = use commit 9 # r, reword <commit> = use commit, but edit the commit message 10 # e, edit <commit> = use commit, but stop for amending 11 # s, squash <commit> = use commit, but meld into previous commit 12 # f, fixup <commit> = like "squash", but discard this commit's log message 13 # x, exec <command> = run command (the rest of the line) using shell 14 # b, break = stop here (continue rebase later with 'git rebase --continue') 15 # d, drop <commit> = remove commit 16 # l, label <label> = label current HEAD with a name 17 # t, reset <label> = reset HEAD to a label
  • 65. @joelchippindale Make your progress clear by rewriting your history to tell a simple story
  • 66. 1. Plan your commits 2. Use single purpose branches 3. Make atomic commits 4. Write good commit messages 5. Rewrite your history to tell a story (early and often)
  • 67. $ git cherry-pick $ git add --patch $ git rebase --interactive
  • 68. @joelchippindale Following these 5 habits will free up your brain...
  • 69. @joelchippindale ...and have the added bonus of providing an explanation for your work
  • 70. “Every line of code is always documented - Mislav Marohnić https://mislav.net/2014/02/hidden-documentation/
  • 71. @joelchippindale Any questions? Joel Chippindale - CTO at Unmade - @joelchippindale We are hiring https://www.unmade.com/careers/
  • 72. @joelchippindale Thank you Joel Chippindale - CTO at Unmade - @joelchippindale We are hiring https://www.unmade.com/careers/