TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Rf: an experimental refactoring tool for Go

241 pointsby robfigalmost 4 years ago

9 comments

CGamesPlayalmost 4 years ago
This seems pretty cool, from looking over the documentation. Two things I wish I could do that I don&#x27;t see in the documentation:<p>- Replace an import with another import. This is used when forking a go package.<p>- Rename a package.<p>It&#x27;s also pretty unclear from the documentation which operations are &quot;UNIMPLEMENTED&quot;, since the label simply falls directly between two different operations. It would be nice if this were made more explicit.
评论 #27271403 未加载
omezealmost 4 years ago
I used to joke at work that the fastest, simplest way to get promoted to a staff engineering position was to finish a 1 yr refactor.<p>Getting existing codebases to do new things is hard, and most of enterprise software engineering is basically &quot;rework this API (in the general sense, not web-API sense) for a new product use case&quot;.<p>This tool seems to borrow the philosophy of Go&#x27;s keeping the language simple, with the tradeoff of a more complex (but fairly well supported) ecosystem to account for missing language features.<p>IME, Golang (some would say paradoxically due to a lack of generics) is one of the best languages to refactor because of:<p>- Forced error handling semantics so that unhappy paths are easily enumerated<p>- Tooling like `rdep` to quickly grok the impact of a package refactor<p>- String templates&#x2F;codegen being a first-class &quot;blessed&quot; part of the ecosystem (i.e. you can find tooling by the Go team as a reference when writing your own)<p>Some would balk at things like codegen being how Go handles this, but for the iteration loops at most companies at scale (where a few tools to do codegen are written &amp; maintained by one team and consumed by others) it works well. For paradigms where you want everyone to contribute to the tooling, it works slightly less well since the barrier of understanding the ecosystem is greater than just understanding the language. Nevertheless, it seems to be the right tradeoff for most enterprise use cases.
评论 #27272226 未加载
评论 #27271789 未加载
评论 #27271864 未加载
评论 #27275406 未加载
iddanalmost 4 years ago
A similar concept named &quot;Tactics&quot; was explored in Haskell. <a href="https:&#x2F;&#x2F;reasonablypolymorphic.com&#x2F;blog&#x2F;towards-tactics&#x2F;" rel="nofollow">https:&#x2F;&#x2F;reasonablypolymorphic.com&#x2F;blog&#x2F;towards-tactics&#x2F;</a> HN Discussion: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=24759649" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=24759649</a>
评论 #27275761 未加载
jchwalmost 4 years ago
I hope more refactoring tools come into existence in the future. Right now, writing transforms similar to this complexity using Clang would require a fairly large amount of boilerplate code, implementing at least some AST matching code and wrapping it into a frontend action. While having this for Go is good, I hope it grows and inspires others to do similar things in other languages, the same way gofmt once did.
评论 #27271113 未加载
评论 #27271556 未加载
AYBABTMEalmost 4 years ago
I think this is cool but I wonder what the expected API surface for editor integrations (with mouse-click menu selection to apply a refactor) would work. Would editors code-generate this mini scripting language? Or will there be a more abstract way of providing the same intention to the tool? If editor integrations are expected to send the script-snippets, will there be facilities for programmatically generating valid script snippets?
alert0almost 4 years ago
I&#x27;ve always wanted a tool that finds duplicate code (with minor variable name differences) so I can factor it out. Often when prototyping I&#x27;ll copy a function thinking it will change a lot or maybe just not knowing what will change. As the application matures I&#x27;ll go back and clean these up but it shouldn&#x27;t be too hard for a tool to identify.
评论 #27272415 未加载
评论 #27272457 未加载
评论 #27272486 未加载
konartalmost 4 years ago
Shouldn&#x27;t this be part of gopls or something?
评论 #27275976 未加载
dorian-graphalmost 4 years ago
A similar, but general purpose, tool to this is <a href="https:&#x2F;&#x2F;comby.dev&#x2F;" rel="nofollow">https:&#x2F;&#x2F;comby.dev&#x2F;</a>.<p>I&#x27;ve used it before locally for some structural code changes. The author is super helpful&#x2F;responsive too.
MorganGallantalmost 4 years ago
I wonder if this is some sort of precursor work for the generics release? Feels like gofmt -r on steroids, and could be eventually used to do large scale transformations to the standard library?