On 2014-03-14 05:14:52 +0000, Manu <[email protected]> said:
So it comes up fairly regularly that people suggest that the compiler should have a mode where it may update user code automatically to assist migration to new compiler versions. I'm personally against the idea, and Walter certainly doesn't like it, but it occurred to me that a slight variation on this idea might be awesome. Imagine instead, an '-update' option which instead of modifying your code, would output a .patch file containing suggested amendments wherever it encountered deprecated code... The user can then take this patch file, inspect it visually using their favourite merge tool, and pick and choose the bits that they agree or disagree with. I would say this approach takes a dubious feature and turns it into a spectacular feature!
If you're using a version control system, it's probably simpler to just apply the patch automatically and then review it like you'd review any change you're ready to commit, while tweaking the changes if needed.
But before you can consider building such a tool, you'll have to convince Walter that the locations of tokens should be tracked more precisely in the frontend. Currently the frontend remembers only the file and line of any token it finds. You can't implement a refactoring with that. Last time that came in in a discussion (about error messages showing the exact location of the error), the idea was shut down on the ground that storing better location info would slow down the compiler.
Language changes are probably easy enough to handle, but what about cases of 'deprecated' in the library? It's conceivable that the deprecated keyword could take an optional argument to a CTFE function which would receive the expression as a string, and the function could transform and return an amended string which would also be added to the output patch file. This way, the feature could conceivably also offer upgrade advice for arbitrary library changes. Considering the advice in the context of a visual diff/merge window would be awesome if you ask me.
Xcode has a refactoring for transitioning to ARC, and it works by presenting you a merge view of the changes, which you can edit, before saving them. I'm sure other IDEs can do that too.
http://cdn5.raywenderlich.com/wp-content/uploads/2012/01/Review-Changes.png -- Michel Fortin [email protected] http://michelf.ca
