Skip to main content
00:00/00:00
Lecture 30 of 79

The First Law of Defensive Programming

Download Course (Free)

Course Content

0 / 79 completed
Section 1: Dismissing Defensive Code by Avoiding Primitive Types10 videos

The Reasons to Avoid Enumerations

7m

Alternatives to Enumerations

3m

Converting Enumeration to a Class

11m

The Reasons to Never Stringify Data

12m

Reaping the Benefits of String Encapsulation

7m

Avoiding Primitive Types Altogether

2m

Example - Modeling Money

5m

Persistence - Small-scale CQRS and DDD

4m

Demonstrating Persistence

10m

Summary

2m
Section 2: The Principle of Working with Objects, Not with Nulls9 videos

Understanding the Role of Null

5m

Why Compilers Still Rely on Null

5m

Using Callback on Optional Content

6m

Overloading Existing APIs to Never Return Null

7m

Returning an Optional Object

9m

Implementing Custom Option Type

9m

Consuming the Option

12m

Persistence - Creating Complex Domain Objects

10m

Summary

2m
Section 3: Course Overview1 videos

Course Overview

1m
Section 4: Designing Alternative Workflows Instead of Defending from Errors9 videos

What’s Wrong with Status Codes

6m

Understanding Effects of Throwing Exceptions

5m

What Exceptions Are Not Meant to Do

8m

Leave Nothing Exceptional in Exceptions

11m

Returning a Polymorphic Type Instead of an Excep

8m

Separating Positive and Negative Return Values

9m

Inventing the Either Type

10m

Consuming the Either Type

5m

Summary

3m
Section 5: Understanding Limitations of Traditional Defensive Code8 videos

The First Law of Defensive Programming

5mNow Playing

Version Check

1m

What Follows in This Course

8m

Traditional Defensive Techniques

4m

Defensive Design - An Experiment

7m

Called Method Cannot Defend

5m

Defining Function Domains

4m

Summary

2m
Section 6: Removing Corruption by Only Creating Consistent Objects7 videos

Creating Objects

3m

Creating Consistent Objects

4m

Pros and Cons of Multiple Constructors

11m

Understanding Limitations of the Constructor

4m

Promoting Constructor into Builder

4m

Variations in the Builder Implementation

11m

Summary

3m
Section 7: Removing Corruption by Only Making Valid State Transitions9 videos

Reaping the Benefits of Constructor Validation

9m

Defending in Property Setters

8m

Understanding Distinct Kinds of Properties

3m

Defending in Complex Mutations

10m

Function Domains Revisited

5m

When Constructor Depends on Multiple Objects

6m

Creating Objects in Small Steps

5m

Persistence and Parameterized Constructors

5m

Summary

2m
Section 8: Defining Function Domains as the Primary Line of Defense9 videos

Introducing Guard Clauses

5m

Guarding Against Null Only

7m

Dont Guard Business Rules

14m

Removing Guards Through Design

12m

Turning Domain Rules into Rule Objects

5m

Turning Rule Objects into Active Elements

12m

Completing the Students Filter

10m

Persistence - Querying View Models

14m

Summary

2m
Section 9: Building Defensive Design Instead of Writing Defensive Code8 videos

Encapsulating State

8m

Keeping Related Data Together

10m

Turning Chained Ifs into the Chain of Rules

9m

Making Friends with Regular Expressions

4m

Replacing Branching with Regular Expressions

13m

Moving Expressions out to Configuration

11m

Persistence - Creating and Updating Domain Objects

16m

Summary

2m
Section 10: Building Rich Domain Model as an Effective Defense by Design9 videos

Reconsidering Immutable Objects

12m

Turning Classes Immutable

6m

Avoiding Aliasing Bugs Altogether

10m

The Downside of Immutability

9m

Constrained Mutability with Set-once Properties

9m

Consuming Semi-mutable Objects

8m

Using Historical Model

6m

Implementing Simple Historical Model

18m

Summary

3m