Skip to content

proposal: Go 2: simplify error handling and simplify conditions processing and "?" pipe operation symbol #39148

Closed
@enddeadroyal

Description

@enddeadroyal

1.Simplify error handling:
for example (reference to rust)
old(go 1.12):

dat,err := ioutil.readFull("Go Programming.pdf")
if err != nil {
   log.error(err.Message())
   return err
}

OR

if dat,err := ioutil.readFull("Go Programming.pdf");err != nil {
   log.error(err.Message())
   return err
}

expect:

dat := ioutil.readFull("Go Programming.pdf") ? err =>  log.error(err.Message())

OR

dat := ioutil.readFull("Go Programming.pdf") ? err => {
     log.error(err.Message())
     return err
}

when err is nil, don't do err expression

2 Simplify Conditions Process
old(go 1.12):

dat,err := ioutil.readFull("Go Programming.pdf")
_,ok := err.(os.Err)
if ok {
 //do something
}
_,ok := err.(file.NotFindErr)
if ok {
 //do something
}

expect:

switch err => {
    os.Err, io.Err: =>    //do something
    file.NotFindErr:=> {
            //do something
     }
}

when 1 and 2 use at the same time

dat := ioutil.readFull("Go Programming.pdf") ? err => {
   switch err => {
     os.Err, io.Err:=>    //do something
     file.NotFindErr:=> {
            //do something
      }
    }
}

OR

dat := ioutil.readFull("Go Programming.pdf") ? switch err => {
    os.Err, io.Err:=>    //do something
    file.NotFindErr:=> {
            //do something
    }
}

"?" operation symbol is was used as a pipe which concat expressions
like as linux "|" operation symbol

netstat -an | grep 8080

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions