45 ms·
The Icon programming language has a nice error handling style that reminds me of Go's local error handling but with less boilerplate. Functions can return succe
by cpeterso 8y ago
The Icon programming language has a nice error handling style that reminds me of Go's local error handling but with less boilerplate. Functions can return success/failure along with the actual return value, like an implicit Maybe/Option type.
Converting the article's example code from Go:
f, err := os.Open("file.txt")
if err != nil {
// handle error here
}
to pseudo-Icon:
if f := os.Open("file.txt") then
read(f)
else
handle error here
https://en.wikipedia.org/wiki/Icon_(programming_language) https://en.wikipedia.org/wiki/Icon_(programming_language)
- scns 8y agoiirc it works like that in swift: if let file = os.Open(file) { do sth } else { handle error }