“Get” Stuffed
I never, ever, ever use the word “get” as part of a method or function name. Why? Consider the following function/method names:
- -getStoryWithID: /* Calls a web service to return a string */
- getPreferences() # Reads a preferences XML file from disk
- getUserProfile() # Fetches user information from the Users table
If you’re among the college-bound you might have already noticed the problem: What the hell does “get” really mean? Does “get” mean make a network request? Does it mean that it hits the disk? Does it execute a SQL select? The problem is that “get” is way too general of a verb to use in programming — it could mean anything from a nearly instantaneous read from a register or a several-second long synchronous network request.
[Cocoa uses the verb get to mean “return by-reference in a pointer”, which is still pretty okay — but we wouldn’t need it if Objective-C had Python’s return tuple(1, 2); x, y = f()]
This problem is frequently compounded by using very generic nouns in method names. (Some of my least favorites are “status” and “progress”.) Combine this with function overloading in some of the world’s more regrettable programming languages and you get:
- getProgress(int)
- getProgress(Object)
- getStatus(int)
- getStatus(Object, float, int)
Even better, you can add doc comments:
/*
* @function getStatus
* @description Gets the status of an object.
* @param status an object
* @return Returns the status.
*/
Awesome.
(Inspired by this)
About this entry
You’re currently reading “ “Get” Stuffed ,” an entry on stuffonfire.com
- Published:
- 4.29.07 / 1pm
- Category:
- Programming
11 Comments
Jump to comment form | comments rss [?] | trackback uri [?]