A Programmer's Guide To Go With Visual Studio Code |
Written by Mike James | ||||||
Monday, 08 July 2019 | ||||||
Page 1 of 5 Google's system programming language Go is becoming more mature and easier to use. Now is a good time to try it out with Visual Studio Code making it even easier. A Programmers Guide To LanguagesContents
There is an older version of this article which uses the LiteIDE instead of Visual Studio Code: A Programmer's Guide To Go With LiteIDE Part 1 Language Basics
Go is an easy-to-use but surprisingly powerful language. You could call it a modern version of C, but read on and find out what you think of it for yourself. It has a clean and simple structure that is said to be statically typed. but it behaves like a dynamically typed language. It also compiles to native code, but is as easy to work with as an interpreted language. The bottom line is that it's worth a look and this article tells you all you need to know to get started. In Part 2 we'll take a closer look at how Go deals with objects and concurrency. SetupAll you have to do to set up Go is to download the appropriate binary and extract it to the correct directory and set the Path to point to the location of the bin directory where all of the Go tools live. If you are using OSX or Windows then there are installers that you can use that will add the appropriate path. The Windows MSI installer works very well and it gives you an instantly working installation - I recommend using it. By default it installs the system in C:\Go
You can check that you have a working system by creating a simple program:
You can use NotePad or any plain text editor and save the file as hello.go. To run it you need to open a console and type:
There are all sorts of things that can go wrong with this procedure but all minor. The first is that if you use NotePad make sure that the file name is Hello.go and not Hello.go.txt. You will also have to either change directory to where the file is stored or enter the complete path to hello.go. Eventually however it should all work. Notice that it can take a few seconds to compile the program before you see the message. As an alternative you can move on to install Visual Studio Code and try running a program from there. An IDE isn't essential for creating Go programs and you will hear programmers saying that it isn't necessary - all you need is an editor. This is true but for the casual programmer an IDE makes getting started easier and once you use Visual Studio Code you will quickly find that it makes you much more productive. First you need to install Visual Studio Code. Just go to the web site https://code.visualstudio.com/ and use the installer. Next install the GitHub app: This isn't needed for the general use of Visual Studio Code but it is needed as part of the installation of the Go tools. Run Visual Studio Code and select Tools and Languages: In the list of tools on the left scroll down and select Go and install it:
Select the Explorer and click Open Folder and create a new folder called Go and select it. Next Select New File and create Hello.go. The go extension automatically loads the Go editor and you can now type in your program with Intellisense help:
You can run the program using the Debug menu command. While you are doing all this you will see warnings pop-up that there are commands that are not installed. You should click the Install button that appears in the bottom right and wait while the command is installed - it can take a few minutes. When everything is installed and you no longer see the warnings your program should run and its output will be in the Debug Console Window:
If this doesn't work the only possibilities are that you haven't installed the GitHub app or the Go tools. |
||||||
Last Updated ( Monday, 08 July 2019 ) |