Simon Painter

Down the Oregon Trail with Functional C#

What if the Oregon Trail's messy GOTO logic could become a clean, monadic pipeline? See how functional C# transforms a classic game into modern, testable code.

Down the Oregon Trail with Functional C#
#1about 5 minutes

Core principles of the functional programming paradigm

Functional programming is a declarative style emphasizing immutability, pure functions, and expressions over statements to write more testable and robust code.

#2about 2 minutes

Applying the umbra and penumbra metaphor to C#

Achieve nearly pure functional code by isolating necessary compromises, like I/O, to the outer edges (penumbra) of the application.

#3about 3 minutes

The historical context behind the Oregon Trail game

The game is based on the 19th-century migration of settlers in covered wagons from the US East Coast to Oregon.

#4about 7 minutes

How BASIC and time-sharing enabled interactive games

The creation of the user-friendly BASIC language and time-sharing terminals at Dartmouth University led to a boom in early computer games.

#5about 4 minutes

Analyzing the original 1975 Oregon Trail BASIC code

The original game's logic is built on line numbers, GOTO statements, and reversed IF conditions, which requires careful translation.

#6about 11 minutes

Handling impure user input with discriminated unions

Manage the side effects of console input by wrapping results in a `Maybe` type, a discriminated union representing `Something`, `Nothing`, or `Error` states.

#7about 5 minutes

Replacing indefinite loops with a functional helper

Avoid imperative `while` loops for input validation by using a recursive `iterate until` helper function that encapsulates the looping logic.

#8about 2 minutes

Structuring the main game loop with a monadic flow

Chain game events together using a `continue game` extension method that checks the game state before executing the next function, simplifying the main loop.

#9about 1 minute

Recreating the time-based hunting mini-game functionally

Implement the time-sensitive "type BANG" mechanic by injecting a time service to enable pure, testable functions for calculating shot accuracy.

#10about 3 minutes

Refactoring complex conditional logic with switch expressions

Replace the original game's convoluted, nested IF statements for rider encounters with a clean and readable C# switch expression.

#11about 3 minutes

Exploring other classic text-based games to remake

Consider other classic text-based games like Star Trek, Doctor Who, and Zork as potential future projects for functional programming exercises.

Related jobs
Jobs that call for the skills explored in this talk.

Featured Partners

Related Articles

View all articles
BR
Benjamin Ruschin
What Developers Really Need to Create Great Code Demos
Every developer on earth has, at some point, had another developer to thank for a breakthrough, a success, an aha moment they wouldn’t have had without coming across that blog post, that open-source contribution, that reply on socials or that humble ...
What Developers Really Need to Create Great Code Demos
BR
Benjamin Ruschin
What Developers Can Learn from Indie Games
The beauty of the WeAreDevelopers World Congress is seeing developers from every corner of the industry come together and share their passion for programming. Back in summer 2025, at our Berlin World Congress, game legends John Romero (Doom, Quake) a...
What Developers Can Learn from Indie Games
DC
Daniel Cranney
Dev Digest 181: America Offline! Pay to code? And bad AI hackers…
Inside last week’s Dev Digest 181 . ☎️ AOL shuts down dial-up internet 🔥 Bot-only social media platform immediately goes to war 🤑 Is the future pay to code? ⚠️ Path traversal vulnerability in Microsoft’s agentic web 🤷 Why is XSS still a thing? 🟪 The...
Dev Digest 181: America Offline! Pay to code? And bad AI hackers…

From learning to earning

Jobs that call for the skills explored in this talk.

Rust and GoLang

Rust and GoLang

NHe4a GmbH
Karlsruhe, Germany

Remote
55-65K
Intermediate
Senior
Go
Rust
Gameplay Programmer

Gameplay Programmer

Parable Studios

Remote
26-28K
Intermediate
C++
Python
Unreal Engine
+1