Created
October 31, 2017 12:11
-
-
Save asterite/3715161c55fa3f7322ada6fc4e2de86c to your computer and use it in GitHub Desktop.
Refactoring in Crystal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def foo(x) | |
# Rename this call from "bar" to "baz": | |
# What other things change in this file? | |
# | |
# According to what's called, Bar#bar needs | |
# to change. But what about Baz#bar? I can | |
# also pass Baz.new to Foo.new.foo. There's | |
# no way to tell if that should be renamed too. | |
# | |
# Renaming based on usage isn't correct. The | |
# only solution to this is to make all methods | |
# have mandatory argument types, and return | |
# types. Then you'll know for sure what needs | |
# to be renamed. | |
x.bar(1) | |
end | |
end | |
class Bar | |
def bar(x) | |
end | |
end | |
class Baz | |
def bar(x) | |
end | |
end | |
Foo.new.foo(Bar.new) |
Well, I guess I can add at least basic rename support 👍 , see: crystal-lang-tools/scry#101 (comment)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Personally, local variable renaming, and small refactors such as "extract this subexpression to a variable" would be my 99% usecase for a refactoring tool. Renaming methods at the callsite seems complex, simply look up definitions and rename at the method definition site. For renaming at method definition, first type the whole program, rename all the places where we call the method on the non-union type, then give me a list of places where the method is called on a union which includes the type, and let me decide what to do on a case-by-case basis.