From 70827fe44d6844528e7dd56637de2f0f3e0cf847 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 1 Aug 2020 17:25:39 +0530 Subject: update irc nick, publish post --- posts/gripes_with_go.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'posts/gripes_with_go.md') diff --git a/posts/gripes_with_go.md b/posts/gripes_with_go.md index 60aabc8..9bcaabc 100644 --- a/posts/gripes_with_go.md +++ b/posts/gripes_with_go.md @@ -166,12 +166,27 @@ employed by Rust as well: // 1. error handling is compulsory // 2. errors are propagated with the `?` operator fn foo() -> Result { - let mut f = File::open("foo.txt")?; // return here if error + let mut f = File::open("foo.txt")?; // return if error let mut s = String::new(); - f.read_to_string(&mut s)?; // return here if error + f.read_to_string(&mut s)?; // return if error - Ok(s) // all good, return the value inside a `Result` context + Ok(s) // all good, return a string inside a `Result` context +} + +fn main() { + // `contents` is an enum known as Result: + let contents = foo(); + match contents { + Ok(c) => println!(c), + Err(e) => eprintln!(e) + } } ``` +### Conclusion + +I did not want to conclude without talking about stylistic +choices, lack of metaprogramming, bizzare export rules, but, +I am too busy converting my `interface{}` types into actual +generic code for Go v2. -- cgit v1.2.3