Ideas for a refactoring with traits?

mrgonza78 mrgonza78 at gmail.com
Thu Sep 6 19:58:58 UTC 2007


In my particular case, what I'm doing is a master thesis about trait aware
refactorings. I'm not looking for the best usages of traits. My focus is on
the traits aware refactorings I'm working on.
That's on one hand, on the other hand I agree that just removing code
duplicated across hierarchies is not the best way of selling traits.
I posted the message because I don't only want to show the result of the
refactorings per se, but I also look for a good case in which traits fits
well (if the effort of the refactoring doesn't get me out of my thesis).
I think what I'll end doing is half and a half: I'll apply refactorings just
to remove duplicated code or just for the sake of the refactorings (so I can
collect result or conclusions from them) and also, I'll aply refactorings
for the sake of both the refactorings and traits (so I can collect result or
conclusions from the refactorings and at the same time show how good traits
are).
May be I was too ambitious when I named Seaside, Magritte and Morph. Looking
for good traits and refactoring in those framework may take me several
months and may be subject of it's own thesis (if any).
Thanks for the mind set and hints, I found them very useful.
Alejandro


Jason Johnson-5 wrote:
> 
> Keep in mind that Traits are not at the same level as inheritance, for
> instance.  I wouldn't think of traits as a means of eliminating code
> duplication, even if that is how they are often sold.  I would try to
> keep the mind set that Traits are.... traits.  That is "am I working
> here with a new entity? (create a class) An entity that has various
> specializations? (create subclasses) Or am I working with a trait that
> many unrelated classes have? (trait)".
> 
> If you use this mindset then I think you can find elegant places for
> traits when they are needed.  If we go around looking for duplicated
> code and stick a trait in there we will end up with a mess.  There are
> many ways of eliminating duplicate code, you don't need traits for
> this.
> 
> Having said that, I would like to see what you've done with Magnitude
> as that is a very obvious trait in my opinion.  To find a trait look
> for classes that seem to be inherited to the wrong place, purely to
> gain some interface or something.  A trait could be hiding there, or
> it could simply be a case that needs normal traditional refactoring.
> 
> The other thing I would personally keep in mind is that traits
> probably work best when kept small.  For example, in Magnitude you
> basically just have equality and comparison.  I would even break that
> up to an equality trait (for things which can be equal) and a
> comparison trait (for things which can be compared).  If you get a
> trait that is as big as a class, then I would consider that a strong
> code smell.
> 
> On 9/6/07, Alejandro Gonzalez <mrgonza78 at gmail.com> wrote:
>> Hi,
>>   I'm working in trait aware refactorings, and I reached a point in which
>> I
>> have to use them so as to give them a try in real cases and see how
>> suitable
>> they are or see what other features should be nice to have.
>>   I'm wandering through the image looking for good candidates to apply
>> traits. I started (and I already finished)  with Magnitude and a few
>> particular classes. Now it's time for another refactoring a little more
>> ambitious, but not many ideas have came out of my mind so far :(
>>   Stream and Collection (I know the latter was already refactored) are
>> good
>> candidates, I'll start looking at them, but I was wondering if there
>> wasn't
>> other projects/frameworks like Seaside, Magritte, Morph? or something
>> else,
>> that could benefit from traits.
>>   I'm not looking to implement something with traits from scratch, I just
>> want to take a set of classes, methods (or traits, why not) and
>> restructure
>> code by applying refactorings instead of doing it manually.
>>    Anyone having an idea, please let me know it. Just name a class and a
>> couple of methods you know are spread across several classes and where
>> you
>> think traits would help, and I'll figure out what and how to refactor.
>>   Thanks in advance
>>   Alejandro
>>
>>
>>
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Ideas-for-a-refactoring-with-traits--tf4391535.html#a12530269
Sent from the Squeak - Dev mailing list archive at Nabble.com.




More information about the Squeak-dev mailing list