Coding Fast and Slow

Prof. Daniel Kahneman Mar 5, 1934 – Mar 27, 2024

“for having integrated insights from psychological research into economic science, especially concerning human judgment and decision-making under uncertainty”

Economics? × × × × ECON101: People are rational; that’s why markets work. - Nope, they aren’t; here’s 50 years of study. - Oh, wow, they really aren’t. It probably has a profound effect on economics! Here’s a Nobel Prize for ya! ECON101: People are rational; that’s why markets work.

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

How much does the ball cost? 0.10 + (1.00+0.10) = 1.20 0.05 + (1.00+0.05) = 1.10

Baruch Sadogursky - @jbaru ch × Head of DevRel at TuxCare (I am hiring!) × Developer Productivity Nerd × Development -> DevOps -> #DevProd

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

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

Wait, let’s think about that! I recognize this pattern!

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()); } }

You have “mental fuel”

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

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

effortless

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); } }

How Many Triangles?

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); }

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

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

But We don’t know when to qu x x x x it Default parole decision: deny Fewer paroles when judges are tired/hungry Granting parole needs System 2 thinking Judges unaware of switching to System 1

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

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

× × × × × 10,000 hours of practice mov e some system 2 activities to sy stem 1 Driving Golf Tennis Music playing Safety drills for fire fighters

Wait, let’s think about that! I recognize this pattern!

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

Which sucks less? Bad code “OK” code

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

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

Invest in The goal: Have enough mental fuel to last all day

Time Management Strategies × Time Blocking × Pomodoro Technique

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

× Block time × Batch tasks × Allow access

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

Workspace and Interruption M anagement × Workspace Organization × Notification Management × Prioritization Techniques

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

Caffeine nap Drink caffeine Dark, cold, quite room Set alarm to 20 minutes Reserves taped!

Coding practices × Automate everything × Shorten feedback loops × Delegate to tools!

Use AI smartly! Right tool – right job Not all tools are created equal. Go deep, not wide ATM specialized beats generalized Local ai = control Better control and privacy.

Agentic AI is RAD if it does the right thing

Coding practices × × × × Automate everything Shorten feedback loops Delegate to tools! Delegate to pros!

when to delegate No Is it easy to learn? Do you have time to learn it? Delegate! Is the task your core expertise? No No Yes Yes Yes Learn it! Do it!

Save mental fuel! × × × × × Time management Workspace management Mental wellbeing Engineer fewer interruptions Delegate when needed

THANKS! Q&A and Twitter X/Bsky/Mastodon/LinkedIn ads: x @jbaruch x @Geecon x speaking.jbaru.ch