Is it justified to use project-wide unique function and variable names to help future refactoring?
- by kahoon
Refactoring tools (like ReSharper) often can't be sure whether to rename a given identifier when, for example refactoring a JavaScript function. I guess this is a consequence of JavaScript's dynamic nature.
ReSharper solves this problem by offering to rename reasonable lexical matches too. The developer can opt out of renaming certain functions, if he finds that the lexical match is purely accidental. This means that the developer has to approve every instance that will be affected by the renaming.
For example let's consider we have two Backbone classes which are used completely independently from each other in our application:
var Header = Backbone.View.extend({
close: function() {...}
})
var Dialog = Backbone.View.extend({
close: function() {...}
})
If you try to rename Dialog's close method to for example closeAndNotify, then ReSharper will offer to rename all occurences of Header's close method just because they are the same lexically prior to the renaming.
To avoid this problem, please consider this:
var Header = Backbone.View.extend({
closeHeader: function() {...}
})
var Dialog = Backbone.View.extend({
closeDialog: function() {...}
})
Now you can rename closeDialog unambiguously - given that you have no other classes having a method with the same name.
Is it worth it to name my functions this way to help future refactoring?