pseudo-python icon indicating copy to clipboard operation
pseudo-python copied to clipboard

No error handling for Go

Open ns-cweber opened this issue 8 years ago • 3 comments

Compiling the following program to Go produces no error handling logic:

import sys

print(int(sys.argv[1]))
package main

import (
	"strconv"
	"os"
	"fmt"
)

func main() {
	_int, _ := strconv.Atoi(os.Args[1]) // error handling missing
	fmt.Println(_int)
}

When we go run foo.go "not_an_int", the program prints 0 and exists successfully. When we python3 foo.py "not_an_int", we see:

Traceback (most recent call last):
  File "foo.py", line 3, in <module>
    print(int(sys.argv[1]))
ValueError: invalid literal for int() with base 10: 'not_an_int'

ns-cweber avatar Jan 09 '17 17:01 ns-cweber

That's right, a middleware that implements Go-style error checks was in the works, however currently that's not implemented.

As a whole this projects is currently on hold: I am currently focused on my job and different projects. I'll probably finish a more stable new version if there is any interest in it. (The people interested in this project had vastly different usecases/wishes for its functionality so I decided to wait for a compelling usecase)

alehander92 avatar Jan 09 '17 18:01 alehander92

Fair enough. I'm certainly interested in this project. I'm contributing to Grumpy (a Python runtime in Go) which aims to support most of Python2.7 in all its dynamic glory, but it does so by compiling everything into a Go *Object struct. Ideally, I would like a hybrid approach, which compiles to idiomatic Go whenever provably possible, falling back to dynamic *Objects when not. This is well outside the scope of this project and probably not feasible, but I'm sure I can learn a lot toward that end by following this project.

ns-cweber avatar Jan 09 '17 21:01 ns-cweber

That's a very nice idea, but you're right, it's outside the scope of this project. Grumpy is pretty interesting, I wonder if somebody is building a Ruby runtime on Go too.

alehander92 avatar Jan 10 '17 15:01 alehander92