Send to Printer

development

When you don't know what you don't know...

October 3, 2006 7:43:37.668

Cédric Beust went off on a rant about refactoring (specifically, renaming classes) in dynamic languages yesterday:

All the Smalltalk IDE did for renaming was search and replace, which is, frankly, the best it could do. And clearly unacceptable today.
It's simple, really: dynamic languages that are not statically typed (i.e. let you get away with not typing variables) simply *cannot* do certain refactorings, among which "renaming".

Pulling up my BottomFeeder development image, I spot class Text - specifically, the one in namespace XML (as opposed to the one in UI). I go ahead and rename that to XMLText, and then go look for class Text in namespace UI - and there it is, blissfully not renamed.

It seems that in VW Smalltalk, renaming is scoped by the namespace of the class in question. So - in practice (as opposed to theory), you'll be putting your new classes into namespaces - and you'll be disambiguating by using namespaces. So... any renaming of classes that you do will "just work". Can you come up with edge cases that will break? Almost certainly. Will you actually run into any of them? Probably not. In many, many years of Smalltalk work, I can't recall getting bitten by renaming a class - and most of those years preceded the introduction of namespaces.

Sure, code that's not loaded won't get that (or any other) refactoring, but that has to do with the image based environment - something that also makes renaming much, much faster than running over a bunch of text files. I hope Cédric feels a lot safer over there - I'll be busy being productive in the meantime, unworried over edge cases I won't hit.

Update: As Alan states in a comment, I misread this:

The limitations that Smalltalk has in renaming methods are precisely the limitations of not using methods monomorphically. In a statically typed language, you will have the same kind of issues as soon as you start using features like generics, or subclassing. I talked about this in more detail the last time this endlessly recurring issue came up, about a year ago, over here.

Technorati Tags: ,

Comments

Rename method?

[murphee (http://jroller.com/page/murphee)] October 3, 2006 9:14:31.848

Well... that's for renaming classes, but what about renaming methods? Some time ago I put together an article to understand some of the refactoring tools in Smalltalk, and I'm always curious about realworld experience with these tools.

Your example is an edge case

[Matthias] October 3, 2006 9:19:36.168

Read again. Cedric talks about renaming methods, not classes. The space of class names is in fact pretty static in Smalltalk, too, and therefore renaming works well. But how about renaming, say, a #parent method? You might say, selectors are typically way more unique and errors are unlikely to occur. Yet I prefer impossible over unlikely.

Method renaming

[ James Robertson] October 3, 2006 9:34:42.179

Comment by James Robertson

In places where I've renamed methods, it's rarely been a common name. As well, if you need to be specific, the refactoring engine can be scripted for that (although, I have to admit that I've not looked into that). His example is fairly silly, IMHO - I can't imagine wanting to change the name of a method like #initialize in one of my classes. Refactoring it to be shorter, sure. Renaming it to #initialize2? Not so much.

Static languages aren't immune

[Alan Knight] October 3, 2006 10:06:53.720

The limitations that Smalltalk has in renaming methods are precisely the limitations of not using methods monomorphically. In a statically typed language, you will have the same kind of issues as soon as you start using features like generics, or subclassing. I talked about this in more detail the last time this endlessly recurring issue came up, about a year ago, over here  http://www.cincomsmalltalk.com/userblogs/knight/blogView?showComments=true&entry=3304075060

Something Handy

[Patrick Logan] October 3, 2006 12:20:11.184

There are these things called tests. They come in handy. I recommend especially that people who are afraid use them.

When you don't know what you don't know...

[Isaac Gouy] October 3, 2006 15:39:20.538

James your comments are a wonderful demonstration that the blog post title "When you don't know what you don't know... applies strongly to you.

You've criticized someone for ignorance and demonstrated your own ignorance - by not reading their comments sufficiently to understand that they were talking about method renaming, and with a handwaving reduction to the special case of monomorphic methods.

Have Alan Knight respond to bogus technical criticisms - he's better at it.

Isaac...

[ James Robertson] October 3, 2006 16:00:08.959

Comment by James Robertson

When you achieve perfection, let me know. Until then, just calm down.

[] October 3, 2006 17:31:05.856

"There are these things called tests. They come in handy. I recommend especially that people who are afraid use them."

 

Tests and static analysis are not mutually exclusive.  Why not let the computer do some of my testing for me?

James...

[Isaac Gouy] October 3, 2006 23:04:50.440

When you achieve perfection, let me know. Until then, just calm down.
That's a sentiment I wish you would take to heart.

Isaac gets Cedrik to reconsider

[David Mitchell] October 3, 2006 23:10:04.256

James, I love your blog in that you are willing to go on record with your opinions. I appreciate Isaac for taking you to task. He does a great job of playing devil's advocate regardless of the site. Check out the comments on Cedric's blog to see where he eventually convinces Cedrik that Eclipse has to do the same thing as Smalltalk (as it is a polymorphism issue and not a dynamic/static type thing). Both Eclipse and the refactoring browser offer to rename all (safe but potentially overreaching) or let you choose (just what you want but more work). Dynamic/Static doesn't enter into it. All of which makes me wonder just what all that extra typing is buying you. (Most Java people think Autocomplete can't be done in Smalltalk either since Ruby IDEs don't have it).

Static Checking

[Patrick Logan] October 3, 2006 23:45:24.310

Let the computer do static checking for me? Sure. Let it do model checking of my concurrent systems. That's a hard problem that computers are getting pretty good at. 

Let it do static type checking for me at "compile time"? Why on earth when I don't need it, and it just gets in the way.

 No thanks!

eventually convinces Cedrik

[Isaac Gouy] October 4, 2006 12:16:22.955

David, let's just say Cedric is presently bamboozled by the verbiage.

Both Eclipse and the refactoring browser offer to rename all (safe but potentially overreaching)...
Well no, for a couple of reasons:

  1. I wasn't clear enough on Cedric's blog; afaik Eclipse is only offering to rename "doStuff" methods in classes that implement the interface, while the Refactoring Browser is offering to rename any method named "doStuff" in any class in the image.
  2. I missed something in Alan Knight's September 2005 comments, we started talking about rename method not rename method refactoring - iow we started talking about changes which were not guaranteed to be behaviour preserving. afaict using rename method on an overriding method in a subclass isn't guaranteed to be behaviour preserving (it's unlikely to be), so it isn't something Eclipse offers as a refactoring. Eclipse offers a guaranteed behaviour preserving transformation - rename all the "doStuff" methods in classes that implement the interface.

 Share Tweet This