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.

Codemod – A library to assist with large-scale codebase refactoring

42 pointsby pestkrankeralmost 8 years ago

8 comments

xaedesalmost 8 years ago
I also like Clang Tools for C++ AST and programmatic refactoring. Much better than regex replace. What exactly is the benefit of Codemod? Too me it seems like a glorified regex replacer, nothing more.<p>Suppose you have a function Foo::bar() and Bar::bar(). You decide to replace Bar::bar() by Bar::foo(). Good look with doing that via regex. Foo::bar() calls will most likely be affected as well. Matching directly on the AST solves this problem by explicitely matching all Bar::bar() calls.<p>What I really want: a language agnostic abstract syntax tree parser, matcher and transformer.<p>AST matchers and Clang refactoring tools: <a href="http:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;2014&#x2F;07&#x2F;29&#x2F;ast-matchers-and-clang-refactoring-tools" rel="nofollow">http:&#x2F;&#x2F;eli.thegreenplace.net&#x2F;2014&#x2F;07&#x2F;29&#x2F;ast-matchers-and-cla...</a><p>Refactoring C++ with Clang with cool examples: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=yuIOGfcOH0k" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=yuIOGfcOH0k</a><p>Clang rename refactoring tool: <a href="https:&#x2F;&#x2F;clang.llvm.org&#x2F;extra&#x2F;clang-rename.html" rel="nofollow">https:&#x2F;&#x2F;clang.llvm.org&#x2F;extra&#x2F;clang-rename.html</a>
Etherytealmost 8 years ago
This is nice, but I don&#x27;t see the upside over using the tools provided by the IDE or editor of your choice. Some of the additional flags are interesting, true, but I can&#x27;t really say I&#x27;ve ever felt a need for something like it.
评论 #15085999 未加载
stringhamalmost 8 years ago
I find the idea of <a href="https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;jscodeshift" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;jscodeshift</a> to be really useful.<p>I&#x27;ve started writing small scripts using the TypeScript parser as a library to make meaningful improvements in our codebase. Since JavaScript is valid TypeScript syntax the scripts work on both.<p>For example, I wrote a small script to change var to let or const when possible. It uses the AST to check scoping rules and to check if a variable is ever reassigned.<p>Writing scripts like this is way more effective than doing it by hand.
mygoshalmost 8 years ago
Or just use a language that supports large scale refactoring, say Java, C#, perhaps even C++ if you are careful. I generally don&#x27;t like dynamic languages for large projects exactly because of this. You can&#x27;t safely and quickly do large scale refactorings, a point that will come back and haunt you sooner or later. No matter how good you are or how much care you take, the code will rot significantly more than in Java&#x2F;C# because you just can&#x27;t quickly refactor stuff across the entire codebase, so you won&#x27;t.
jameslkalmost 8 years ago
I&#x27;d also recommend checking out <a href="https:&#x2F;&#x2F;github.com&#x2F;Yelp&#x2F;undebt" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;Yelp&#x2F;undebt</a> which is a bit more robust it seems in the search aspect, since it&#x27;s grammar-based instead of regex-based.
评论 #15086573 未加载
pspeter3almost 8 years ago
I think this was open sourced earlier but I just discovered it.<p>As a personal anecdote, I&#x27;ve written many ad hoc code mods while working on Luna2 (Asana&#x27;s next framework) and had no idea one of our founders wrote this. He apparently assumed IDEs would just handle this by now.
评论 #15084782 未加载
amenghraalmost 8 years ago
This code was open sourced in 2008, with a few improvements here and there until 2010.<p>Codemod is great, but there are better tools out there (pfff by facebook, IntelliJ plugins, etc). It&#x27;s too bad the readme doesn&#x27;t do a great job explaining that.
allendoerferalmost 8 years ago
Nice project, but a less powerful version of vim&#x27;s :argdo.
评论 #15085088 未加载