« Hold the Button - Don't Waste Your Time | Main | Change File Permissions on Apache-created Files »

May 13, 2004

Switching Method Naming Conventions in Perl

We're in the process of redoing a core library (base module for 75% of our code). Up to this point we've always used underscores in method names like get_version() and set_primary_key(). The new version of this library is written using a different style: getVersion(), setPrimaryKey() (also known as lower CamelCase).

I'm troubled. I think because I associate the underscore naming convention with Perl and wouldn't want to do anything that isn't unPerl-like. I searched a bit but didn't find any concrete documentation saying such. A recursive grep through our code reveals we've got 3373 methods, 2617 of those have an enderscore separating words in method names and 87 use lower Camel Case (mostly in the new library). An egrep of /usr/local/lib/perl5 reveals 11290 methods, 4188 methods with separating underscores and 320 with lower CamelCase (2-3% in both our and CPAN code).

I think more important than being Perl-like is being consistent in naming. Moving to CamelCase means that we've got a noticeable difference in our code. That could be good in the sense that the next generation of our code has a new naming convention and is easy to separate from the old. It could also be bad in the sense that we're having to use different styles in code that references newer code and older code. It could be good in that to migrate dependant code the code will break until it's updated. That could make a lot more work, but I think we're convinced we want to redo the module without any gaurantee of compatibility (gives us freedom to do things right, even if it breaks stuff). Either way, unless we plan to rewrite everything, it will be ugly to have intermixed styles (not that our code is pretty without it).

Sounds like an excellent conversation for our next developer meeting.

Posted by mike at May 13, 2004 8:45 AM