DEV Community

Chris Riddick
Chris Riddick

Posted on

My Experience Learning Go, next steps

I recently posted about my efforts to learn Go and GUI development in Go here. This post is about the next steps in my learning process.

I was able to get a basic dashboard implemented and functioning using and a simple CPU simulator. You can see that in my git repo.

My next step was to find an existing CPU simulator implemented in Go and integrate my dashboard with it. Reading and understanding someone else's code is one of the best ways to learn a new language. Not only must you grasp the syntax and semantics of the language, but you also must decipher and learn the idioms and patterns used by the other programmer. Programming is as much an art as it is engineering, and reading and following someone else's coding is, to me, like walking through an art gallery and appreciating the nuances and techniques applied by each artist.

Much to my delight, I discovered a complete implementation of a 6502 CPU simulator written in Go. Not only did the project include a CPU simulator, but it included an assembler, disassembler, and utilities! The project I found, go6502, is so comprehensive that after only a few days working my way through the code, I was able to understand how almost everything worked together. The project is so well-done that I was able to integrate my dashboard without breaking any of the existing simulator code.

When a software engineer encounters code that is so well-written that it makes adding features a breeze, you have to tip your hat to the engineer for doing such a fine job. That is how I found this project. It was complex, but well-designed and built for flexibility. I was able to learn many new things about Go that were not obvious from reading the manuals and tutorials.


I created a fork of the go6502 project. Then, I added a folder for my dashboard package. I worked through updates to the go.mod files to make sure that I was pulling from my repo and not the original repo. That is one of the beauties of Go. Dependencies are much easier to work with than when I was doing Java development.

The primary hooks into the existing go6502 simulator were the bufio.Writer for terminal output and the Host object with a structure and associated functions to take commands from the GUI buttons. Using the Fyne widgets and callback functions, I was able to insert calls to the Host object, passing in command strings instead of sending them to the terminal. Output is redirected to a scrolling widget in the dashboard. New commands, replacing a command line function, are submitted using a data entry widget and submit button. The user determines whether or not to use the GUI at time of program startup by including a flag (-g) in the command. If the flag is absent, the program starts up in its usual terminal mode. If the flag is included, the dashboard is started and the program control is handed off to the GUI. Termination of the program is by an Exit button instead of a command line quit statement.

Sometimes it is hard to know if a program is still running or if it is hung up in an error loop. So, I added a goroutine that updates a clock display every second. That way a user can see the program is still running and not frozen. It also helps someone understand how goroutines and channels make concurrent processing in Go easy.

There is still much to learn from this. I need to add a file picker to allow a user to select a file from the file system to assemble and load. Currently, the program looks for a sample file in the current directory to load. I want to learn if I can use the terminal themes that Vickers incorporated in the terminal code to customize the look of the GUI dashboard. In many ways, is comprehensive and cross-platform, but it is new enough that there isn't a lot of examples to use on which to build your own code. Next steps will explore this further.

Finally, I plan to experiment with the go6502 code to see if I can create my own instruction set and replace the 6502 with a different CPU. The Vickers code seems designed for that purpose. Learning Go this way has been a blast!

Top comments (0)