News for hackers. Stuff that matters.
Re:Codemod – A library to assist with large-scale codebase r... by xaedes on Thursday August 24, 2017 @03:31AM (#15088291)
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.

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.

What I really want: a language agnostic abstract syntax tree parser, matcher and transformer.

AST matchers and Clang refactoring tools: http://eli.thegreenplace.net/2014/07/29/ast-matchers-and-cla...

Refactoring C++ with Clang with cool examples: https://www.youtube.com/watch?v=yuIOGfcOH0k

Clang rename refactoring tool: https://clang.llvm.org/extra/clang-rename.html

Re:Codemod – A library to assist with large-scale codebase r... by Etheryte on Wednesday August 23, 2017 @04:31PM (#15084795)
This is nice, but I don'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't really say I've ever felt a need for something like it.
Re:Codemod – A library to assist with large-scale codebase r... by mayank on Wednesday August 23, 2017 @07:07PM (#15085999)
It's meant for large codebases that can't be loaded into an IDE all at once, or for cases where you need to modify other people's code and automatically send them individual pull requests for approval.
Re:Codemod – A library to assist with large-scale codebase r... by stringham on Wednesday August 23, 2017 @09:24PM (#15086885)
I find the idea of https://github.com/facebook/jscodeshift to be really useful.

I'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.

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.

Writing scripts like this is way more effective than doing it by hand.

Re:Codemod – A library to assist with large-scale codebase r... by mygosh on Thursday August 24, 2017 @03:25AM (#15088274)
Or just use a language that supports large scale refactoring, say Java, C#, perhaps even C++ if you are careful. I generally don't like dynamic languages for large projects exactly because of this. You can'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/C# because you just can't quickly refactor stuff across the entire codebase, so you won't.
Re:Codemod – A library to assist with large-scale codebase r... by jameslk on Wednesday August 23, 2017 @07:50PM (#15086308)
I'd also recommend checking out https://github.com/Yelp/undebt which is a bit more robust it seems in the search aspect, since it's grammar-based instead of regex-based.
Re:Codemod – A library to assist with large-scale codebase r... by paulie_a on Wednesday August 23, 2017 @08:29PM (#15086573)
I have explored undebt and it has some very useful examples. But generally they seem to be low hanging fruit. I really would love to see more specific implementations and use cases
Re:Codemod – A library to assist with large-scale codebase r... by pspeter3 on Wednesday August 23, 2017 @04:19PM (#15084697)
I think this was open sourced earlier but I just discovered it.

As a personal anecdote, I've written many ad hoc code mods while working on Luna2 (Asana's next framework) and had no idea one of our founders wrote this. He apparently assumed IDEs would just handle this by now.

Re:Codemod – A library to assist with large-scale codebase r... by nathancahill on Wednesday August 23, 2017 @04:29PM (#15084782)
Facebook also maintains a JS codemod tool that React uses: https://github.com/facebook/jscodeshift
Re:Codemod – A library to assist with large-scale codebase r... by bm_i on Wednesday August 23, 2017 @04:54PM (#15085017)
jscodeshift (recast) is one of my favourite tools
Re:Codemod – A library to assist with large-scale codebase r... by amenghra on Wednesday August 23, 2017 @09:24PM (#15086891)
This code was open sourced in 2008, with a few improvements here and there until 2010.

Codemod is great, but there are better tools out there (pfff by facebook, IntelliJ plugins, etc). It's too bad the readme doesn't do a great job explaining that.

Re:Codemod – A library to assist with large-scale codebase r... by allendoerfer on Wednesday August 23, 2017 @04:33PM (#15084814)
Nice project, but a less powerful version of vim's :argdo.
Re:Codemod – A library to assist with large-scale codebase r... by fphilipe on Wednesday August 23, 2017 @05:01PM (#15085088)
Or :cdo when using the quickfix window.