Skip to content

sammi-turner/Assorted-Golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 

Repository files navigation


Assorted-Golang

Golang examples and codewars katas.


Installation

Ben Davis has a nice video walk through on how to install Go and set up the path variable


Syntax primer

"Learn X in Y minutes" has a good introduction to Go


To run a single main.go file

go run main.go

To create a go.mod file for a project

go mod init name-of-project

To compile a project that has a go.mod file

go build

To run a project

./name-of-project

To compile and run a project

go build && ./name-of-project

Video course

The FreeCodeCamp YouTube channel has a lengthy beginners course to get you started.


AI Code Generation

Large Language Models (LLMs) are only effective for me because I don't trust their output.

I always test the code that they generate!

However, given that Go is a mature language, backed by Google, there is a suprising amount of training data available.


Function Generation With LLMs

I have had good results with prompts using the following template

Write a [name] function in Golang that takes
[name the parameters and their types] and returns
a [type] such that [describe what the function does].
Then show me the code.

Example of Program Generation with Chat-GPT4

I asked the LLM to generate a TUI (Text User Interface) todo app using the gorm ORM and sqlite.

In this conversation conversation with Chat-GPT I was given the basic functionality I needed.


Hacking the context window limit

Although feeding errors back to Chat-GPT4 can yield good results, sometimes a conversation will drag on so long that the LLM "forgets" what you are talking about and the chatbots answers rapidly become useless.

This is because of a fundamental limit built into the LLM. Namely the maximum size of its context window. The size of the context grows as the conversation progresses.

To avoid running up against this limit when you are working on a code generation task, simply delete the chat you are using, start a new one, attach the source code that needs fixing to the chat (the "Advanced Data Analytics" plugin should be enabled), tell the chatbot that there are syntax errors or unexpected behaviour and ask for its help.

This process can be repeated as often as necessary!


About

Golang examples and codewars katas.

Topics

Resources

Stars

Watchers

Forks