'Is there a Golang terminal shell? Is it possible for a compiled language? [duplicate]
Recently I'm interested in Golang.
When I was learning Python I kicked off a terminal shell and just practised throwing it different data, files, making many trivial silly operations, it's such a nice way to interact with a new language and it's super helpful for writing new programs.
I wonder- I guess because Golang is a compiled language like Java it's not possible to have such a terminal shell. Is that right? If so- what's the real technical reason why it can't work?
Solution 1:[1]
I felt the same way when I first started using golang having used Python for years. I have since decided that for anything beyond trivial coding (which can be done on the go playground) I end up writing a script for anyways and it's really not much harder to add in the boiler plate stuff.
The key I believe is that Go compiles fast enough that I think most people haven't really noticed an issue with just recompiling and running the entire program to see their changes.
You are right though, Go is compiled. This is fundamentally different than say Java or Python which both use Virtual Machines to generate code which it then executes. You can't run a Java program or Python program without the JVM or Python interpreter respectively. A go program on the other hand once compiled can be distributed directly with no dependancies, one reason that many people love it for deployment.
Solution 2:[2]
Take a look at gomacro
go get -u github.com/cosmos72/gomacro
~ $ gomacro
// GOMACRO, an interactive Go interpreter with generics and macros
// Copyright (C) 2018-2019 Massimiliano Ghilardi <https://github.com/cosmos72/gomacro>
// License MPL v2.0+: Mozilla Public License version 2.0 or later <http://mozilla.org/MPL/2.0/>
// This is free software with ABSOLUTELY NO WARRANTY.
//
// Type :help for help
gomacro> import "fmt"
gomacro> a := 10
gomacro> fmt.Println(a)
10
3 // int
<nil> // error
gomacro>
Solution 3:[3]
Not a direct solution, but one thing to try is a Jupyter notebook with a Go kernel like https://github.com/gopherdata/gophernotes
While you'll be using the Jupyter browser interface instead of the terminal, you can still do terminal-like things like execute shell commands and tab-complete. I've found this useful when wanting to import a library I'm not familiar with and quickly trying its functions, for example.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Peter O. |
Solution 2 | Robert Ranjan |
Solution 3 | Daniel Nguyen |