GoLand
It is a visitor put up from John Arundel, a Go author and trainer who runs a free e-mail course for Go learners. His most up-to-date e book is The Deeper Love of Go.
Ahoy, maties! Cap’n Lengthy John Arundel right here with extra tips about crusing the great ship GoLand. This time, we’ll lay aloft to the crow’s nest and switch our spyglass on Junie, the JetBrains AI coding agent.
In case you’re new to Junie and AI instruments, and aren’t certain the place to begin, consider this as your treasure map to the hidden gold of GoLand productiveness. Arrr you prepared to begin coding like a pirate?
Flying the black flag
Your first voyage with AI improvement instruments could be a perilous one, veering from calm seas of code to storms of syntax errors and check failures. So, will your AI agent be a trusty first mate, or simply an unpredictable stochastic parrot squawking nonsense out of your shoulder?
Junie is fairly good, and she will be able to sort out any job you select, however she wants the steerage of a great cap’n. That can assist you keep on the right track, I’ve put collectively a useful six-step workflow I prefer to name “Code like a PIRATE”. Aye, ‘tis one other o’ my made-up acronyms—however ye’ll discover it simple to recollect, me hearties [Are we doing the pirate thing for the whole article?—Anna]
“P” is for Plan
Each good voyage begins with a map. Whenever you set Junie a job, inform her the place the ship’s headed, so she’ll know which path to steer. (I’m certain Junie gained’t thoughts me calling her “she”; enjoyable reality, a lot of pirates had been girls—together with fairly just a few of the lads).
Ask Junie to attract up a fast chart for the voyage, however to not set sail till you’ve authorized it:
Arr, Junie, me fantastic lass. I’m a swashbuckling pirate cap’n who wants a Go program to assist me share out the booty from my newest captured Spanish galleon. Don’t code something but, however present me a quick plan of how the instrument would possibly work.

It’s necessary to get these items proper earlier than you even depart the dock, so don’t be afeared to spend a little bit of time refining the plan. [I’m “afeared” we might be wearing out the salty sea-dog bit already—Anna]
“I” is for Iterate
Even the boldest captains don’t attempt to cross an ocean in a single leap. It’s simpler to island-hop, crusing a brief distance at a time and checking you’re nonetheless on the right track. Give Junie one small job at a time, beginning with the best attainable program that could possibly be helpful:
Let’s begin with a extremely easy prototype. I’d like to have the ability to run the ‘booty’ calculator and reply two questions: the variety of crew, and the variety of items of eight to be divided amongst them.
Assume everybody has an equal share. The instrument ought to print out how a lot every crew member is due. Write simply sufficient code to attain this, after which we’ll take into consideration the subsequent stage.

With too obscure a heading, Junie can find yourself going a bit adrift, like every of us: don’t hesitate to cry “Avast heaving there!” and interrupt her if that occurs. Rowing again when the challenge has gone too far within the improper path will price you lots of time and doubloons [Seriously, clap a stopper on the pirate speak for now—Anna]. Sorry, I meant to say “tokens”.
“R” is for Assessment
As soon as Junie has accomplished every iteration, undergo the code line by line to verify and evaluate her work. She’s fairly good at delivering what you requested for, however she doesn’t essentially know how you need it. For instance:
Good job, Junie, however I’ve just a few strategies for enchancment.
- As a substitute of making a
bufio.Scannerin essential and passing a pointer to it into theaskIntperform, let’s remove a few of that paperwork. ChangeaskIntto take simply the immediate string, and have it create the scanner internally. - The
askIntperform shouldn’t print error messages and nameos.Exitif there’s a scan error. As a substitute, have it return any error together with the integer end result. Let essential maintain all of the printing and exiting. - If there’s an error from
strconv.Atoi, embrace the invalid enter within the error message. For instance, “Sorry, I didn’t perceive%q. Please enter an entire quantity.” - Transfer the shares calculation into its personal perform, in order that we decouple the enter/output code from the enterprise logic. Have it return the share and the rest values, in order that essential can print them out.

When giving suggestions, bundle all of your feedback collectively in a single message. This lets Junie generate the brand new model of this system in a single step, saving tokens. In case you hold making small feedback and asking her to rebuild the entire program every time, you’ll discover your items of eight—I imply, credit—dwindling quickly.
Good packages have a harmonious structure that makes general sense: every part works the identical approach in every single place and all of it appears to suit collectively neatly. Junie can’t obtain this with out your steerage, so hold a hand on the tiller and assist her guarantee issues slot neatly right into a unified construction.
“A” is for Assess
As soon as Junie has completed the step you requested for, don’t simply look on the code and transfer on—take a second to evaluate whether or not it truly does what it ought to. Does this system run cleanly? Do the features behave as anticipated? Are there unusual unwanted effects lurking within the bilges, ready to sink your ship later? [What did I just say?—Anna]
Now you could see this system in motion, you would possibly realise it’s not fairly what you need. In that case, now’s the time to regulate course, both with Junie’s assist or by making little steering inputs your self.
In case you’re pleased with the evaluation, although, you possibly can transfer on to the subsequent iterative step in direction of the ultimate program:
Shiver me timbers, Junie, that be some fantastic work.
May you now please transfer the enterprise logic features right into a booty bundle within the challenge root, and put the primary.go file right into a cmd/booty subfolder?
Additionally, may ye change the plunder calculations in order that the captain will get twice the share of a daily crewmember? Print out the captain’s share individually.

“T” is for Take a look at
No outdated salt trusts a ship that hasn’t been via its sea-trials, and nor must you. As you and Junie construct this system, verify every new plank is watertight by including assessments to accompany every perform. That approach, you’ll know as quickly as one thing springs a leak.
Arr, please add some unit assessments now for the CalculateShares perform. Generate at the very least ten check instances.
Transfer the askInt perform into the booty bundle too, and add logic to verify that the quantity entered is at all times 1 or better, or return an applicable error if it’s not.
Have the perform take an io.Reader to learn enter from, and an io.Author to print prompts to.
Generate two assessments for this perform, one for legitimate inputs, one for invalid inputs.

Junie could be a useful shipmate in relation to drafting assessments, however don’t simply settle for her handiwork blindly. Ask your self: What is that this actually testing? Are there hidden reefs—edge instances—that we’re lacking? And, when the assessments fail (they’re no use in any other case) do they print one thing useful?
Tis a fantastic set of assessments ye have there, Junie. May you make all of them run in parallel?
Within the desk assessments, may you employ a map of check instances keyed by identify, after which use t.Run within the check loop with the map key because the subtest identify? That’ll make it simpler on any scurvy canines attempting to grasp the failure output.
Don’t attempt to examine the error string itself for invalid inputs; that results in fragile assessments. As a substitute, simply verify that AskInt returns any non-nil error for these instances.

“E” is for Consider
Machine studying is ok, however human studying is even higher. After every job, take some time to analyse what labored, and what may have gone higher.
Have been your prompts detailed sufficient? Did Junie sail safely into harbour, or did she find yourself grounded on a sandbar as a result of her pilot was too busy splicing the mainbrace? Each voyage is a lesson that’ll allow you to sharpen your prompting abilities, anticipate pitfalls, and change into a steadier pirate cap’n for the subsequent expedition.
In case you keep in mind the chart we’ve drawn right here and use it to navigate your subsequent challenge, with the assistance of Junie and GoLand, you’ll be prepared to actually code like a PIRATE [That’s it, you’re walking the plank—Anna].
Anchors aweigh
Try the booty calculator challenge to see what Junie and I constructed collectively—strive utilizing it to divvy up your personal pirate booty with associates. It’s additionally sort of enjoyable to say “booty”.
Till subsequent time, shipmates, wishin’ ye truthful winds and full sails!
Authorized disclaimer: JetBrains s.r.o. doesn’t advocate piracy, unlawful seizure of vessels on the excessive seas, or the consumption of rum. Please swashbuckle responsibly.

