prog: (Default)
prog ([personal profile] prog) wrote2006-11-25 11:58 am
Entry tags:

Hey you coders

These questions aren't language-specific; consider the questions as pseudocode. Pretend that the underscores are actually studlyCaps if you'd like.

Also, don't worry about return values of the mutators, which is a separate question.



[Poll #875101]

[identity profile] metahacker.livejournal.com 2006-11-25 05:11 pm (UTC)(link)
...except I prefer Java's standards, which are getFoo() and setFoo().

I have an intrinsic dislike -- learned from LISP, where this caused a bug that took about a week to track down -- of having method names that look like variable names.

[identity profile] prog.livejournal.com 2006-11-25 05:19 pm (UTC)(link)
I was intentionally mixing up language styles by not using studlyCaps. My home turf of Perl allows them, but Perl culture tends to frown on their use. I'm pretty sure it's not just because it makes the code look like Java. (Aw, shucks, I can't Google up an image of the cover of The Perl Journal's "Special Java Issue" cover art from a few years back...)

Anyway, I ask this coz Perl culture has long used dual-purpose accessors, but adherents to "Damian style", led by the Perl Best Practices book I just read, advocate explicit separation of getters and setters, and would agree with the reason you give. So I'm of two minds about it right now.

[identity profile] metahacker.livejournal.com 2006-11-25 05:25 pm (UTC)(link)
StudlyCaps do have the downside of encouraging FileNamesThatLookLikeThis.txt, which can break on non-case-sensitive machines (Macs and, in times past, VMS). And yes, it makes perl look like Java, and who wants to reach all the way over to that shift key anyway? But nowadays even my text editors understand them -- e.g. Ctrl-Left-Arrow in my IDE will move to the next word *part* in a studlyCapped word, which can be very handy.

For a while I stuck with studLy for public methods variables, and lower_underscore() for private methods and internal variables. This got old really fast. Nowadays I just dislike seeing underscores at all, mostly because of people with LJ handles like _________I___AM___K00L_________ and that sort of crap. (Though I retain the _initial_underscore morphology for reserved variables...)

you can grep "set_foo()" easier than "foo"

[identity profile] taskboy3000.livejournal.com 2006-11-25 09:02 pm (UTC)(link)
The more verbose names are more accurately greppable. Don't underestimate the value of that. :-)
wrog: (dew)

[personal profile] wrog 2006-11-26 11:45 am (UTC)(link)
method names that look like variable names.
while this sort of thing does bother me, I'm not sure it's the right argument. get_foo() could be doing all sorts of random things behind the scenes and you'll never know.

I think the real argument against having the same method used as accessor and mutator is the same argument against having the same-named method doing entirely semantically different things depending on the type of an argument or the presence/absence of an optional argument. If munge(x) does something different from munge(), really have no business giving it the same name.

I also hate studly caps. If you're going to have multiple words in your variable names, then, dammit, have actual multiple words complete with spaces to make them legible -- that is what you need the underscores for. As for them being ugly, ugliness is in the eye of the beholder.

[identity profile] dougo.livejournal.com 2006-11-26 05:01 pm (UTC)(link)
If you're going to have multiple words in your variable names, then, dammit, have actual multiple words complete with spaces to make them legible -- that is what you need the underscores for.

Real programmers use hyphens. :)