Skip to content

Instantly share code, notes, and snippets.

@danielrbradley
Last active January 1, 2017 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielrbradley/dd9d7085d4022685ac390999e01c234f to your computer and use it in GitHub Desktop.
Save danielrbradley/dd9d7085d4022685ac390999e01c234f to your computer and use it in GitHub Desktop.
Types instead of Hungarian notation
// Response to https://www.joelonsoftware.com/2005/05/11/making-wrong-code-look-wrong/
// How to use types in place of naming conventions
module Unsafe
// What different variations do we want to handle?
type Encodable =
| Safe of string
| Unsafe of string
// Wrap our Request method to always mark the output as unsafe
let request (key : string) =
Unsafe(Request(key))
// Wrap our Write method to handle escaping.
let write (encodable : Encodable) =
match encodable with
| Safe str -> Write(str)
| Unsafe str -> Write(Encode(str))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment