diff options
author | Akshay <[email protected]> | 2020-08-01 12:55:39 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-08-01 12:55:39 +0100 |
commit | 70827fe44d6844528e7dd56637de2f0f3e0cf847 (patch) | |
tree | 17fd0215faa06d1583321a298047dd19c9567087 /posts | |
parent | 6dc5eb710c27a3fee4a132763c106c5ce16f72ab (diff) |
update irc nick, publish post
Diffstat (limited to 'posts')
-rw-r--r-- | posts/gripes_with_go.md | 21 |
1 files changed, 18 insertions, 3 deletions
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: | |||
166 | // 1. error handling is compulsory | 166 | // 1. error handling is compulsory |
167 | // 2. errors are propagated with the `?` operator | 167 | // 2. errors are propagated with the `?` operator |
168 | fn foo() -> Result<String, io::Error> { | 168 | fn foo() -> Result<String, io::Error> { |
169 | let mut f = File::open("foo.txt")?; // return here if error | 169 | let mut f = File::open("foo.txt")?; // return if error |
170 | let mut s = String::new(); | 170 | let mut s = String::new(); |
171 | 171 | ||
172 | f.read_to_string(&mut s)?; // return here if error | 172 | f.read_to_string(&mut s)?; // return if error |
173 | 173 | ||
174 | Ok(s) // all good, return the value inside a `Result` context | 174 | Ok(s) // all good, return a string inside a `Result` context |
175 | } | ||
176 | |||
177 | fn main() { | ||
178 | // `contents` is an enum known as Result: | ||
179 | let contents = foo(); | ||
180 | match contents { | ||
181 | Ok(c) => println!(c), | ||
182 | Err(e) => eprintln!(e) | ||
183 | } | ||
175 | } | 184 | } |
176 | ``` | 185 | ``` |
177 | 186 | ||
187 | ### Conclusion | ||
188 | |||
189 | I did not want to conclude without talking about stylistic | ||
190 | choices, lack of metaprogramming, bizzare export rules, but, | ||
191 | I am too busy converting my `interface{}` types into actual | ||
192 | generic code for Go v2. | ||