Giter VIP home page Giter VIP logo

better-go's Introduction

The Go Programming Language + try + unwrap

Go with slightly better error handling primitives. Checkout the demo directory.

try

try sugar

content, err := ioutil.ReadFile(filename)
try err or string

try desugared

...
if err != nil {
    return make([]string, 1)[0], err
}

The try statement expects two values.

  1. the error variable
  2. the type of the return value (this is needed because go has this convention of returning the zero value of a type incase of an error)

unwrap

unwrap sugar

fileContent, err := readFile("sample.txt")
unwrap err

unwrap desugared

...
if err != nil {
    panic(err)
}

The unwrap statement expects one value, the error variable.

bababooey

just like try but this doesn't need a type

content, err := ioutil.ReadFile(filename)
bababooey err

bababooey desugared

...
if err != nil {
    return nil, err
}

The bababooey statement expects one value, the error variable.

<<<

sugar for append

numbers := []int{1, 2, 3}
numbers = append(numbers, 4)

append desugared

numbers := []uint{1, 2, 3}
@numbers <<< 4

How to run it

nix develop
cd src
./make.bash

better-go's People

Contributors

rsc avatar griesemer avatar robpike avatar ianlancetaylor avatar bradfitz avatar aclements avatar mdempsky avatar randall77 avatar cherrymui avatar josharian avatar adg avatar minux avatar dvyukov avatar alexbrainman avatar cixtor avatar cuonglm avatar tklauser avatar thanm avatar mknyszek avatar findleyr avatar agl avatar ken avatar davecheney avatar dr2chase avatar nigeltao avatar mvdan avatar filosottile avatar crawshaw avatar 4a6f656c avatar prattmic avatar

Stargazers

Josseph avatar Brook Mezgebu avatar Ezira Ashenafi avatar Dagim G. Astatkie avatar DGCP3 avatar Fraol Lemecha avatar Yohannes Tezera avatar Kaleb avatar

Watchers

Fraol Lemecha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.