Why would it be any different for OOP objects? If there's an object with an internal state that chiefly responds to messages about scanning things, what's wrong with calling it NSScanner?
One of the Best Bits of Programming Advice I ever Got
11–20 of 94 posts
Re: One of the Best Bits of Programming Advice I ever Got
#12good explanation of procedural vs OO programming, but I got kind of lost with the -er tip, is it all about naming conventions, should I go and rename all my ZzzXxxer classes to XxxxZzz?
Re: One of the Best Bits of Programming Advice I ever Got
#13Comparable to the post's rule: in English, a few rules I've picked up are
- avoid words ending in "ly" (suffix weakens concepts; suggestion from Stephen King)
- never start a sentence with "I" and otherwise minimize its use
- "but" negates everything that came before
- avoid "to be"
Any other such suggestions, in natural or artificial languages?
Re: One of the Best Bits of Programming Advice I ever Got
#14I disagree with this advice and the reason I disagree with it because it completely disregards the human tendency to name objects (not OOP objects, but real-life objects) based on their functionality. Guess what a photocopier does? Or a scanner? An eraser? An elevator? I don't think these are particularly bad names; quite the contrary, their meaning is very clear. Why would it be any different for OOP objects? If the…
Re: One of the Best Bits of Programming Advice I ever Got
#15But Travis is overreacting. The REAL goal is to find a collection of abstractions that is powerful enough to accomplish what the program requires but as simple as possible (and as local as possible) to allow humans to comprehend (and maintain) it. There are quite a few times when I have found that one of these "verb-like" abstractions (a word ending in "-er") made things more comprehensible.
For example: the Gang-of-Four patterns "Builder" and "Observer" both end in "-er" and strike me as being well-named. "Builder" is an object with no purpose other than to create (initialize) another object or data structure. HAVING such an object is useful when something requires extensive setup or initialization, because it is easier to understand if the extensive initialization is kept separate from the core functionality. "Observer" is the name for an interface of things that observe... the names of interfaces FREQUENTLY work well as "verbs" since the interface frequently represents "anything that does X".
Similarly, I have often had a class such as "DatabaseConnection" and then created "DatabaseConnectionWrapper" -- a class whose purpose is to wrap a DatabaseConnection to do something like logging, error reporting, pool flushing, driver-bug-patching, and so forth. Suggestions that I call these "LoggingDatabaseConnection", "ErrorReportingDatabaseConnection" and so forth misses the key point: a different mix of features may be required at different times (eg: logging in QA but not in Prod); the fact that they are transparent wrappers that can be added (or not) in any order is a key feature of the design.
So my own advice would be weaker than Travis'. Instead of "Don't make objects that end with -er.", I would say "Be wary of confusing objects; those ending in -er are often confusing."
Re: One of the Best Bits of Programming Advice I ever Got
#16Re: One of the Best Bits of Programming Advice I ever Got
#17Even better: don't use objects at all. Use a functional programming language.
Object oriented programming is the sweet spot solution to many problems. For example, if you have a UI with several text fields, it's natural to think of them as objects that have methods like setText(), setEnabled() and such. These methods often have side effects and that's their whole point. Of course functional programming also has use cases for which it is the sweet spot solution, e.g. writing compilers.
Data deserves much more than being encapsulated in objects, data deserves the right to be put in front of the programmer so that he better sees how ill-designed his data model is :-)
Re: One of the Best Bits of Programming Advice I ever Got
#18I generally accept the point made in the article, but what should I use in place of "Controller"? If using MVC I generally call it "ApplicationController" or "SimpleController". Should it be "Application", "ApplicationControl"...?
Re: One of the Best Bits of Programming Advice I ever Got
#19I disagree with this advice and the reason I disagree with it because it completely disregards the human tendency to name objects (not OOP objects, but real-life objects) based on their functionality. Guess what a photocopier does? Or a scanner? An eraser? An elevator? I don't think these are particularly bad names; quite the contrary, their meaning is very clear. Why would it be any different for OOP objects? If the…
Re: One of the Best Bits of Programming Advice I ever Got
#20Amazing how small linguistic changes can cause large semantic shifts. Comparable to the post's rule: in English, a few rules I've picked up are - avoid words ending in "ly" (suffix weakens concepts; suggestion from Stephen King) - never start a sentence with "I" and otherwise minimize its use - "but" negates everything that came before - avoid "to be" Any other such suggestions, in natural or artificial languages?