Skip to content
This repository has been archived by the owner. It is now read-only.

Inline method refactoring #134

Open
Rpinski opened this issue Oct 27, 2015 · 3 comments
Open

Inline method refactoring #134

Rpinski opened this issue Oct 27, 2015 · 3 comments

Comments

@Rpinski
Copy link
Member

Rpinski commented Oct 27, 2015

Weaving simple method bodies directly into calling code.

Example: http://refactoring.com/catalog/inlineMethod.html

@cstick
Copy link
Contributor

cstick commented Nov 22, 2015

I would like to work on this however I want to ensure my interpretation matches yours.
As I interpret it, these are the conditions in which it would be suggested to inline a method.

  • The method is not exposed external to the project. For example, a public or protected method on a public class. Reason being that this method may be invoked by unknown sources.
  • The suggested refactoring would occur when the caret is placed either on the subject method name or the invocation of the subject method (this may not be appropriate).
  • This refactoring is primarily about code smell, readability. So, I see two instances of behavior based on method complexity. For reference, lets call the first simple and the second complex.
    1. When the method's body is a simple return of a single expression, "return (a+b);" then the method's body will be inline to all callers. IE: var x = Sum(1, 5); will be refactored to var x = (1+5);
    2. When the method's body is more than one line, then the method body will be placed above the caller and the return being changed to a variable declaration with a name similar to the original method's name. The original call to the method will be replaced with this new variable.
  • Again, based on code smell, readability. I would suggest that simple methods which are referenced one or more times are subject to this refactoring. However, complex methods must be referenced only once to be subject to this refactoring.

Additionally, I would like to develop in 2 iterative steps, simple inline method followed by complex inline method.

Please advise so that I can work on it.

Thx,
Chuck

@Rpinski
Copy link
Member Author

Rpinski commented Nov 22, 2015

This refactoring was a user suggestion (on VS Extension Gallery, Twitter or similar). I've left the requirements open intentionally, to have place for discussion. Your interpretation makes sense to me and I think you can implement it that way.

Some comments:

In my opinion the refactoring should also be available with caret on invocation of (private) methods.

It should be possible to inline a single-expression method even without a return (-> return type void).
Regarding the complex method case: We should be aware of name collisions between variables declared inside of inlined method and variables in calling method.

Development in iterative steps is welcome.

@cstick
Copy link
Contributor

cstick commented Nov 23, 2015

Thanks for the affirmation and feedback. I believe I have enough to get started, consider it being worked on.

Thx.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants