Automatic code refactoring
Robert Fraser
fraserofthenight at gmail.com
Sat Aug 4 11:30:49 PDT 2007
Ingo Oeser Wrote:
> > - Renaming a variable/function/template/etc and updating references.
>
> Highly desired. Please have a possibility to ask the user per case or not.
> The implementation is also very simple, if you use the D compiler frontend
> already.
>
> Rationale: Sometimes you rename sth. to forcibly find all its users,
> when you have to break the semantic of sth. (e.g. badly designed,
> non extensible core interfaces) in a big project.
> Supporting this kind of workflow would be great.
>
Of course it'll be optional. But with semantic analysis, youy only need to click a button to find all the references to something.
>
> > - Inline a function (either a single invocation of it or everywhere it's
> > used).
>
> Let the compiler do that. Always! Everything else just asks for long
> function bodies, if junior programmers try to "optimise" code.
>
I wasn't thinking about optimization... sometimes you want to change only part of a function and for whatever reason (it's in a library or someone else's code, it would only be useful in that one invocation, etc.), you don't want to add another parameter.
> > - Struct-to-class or class-to-struct (possibly, I'm not sure how hard this
> > would be to automate. The class-to-struct one, esp. if structs get
> > constructors, seems like it'd be a lot easier if no inheritance is used).
>
> Maybe more useful and easier to implement would be:
> + Extract class members to private struct, build accessors to it
> into class and fix up all users.
>
> Struct to class might be nearly impossible, because structs have properties,
> which classes don't have (e.g. defined member order, can be stored and
> retrieved, can be shared with C/C++ etc.).
That's true, but I was thinking that anyone clicking on the refactoring button would know that, and the refactoring would be able to detect things like that. Order-dependent struct literals could be converted into constructors, etc. A bit tougher than the other way around, but definitely not impossible.
> > - Automatically import modules for symbols if the symbols can be resolved
> > somewhere in the project or attached libraries (and choose from a list if
> > there are multiple possibilities). This will remove the need to manually
> > import stuff. Either the entire module or a selective import can be used.
>
> Very useful! But please do a private import, to not break interfaces this
> way. I guess not making private imports the default are a language design
> oversight, since I see really no reason for this.
>
Imports are private by default now (I hink that was changed just before 1.0).
More information about the Digitalmars-d
mailing list