Live data from Hacker News

Using go fix to modernize Go code

go.dev

61–70 of 97 posts

Re: Using go fix to modernize Go code

#61

[dead]

I believe go tooling is one of the top loved features among gophers, in particular gofmt.

The best part is that all those command line utilities are also available for import. I've used them to create a license checker by walking the dep tree in code.

There are also a ton of gems in the `./internal` directories, Roger Peppe has extracted them for reuse here: https://github.com/rogpeppe/go-internal

Re: Using go fix to modernize Go code

#62
post #24

I think tooling that can modify your source code to make it more modern is really cool stuff. OpenRewrite comes to mind for Java, but nothing comes to the top of my mind for other languages. And heck, I into recently learned about OpenRewrite and I've been writing Java for a long time. Even though I don't like Go, I acknowledge that tooling like this built right into the language is a huge deal for language popularit…

Java and .NET IDEs have had this capabilities for years now, even when Eclipse was the most used one there were the tips from Checkstyle, and other similar plugins.

Yeah I've noticed the IDEs have this ability, but I think tooling outside of IDEs that can be applied in a repeatable way is much better than doing a bunch of mouse clicks in an IDE to change something.

I think the two things that make this a big deal are: callable from the command line (which means it can integrate with CI/CD or AI tools) and like I mentioned, the fact this is built into Go itself.

Re: Using go fix to modernize Go code

#63

I think tooling that can modify your source code to make it more modern is really cool stuff. OpenRewrite comes to mind for Java, but nothing comes to the top of my mind for other languages. And heck, I into recently learned about OpenRewrite and I've been writing Java for a long time. Even though I don't like Go, I acknowledge that tooling like this built right into the language is a huge deal for language popularit…

eslint had `--fix` since like 10 years, so this is not exactly new.

I can’t find where in the article the author claims it is new (as in original).

In fact, the author shows that this is an evolution of go vet and others.

What’s new, however, is the framework that allows home-grown add ons, which doesn’t have to do everything from scratch.

Re: Using go fix to modernize Go code

#64
post #23
post #18

Earlier quoted context omitted.

They're particularly bad about concurrent go code, in my experience - it's almost always tutorial-like stuff, over-simplified and missing error and edge case handling to the point that it's downright dangerous to use... but it routinely slips past review because it seems simple and simple is correct, right? Go concurrency is so easy! And then you point out issues in a review, so the author feeds it back into an LLM,…

> a subtle data race and a rare deadlock That's a langage problem that humans face as well, which golang could stop having (see C++'s Thread Safety annotations).

No language protects from dead lock.

Re: Using go fix to modernize Go code

#65
post #20

Earlier quoted context omitted.

The use of LLMs will lead to homogeneous, middling code.

Middling code should not exist. Boilerplate code should not exist. For some reason we're suddenly accepting code-gen as SOP instead of building a layer of abstraction on top of the too-onerous layer we're currently building at. Prior generations of software development would see a too-onerous layer and build tools to abstract to a higher level, this generation seems stuck in an idea that we just need tooling to gener…

The "LLMs shouldn't be writing code" take is starting to feel like the new "we should all just use No-Code."

We’ve been trying to "build a better layer" for thirty years. From Dreamweaver to Scratch to Bubble, the goal was always the same: hide the syntax so the "logic" can shine. But it turns out, the syntax wasn't the enemy—the abstraction ceiling was.

Re: Using go fix to modernize Go code

#66

I think tooling that can modify your source code to make it more modern is really cool stuff. OpenRewrite comes to mind for Java, but nothing comes to the top of my mind for other languages. And heck, I into recently learned about OpenRewrite and I've been writing Java for a long time. Even though I don't like Go, I acknowledge that tooling like this built right into the language is a huge deal for language popularit…

Does anyone have experience transforming a typescript codebase this way? Typescript's LSP server is not powerful enough and doesn't support basic things like removing a positional argument from a function (and all call sites). Would jscodeshift work for this? Maybe in conjunction with claude?

jscodeshift supports ts as a parser, so it should work.

If you want to also remove argument from call sites, you'll likely need to create your own tool that integrates TS Language Service data and jscodeshift.

LLMs definitely help with these codemods quite a bit -- you don't need to manually figure out the details in manipulating AST. But make sure to write tests -- a lot of them -- and come up with a way to quickly fix bugs, revert your change and then iterate. If you have set up the workflow, you may be able to just let LLM automate this for you in a loop until all issues are fixed.

Re: Using go fix to modernize Go code

#67

I think tooling that can modify your source code to make it more modern is really cool stuff. OpenRewrite comes to mind for Java, but nothing comes to the top of my mind for other languages. And heck, I into recently learned about OpenRewrite and I've been writing Java for a long time. Even though I don't like Go, I acknowledge that tooling like this built right into the language is a huge deal for language popularit…

Does anyone have experience transforming a typescript codebase this way? Typescript's LSP server is not powerful enough and doesn't support basic things like removing a positional argument from a function (and all call sites). Would jscodeshift work for this? Maybe in conjunction with claude?

Try ast-grep

Re: Using go fix to modernize Go code

#68
biome kind of does this stuff for me in the typescript world. for example, it recommends for...of instead of forEach. paired with ultracite, it really improves my workflow because it is super easy to add to any project, just one dependency. breath of fresh air compared with the eslint ecosystem.

i now have an agents.md file that says to run biome fix after every modification. i end with much nicer code that i don't have to go and fix myself (or resave the file to get biome to run). speeds things up considerably to not have that step in my own workflow.

Re: Using go fix to modernize Go code

#69

I think tooling that can modify your source code to make it more modern is really cool stuff. OpenRewrite comes to mind for Java, but nothing comes to the top of my mind for other languages. And heck, I into recently learned about OpenRewrite and I've been writing Java for a long time. Even though I don't like Go, I acknowledge that tooling like this built right into the language is a huge deal for language popularit…

Haskell has had hlint for a very long time. Things like rewriting chained calls of `concat` and `map` into `concatMap`, or just rewriting your boolean expressions like `if a then b else False`.

Re: Using go fix to modernize Go code

#70
Not even mentioned in the article, my favorite capability is the new `//go:fix inline` directive, which can be applied to a one-line function to make go fix inline it's contents into the caller.

That ends up being a really powerful primitive for library authors to get users off of deprecated functions, as long as the old semantics are concisely expressible with the new features. It can even be used (and I'm hoping someone makes tooling to encourage this) to auto-migrate users to new semver-incompatible versions of widely used libraries by releasing a 1.x version that's implemented entirely in terms of thin wrappers around 2.x functions and go fix will automatically upgrade users when they run it.

Post reply on HN