Golang Playground for Practice
The Golang Playground, available on the go.dev, offers a hassle-free solution for practising and learning Golang. This web service enables developers to write, format, compile, and run Golang programs in a secure environment, eliminating the need for complex setups. Introduced in September 2011, it allows users to execute Go code instantly via a modern web browser. Experienced Go users can also experiment with code conveniently. Visit go.dev to access the Golang Playground. Check out the portal's appearance below.
You can visit go.dev to access Golang Playground. Below is a view of what the portal looks like.
How to Use it?
Now that we know what is Golang Playground, We will create a simple Go program to do the addition of two numbers. We will be using the Golang Playground to write our code.
-
Open Golang Playground on your favorite browser.
-
Once the portal is visible. Paste the below code in the editor section. The code instantiates 3 integer variables, adds two of them, and assigns the output to the third variable. This variable is then printed in the console using the fmt go package.
- Lastly, click on the Run button to execute the code. You can see the output in the console of Golang Playground.
Click on the link to visit our Playground :
Executable Examples: From the drop-down select different programs
Apart from writing custom development code, Golang Playground provides multiple pre-written examples for our reference. To access these executable programs jump on the Golang Playground webpage, And select any program that you want to explore.
Once you selected a given item from the drop-down, Its respective code will be in the editor section. run the code and the output will be displayed in the Playground console.
Below is an example for Display Image.
Offline Playground
Golang playground at go.dev is a great idea for experimenting and trying code. It does not require any setup nor does it have any restrictive environment which can damage your machine. It has many drawbacks that we will discuss in the later part of the article. Emacs offers many such tools for Go development so it is the most comfortable playing with Golnag code. Of course, a local playground requires you to set up a Go environment but if you developing in Go you are anyway would need to set up go-mode and helper tools for comfortably working with code. Visit the local playground to understand it more Thoroughly.
Features
- It works with all the go plugins installed.
- The playground files saved are saved under GOPATH which helps to keep track of previous codes.
- It could split the code into an arbitrary number of files.
- It could import any external packages from your GOPATH.
- It uses vendored packages in your snippet directory.
Limitations Using Go Playground
- The Golang Playground can use most of the standard libraries, But for communication in Playground code and the developer, it should be only done in standard I/O and errors.
- There are limits to the amount of memory and the execution time for a program. Hence, we can't run programs that are resource heavy.
- The time in Golang Playground begins at 2009–11–10 23:00:00 UTC. This is done to give a reliable and deterministic output.
Conclusion
Golang Playground provides a great starting point in the journey of learning golang. It helps the developer to write and test programs without changing any local configuration. The Playground also provides programs for basic problem statements that we can directly use.