Hacker News new | past | comments | ask | show | jobs | submit login

I wonder how hard it would be to write a program to automatically refactor code like this into something reasonably clean. My intuition thinks it should be difficult but possible... and extremely useful.



There are linters which do a bit of this, but they only cover the lints they have rules for. I'm pretty sure no one has a rule for "all loop indices declared as class members" because no one writing code of this quality has yet used a linter. Many issues in this code-base are not tractable at all for automated repair: how are you going to rework thousands of line long methods into well-factored classes and methods?


ReSharper (and presumably IntelliJ) supports expression-based search and replace.

Here are some commits where I used it to remove boilerplate from some test cases. The code was written long before MSTest added support for Assert.ThrowsException.

https://github.com/dbremner/PowerCollections/commit/a364a154...

https://github.com/dbremner/PowerCollections/commit/1de2f916...

https://github.com/dbremner/PowerCollections/commit/183e3c7c...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: