Avoid typing hundreds of if error checks

Written by
Link to Post

https://www.reddit.com/r/golang/comments/by9tos/avoid_typing_hundreds_of_if_error_checks/ by 

I wanted to alert anyone that might not know modern editors include “snippet” support. Very seldom have I ever actually written if err != nil { ... } because my editor always writes it for me. Just hit three keys: i + e + t and continue on.

VSCode:

"if err != nil": { "prefix": "ie", "body": "if err != nil {nt${0}n}", "description": "if err != nil" },

Atom:

'if err != nil': 'prefix': 'ie' 'body': ''' if err != nil { $0 } '''

vim-go

“`

error snippet

snippet ie “if err != nil” !b if err != nil { ${0} } endsnippet “`

“ie” = [i]f [e]rror and makes me laugh and think of “Internet Explorer”

It’s worth noting that you can run with this idea and actually create a whole army of snippets for any type of error: t.Error(err), log.Fatal(err), return nil, err, etc…

Note, this isn’t a put down to the actual issue of verbosity, just an immediate band-aid for those annoyed by it.

submitted by /u/Xeoncross
[link] [comments]

Article Tags:
· ·
Article Categories:
reddit

Leave a Reply