> Markdown version of [/videos/569-down-the-oregon-trail-with-functional-c?t=0](https://www.wearedevelopers.com/videos/569-down-the-oregon-trail-with-functional-c?t=0). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # Down the Oregon Trail with Functional C# The 1975 classic Oregon Trail was built on chaotic GOTO commands. Watch how recreating this retro game exposes the secrets to isolating side-effects in functional C#. - **Speakers:** Simon Painter - **Event:** WeAreDevelopers LIVE - **Published:** April 18, 2023 - **Duration:** 46:08 - **URL:** https://www.wearedevelopers.com/videos/569-down-the-oregon-trail-with-functional-c ## Summary The video explores the intersection of retro gaming and modern software architecture by walking through the recreation of the 1975 text-based classic, Oregon Trail, using functional C#. Transitioning from the historical origins of Timeshare BASIC—where unstructured commands like `GOTO`, imperative logic, and side-effect-heavy inputs ruled—the speaker illustrates the challenge of applying a declarative, stateless paradigm to an inherently stateful and IO-heavy application within the constraints of the C# language. To bridge this gap, the talk unpacks core functional programming principles, including immutability, higher-order functions, pure functions (referential transparency), and modern pattern matching. A central architectural theme introduced is the 'umbra and penumbra' metaphor: keeping the application's core logic purely functional (the solid umbra) while deliberately pushing necessary compromises, such as user inputs and indefinite looping, out to the application's edges (the fuzzy penumbra). Because C# lacks F#'s tail-call optimization, indefinite game loops using recursion risk stack overflow errors; therefore, the speaker encapsulates hidden `while` loops into custom functional extension methods like `IterateUntil` to maintain a declarative codebase. The implementation heavily leverages C# constructs such as `Func` and `Action` delegates, modern `switch` expressions, and custom Discriminated Unions (using a `Maybe` monad pattern) to explicitly handle unpredictable player input as safe, predictable states (`Text`, `Integer`, `Empty`, or `Error`). By injecting dependencies like time services and random number generators, the pure functional game engine remains completely unaffected by side effects, resulting in code that is highly robust and easily testable without mocking complex layers. Ultimately, developers learn that while 100% pure functional C# is impossible, structurally isolating side-effects yields highly predictable code. **Keywords:** functional c#, declarative programming, pure functions, referential transparency, higher-order functions, c# pattern matching, discriminated unions, maybe monad pattern, immutability architecture, handling i/o side effects, stateless application state, c# delegates, tail-call optimization limitations, legacy basic refactoring, c# switch expressions ## Chapters 1. **Functional programming principles and practical application in C#** (00:00) — An overview of declarative styles, immutability, pure functions, and managing state boundaries in C#. 1. **Historical context of the Oregon Trail migration route** (08:10) — The geographical and historical background of the 19th-century American migration route. 1. **The invention of BASIC and early timesharing terminals** (10:56) — How early timesharing computers and the BASIC language enabled the creation of accessible educational games. 1. **Deconstructing the original 1975 BASIC source code syntax** (19:36) — Deconstructing early BASIC syntax, line numbers, and reversed conditional logic in the original game. 1. **Managing side effects and unpredictable console user inputs** (22:01) — Wrapping unpredictable user interactions using discriminated unions to maintain pure functional paradigms. 1. **Handling indefinite loops with functional recursive patterns** (31:38) — Using extension methods and recursion to execute validation loops without imperative while iterations. 1. **Architecting a functional game engine state machine** (37:31) — Processing sequential game events and probability-driven mini-games through continuous object state transformations. 1. **Future text adventure conversions and functional programming extensions** (43:15) — Adapting functional design patterns for upcoming conversions of classic text-based adventure games. ## Related Moments - [Introduction to functional programming concepts in C++](https://www.wearedevelopers.com/videos/1409-functional-programming-in-c) (from "Functional Programming in C++") - [Core functional principles and basic Phel syntax demonstration](https://www.wearedevelopers.com/videos/791-phel-a-native-lisp-for-php) (from "Phel, a native Lisp for PHP") - [Teaching foundational programming concepts through game development projects](https://www.wearedevelopers.com/videos/1761-wearedevelopers-live-frontend-inspirations-web-standards-and-more) (from "WeAreDevelopers LIVE – Frontend Inspirations, Web Standards and more") - [Exploring esoteric programming languages and unconventional input methods](https://www.wearedevelopers.com/videos/1730-wearedevelopers-live-accessibility-isn-t-magic-longevity-devrel-in-times-of-ai-and-more) (from "WeAreDevelopers LIVE - Accessibility isn't magic, Longevity, Devrel in times of AI and more") - [Defining the core principles of functional programming](https://www.wearedevelopers.com/videos/408-a-guide-to-functional-programming) (from "A Guide To Functional Programming") - [Avoiding state and side effects in code](https://www.wearedevelopers.com/videos/706-f-path-to-functional-enlightenment) (from "F#, path to functional enlightenment") ## Related Articles - [Dev Digest 118 - not a total recall](https://www.wearedevelopers.com/magazine/452-dev-digest-118-not-a-total-recall) - [Dev Digest 136 - No JS(on) of mine](https://www.wearedevelopers.com/magazine/482-dev-digest-136-no-js-on-of-mine) - [Using Java 17 latest features in real world projects](https://www.wearedevelopers.com/magazine/121-using-java-17-latest-features-in-real-world-projects) - [Dev Digest 130 - The Diablo is in the details](https://www.wearedevelopers.com/magazine/470-dev-digest-130-the-diablo-is-in-the-details) ## Related Jobs - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/15942-senior-software-engineer) at **GitHub** - [Senior Software Engineer, Client Apps Platform](https://www.wearedevelopers.com/jobs/ext/1773893-senior-software-engineer-client-apps-platform) at **GitHub** - [Principal Software Engineer, Identity](https://www.wearedevelopers.com/jobs/ext/1469181-principal-software-engineer-identity) at **GitHub** - [iOS Engineer, Swift/SwiftUI/Combine (B2C Broker)](https://www.wearedevelopers.com/jobs/ext/1611832-ios-engineer-swift-swiftui-combine-b2c-broker) at **Bitpanda** - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/159190-senior-software-engineer) at **GitHub** - [Principal Software Engineer, Enterprise AI Platform](https://www.wearedevelopers.com/jobs/ext/1467292-principal-software-engineer-enterprise-ai-platform) at **GitHub**