Coding Fast and Slow: Applying Kahneman’s Insights to Improve Development Practices and Efficiency

A presentation at NFJS Webinar April 2024 in April 2024 in by Baruch Sadogursky

Slide 1

Slide 1

Coding Fast and Slow

Slide 2

Slide 2

Slide 3

Slide 3

Baruch Sadogursky - @jbaru ch × Developer Productivity Advocate × Gradle Inc × Development -> DevOps -> #DPE

Slide 4

Slide 4

shownotes × × × × speaking.jbaru.ch Slides Video All the links!

Slide 5

Slide 5

Daniel Kahneman Mar 5, 1934 – Mar 27, 2024

Slide 6

Slide 6

Slide 7

Slide 7

A bat and a ball cost $1.10 in total. The bat costs $1 more than the ball. How much does the ball cost?

Slide 8

Slide 8

How much does the ball cost? C10 + $1.10 = $1.20 C5 + $1.5 = $1.10

Slide 9

Slide 9

Two systems x x x x x Fast Intuitive Automatic Emotional Cheap and eager x x x x x Slow Analytical Controlled Logical Expensive and lazy

Slide 10

Slide 10

class UniqueWords { public static void main(String[] args) throws IOException { if (args.length != 1) { throw new IllegalArgumentException(“Invalid argument”); } Set<String> words = new HashSet<>(); for (String line : Files.readAllLines(Path.of(args[0]))) { // Ignore commented lines if (!line.startsWith(“#”) || !line.startsWith(“//”)) { Collections.addAll(words, line.split(“\W+”)); } } System.out.println(”Count of unique words: ” + words.size()); } }

Slide 11

Slide 11

Slide 12

Slide 12

Slide 13

Slide 13

Slide 14

Slide 14

Slide 15

Slide 15

Slide 16

Slide 16

You have “mental fuel”

Slide 17

Slide 17

Slide 18

Slide 18

Slide 19

Slide 19

Slide 20

Slide 20

Attention and Capacity Limits in Perception: A Cellular Metabolism Account × × × × BNIRS and oxCCO Cellular Metabolism as Mental Fuel Finite Energy Supply High Load Mode vs Low Load Mode 20

Slide 21

Slide 21

Which system do we use for co d ing? x x x x x Fast Intuitive Automatic Emotional Cheap and Eager x x x x x Slow Analytical Controlled Logical Expensive and Lazy

Slide 22

Slide 22

Slide 23

Slide 23

Slide 24

Slide 24

effortless

Slide 25

Slide 25

Slide 26

Slide 26

Slide 27

Slide 27

27

Slide 28

Slide 28

public class DiscountCalculator { public static void main(String[] args) { calculateDiscount(100, 15); } public static void calculateDiscount(double price, double discount) { double finalPrice = price - (price * discount / 100); System.out.println(“The final price after a ” + discount + “% discount is: ” + finalPrice); } }

Slide 29

Slide 29

How Many Triangles?

Slide 30

Slide 30

public class TaxCalculator { public static void main(String[] args) { calculateTax(100, 5); } } public static void calculateTax(double amount, double taxRate) { double totalAmount = amount + (amount * taxRate); System.out.println(“The total amount with tax: ” + totalAmount); }

Slide 31

Slide 31

The problem: × You deplete your fuel by contextswitching × You’re not in the flow because of context-switching × Loose-loose: you need more fuel needed, but you have less fuel

Slide 32

Slide 32

Slide 33

Slide 33

When we are tired, we produce worse code × “Developers are cutting corners on quality when fatigued.” (duh)

Slide 34

Slide 34

Slide 35

Slide 35

But We don’t know when to qu x x x it Parole Judges issued fewer paroles when tired and/or hungry Granting parole requires System 2 The Judges didn’t realize they had switched to System 1

Slide 36

Slide 36

Real-life outcome: you run on system one x x x x x Fast Intuitive Automatic Emotional Cheap and Eager x x x x x Slow Analytical Controlled Logical Expensive and Lazy

Slide 37

Slide 37

Slide 38

Slide 38

Which sucks less? Bad code “OK” code

Slide 39

Slide 39

The problem of “ok code” It looks “OK” to us System 1 It looks “OK” to PR review System 1 It looks “OK” to pipelines System 1

Slide 40

Slide 40

Next thing you know: You have an “ok” product

Slide 41

Slide 41

Invest in The goal: Running on System 2 all-day

Slide 42

Slide 42

Time Management Strategies × Time Blocking × Pomodoro Technique × Task Batching

Slide 43

Slide 43

Time blocking × Calendar everything × Separate work and personal × reclaim.ai

Slide 44

Slide 44

Mindfulness and Cognitive Pra ctices × Mindfulness and Meditation × Reflective Practices × Single-tasking

Slide 45

Slide 45

Workspace and Interruption M an agement × Workspace Organization × Notification Management × Prioritization Techniques

Slide 46

Slide 46

Physical and Mental Well-bein g × Physical Exercise × Breaks and Downtime

Slide 47

Slide 47

And… Developer productivity Engineering!

Slide 48

Slide 48

Developer Productivity Enginee Foster Faster Feedback Collaborate through Effective Tooling Eliminate Toil for Developers Dedicated Organizational Mindset ring Embrace Rigorous Observability for Proactive Improvement Prioritize Automation and Eliminate Bottlenecks Outcomes Over Output

Slide 49

Slide 49

feedback efficiency × × × × IDE: Sub-seconds (I type, it marks it red) Build: Seconds CI: Minutes Production: Hours/Days

Slide 50

Slide 50

Reverse dependency on distance from developers IDE Build CI Feedback Time Faster Slower Distance from Developers Expected Production

Slide 51

Slide 51

Reverse dependency on distance from developers IDE Build CI Production Feedback Time Faster Slower Distance from Developers Expected Real

Slide 52

Slide 52

Two types of feedback x e.g., CI/CD x we never wait for it x results are distracting x e.g., build x we’ll wait for it in the flow x we’ll be pissed off when it’s slow

Slide 53

Slide 53

Reverse dependency on distance from developers IDE Build CI Feedback Time Faster Slower Distance from Developers Production

Slide 54

Slide 54

Reverse dependency on distance from developers Faster IDE Build CI Feedback Time Commit time synchronous asynchronous Slower Distance from Developers Production

Slide 55

Slide 55

“Faster foster feedback” saves Speeding up local build minimizes context switch Less context switch saves mental fuel mental fuel Run on System 2 all-day

Slide 56

Slide 56

How can we engineer less con tex × × × × × t switches? Measure local build times! Avoid building and testing what didn’t change Speed up what can’t be avoided Fight evil flaky tests! Watch your build like a hawk for degradations

Slide 57

Slide 57

What you can do today (for fr ee × × × × × ) Parallel local Local caching Remote caching* Build Scans Win Prizes (a.k.a. speed challenge)

Slide 58

Slide 58

What your company should pa y for × All the books (see shownotes) × Top development hardware × Develocity (or similar)

Slide 59

Slide 59

Learn more and try it today! × × × × Take the Gradle/Maven Speed Challenge Be DPE Agent of Change! Read the DPE Handbook Watch the DPE Summit videos x speaking.jbaru.ch

Slide 60

Slide 60

Slide 61

Slide 61