Last active
January 1, 2017 09:12
-
-
Save danielrbradley/dd9d7085d4022685ac390999e01c234f to your computer and use it in GitHub Desktop.
Types instead of Hungarian notation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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