mj's Logbook

Tag: programming remove

Choosing an Error Handling Strategy

From Real World OCaml. The whole page on error handling is good, but I’m mostly interested in Exceptions vs explicit Result/Error types:

Given that OCaml supports both exceptions and error-aware return types, how do you choose between them? The key is to think about the trade-off between concision and explicitness.

Exceptions are more concise because they allow you to defer the job of error handling to some larger scope, and because they don’t clutter up your types. But this concision comes at a cost: exceptions are all too easy to ignore. Error-aware return types, on the other hand, are fully manifest in your type definitions, making the errors that your code might generate explicit and impossible to ignore.

The right trade-off depends on your application. If you’re writing a rough-and-ready program where getting it done quickly is key and failure is not that expensive, then using exceptions extensively may be the way to go. If, on the other hand, you’re writing production software whose failure is costly, then you should probably lean in the direction of using error-aware return types.

To be clear, it doesn’t make sense to avoid exceptions entirely. The maxim of “use exceptions for exceptional conditions” applies. If an error occurs sufficiently rarely, then throwing an exception is often the right behavior.

Also, for errors that are omnipresent, error-aware return types may be overkill. A good example is out-of-memory errors, which can occur anywhere, and so you’d need to use error-aware return types everywhere to capture those. Having every operation marked as one that might fail is no more explicit than having none of them marked.

In short, for errors that are a foreseeable and ordinary part of the execution of your production code and that are not omnipresent, error-aware return types are typically the right solution.

programming ocaml advice

3 years ago

Tools for Thought

Tools For Thought by Howard Rheingold

books programming technology

3 years ago

Git Flight Rules

git programming

3 years ago

Bevy

A data-driven game engine for Rust.

programming gamedev rust gameengine

3 years ago

PostgreSQL Exercises

postgres tutorial programming database

3 years ago

Rust Resources

rust programming

3 years ago

Elegant Library APIs in Rust

rust programming

3 years ago

Introduction to Networked Physics

gamedev games programming network

3 years ago

Gerbil Scheme

“Gerbil is a meta-dialect of Scheme with post-modern features”

programming scheme lisp language

3 years ago

Learn ClojureScript

A ClojureScript book

clojurescript clojure books programming

4 years ago

Nand Game

Build a game out of nand gates.

programming cs games tutorial

4 years ago

Processing Sphere

processing programming

4 years ago

How to Manage HTML DOM with Vanilla JS

html programming javascript

4 years ago

Pixel Vision 8

A fantasy console with a more graphical bent and swappable constraints.

pv8 retro fantasy console games programming

4 years ago

Voxel Space

Terrain rendering algorithm in less than 20 lines of code.

gamedev programming cs

4 years ago

Algorithms Illuminated

Contains video links to Youtube videos.

programming algorithms video

5 years ago

BYTEPATH: A tutorial on making a game in Love 2D

games programming lua love toread gamedev

5 years ago

Braid: An ML-like language that compiles to Go

I’d really like for something like this to be production-ready.

ml golang programming languages

5 years ago

Generative Artistry

Interactive tutorials by Tim Holman on making generative art using JS.

javascript art generative art programming

5 years ago

The Total Beginner's Guide to Game AI

games programming ai gamedev

5 years ago