Saturday, June 21, 2008

toString() generator will be in a separate dialog

Last week I did some work to make my code clean enough to post on Bugzilla. When I submitted it, Martin suggested that it's not a good idea to have toString() generator in the same dialog with hashCode()/equals(). I was surprised at first, as he was the first person to tell me so. But his arguments were strong: the dialog is too big and there's no good name for the action. His main argument was that hashCode/equals doesn't usually use the same fields as toString. I had doubts about it but I don't have enough experience to argue.
I've made a quick poll about it on the eclipse IRC channel - 100% of participants said that toString generation should not be combined with hashCode/equals (100% of 1 person - I guess IRC is not a good place for polls :P)
I tried to fit elements on the dialog to make it look better, but without satisfactory results (see here and here). So I decided to make a separate action and I won't get back to the previous idea unless there's *a lot* of people asking for it. I submitted a patch with the new action today and I'm waiting for feedback. If you're too lazy to check the patch, here's a screenshot of prepared dialog:

Plan for the next week: investigate possible ways of template handling. I know there's a rich template support in Eclipse but I'm afraid it may not be exactly what I need as these templates relate to the code directly. I saw a nice dialog with templates in Mylyn plugin (Preferences->Mylyn->Team) and I'm going to see how it's done. Do you have any suggestions of where else I should look?

4 comments:

KetanPadegaonkar said...

Would you also be providing autocomplete for toString() generation, with some sensible defaults ?

Mateusz Matela said...

You mean code assist? I'll definitely look into that, after I finish the main part. The question is, what are the sensible defaults?

mhaller said...

I'd say: Selecting the "toString() Wizard" in content assistant brings up the toString() dialog with (all/most/some) fields pre-selected.

With "most" i mean that you probably want to exclude some well-known fields like serialVersionUID, static fields in general.

shubham said...

Great Work! Thank u for wonderful information.