Re: Java vs. Objective-C for Cocoa
Re: Java vs. Objective-C for Cocoa
- Subject: Re: Java vs. Objective-C for Cocoa
- From: Keith Ray <email@hidden>
- Date: Sun, 24 Apr 2005 09:00:21 -0700
Refactoring is about behavior-preserving changes to the structure of
classes and methods. (Obviously only the behavior your interested
in... refactorings may increase or decrease the number of method
calls, which can increase or decrease the stack depth and timings.
Usually such things are not that the behavior of interest.)
You get the structure of classes and methods by doing the same kind of
parsing that the compiler does *or* by using run-time reflection. All
refactoring tools that I know of, even the Smalltalk ones, use parsing
primarily... but I could be wrong.
In any parsing-a-language situation, the lowest level involves lexing,
which can be done by regular expressions. The rest of parsing builds
on top of that.
The problem with Objective-c is that we have the preprocessor... this
is also a problem with C++, though C++ templates and complexity of
that language have hampered creation of refactoring tools. In spite of
this problem, some C++ refactoring tools are coming out.
On the other hand, if the preprocessor isn't abused, Objective-C is a
simple enough language to be parsed without writing a full compiler,
and therefore refactoring tools * could * be written if motivated
people wanted to.
Here's a few refactorings that would be useful. (See
http://www.refactoring.com/catalog/index.html for a "complete" list.)
"Collapse Heirarchy" - choose this menu item in your IDE, get prompted
to select two or more classes, the tool collapses all the selected
classes into one base class. It finds all references to the
now-extinct classes and changes them to refer to the base class.
Whatever "merges" that can't be done reliably via software are left to
be done by the programmer.
<http://www.refactoring.com/catalog/collapseHierarchy.html>
"Extract Class" - select one or more member variables, and/or one or
more methods, choose this menu item in your IDE, and get prompted for
a new class name. This tool creates a new class containing those
variables and/or methods, and in the old class, replaces the
variable/methods with references to the new class.
<http://www.refactoring.com/catalog/extractClass.html>
"Extract Interface" - to use Objective-C terminology, that would be
"Extract Protocol"...
<http://www.refactoring.com/catalog/extractInterface.html>
"Extract Method" - this is the most commonly-used refactoring,
especially with legacy code, which almost always has too-big methods.
<http://www.refactoring.com/catalog/extractMethod.html>
"Inline Method" - the opposite of Extract Method. Sometimes you need
to inline several methods in one, and then extract methods in a
different way, to put the where code belongs.
<http://www.refactoring.com/catalog/inlineMethod.html>
"Extract Superclass" - this moves common features from two or more
classes into a common base class.
<http://www.refactoring.com/catalog/extractSuperclass.html>
"Pull Up" Method/Variable and "Push Down" Method/Variable... moving
things from subclass to parent-class and vice-versa.
"Replace Inheritance with Delegation"
<http://www.refactoring.com/catalog/replaceInheritanceWithDelegation.html>
"Replace Method with Method Object"
<http://www.refactoring.com/catalog/replaceMethodWithMethodObject.html>
"Replace Temp with Query"
<http://www.refactoring.com/catalog/replaceTempWithQuery.html>
---
C. Keith Ray
<http://homepage.mac.com/keithray/blog/index.html>
<http://homepage.mac.com/keithray/xpminifaq.html>
<http://homepage.mac.com/keithray/resume2.html>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden