[mtasc] checking for constructor name
info at bokelberg.de
Tue Jun 7 14:05:28 CEST 2005
Yep, that's true. The only way to recognize a constructor is by
convention (Uppercase class/constructor and lowercase methods).
One more reason why conventions are good :)
If we need more flexibility, we could delay the check until all methods
are parsed, see if a method named like the class exists, and only if
not, create a warning. The problem is, that this will create a lot of
warnings for classes without an explicit constructor.
Maybe we could use diff as the comparison method and only issue a
warning, if the diff is reasonable low. (diff calculates the number of
changes needed to convert one string into a second string). We could
make the diff threshold a parameter. But all this is a lot more
complicated and i don't need it.
Nicolas Cannasse wrote:
>>Every so often my code breaks because my constructor is named different
>>from my class. This happens whenever i rename a class but forget to
>>rename the constructor. These kind of bug is very hard to find.
>>Today i had the idea to let mtasc do it, and it actually works quite
>>good. All i do is to compare every method starting with an uppercase
>>letter to the name of the current class. Whenever they are different,
>>mtasc spits out a warning.
>>You can find the code at http://osflash.org/doku.php?id=mtaschacks
> Yes but this cannot be standard since some users might want to name their
> methods with an uppercase (or their classes with a lowercase). In
> MotionTypes constructor is always named "new" which remove all ambiguities
> since it's keyword.
> MTASC : no more coffee break while compiling
More information about the mtasc