Live data from Hacker News

One of the Best Bits of Programming Advice I ever Got

objology.blogspot.com

11–20 of 94 posts

Re: One of the Best Bits of Programming Advice I ever Got

#11
I 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 there's an object with an internal state that chiefly responds to messages about scanning things, what's wrong with calling it NSScanner?

Re: One of the Best Bits of Programming Advice I ever Got

#12
post #9

good 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?

yes, that's his advice. Organizer -> Organization, don't ask, just do it. while this sounds silly, i think it's all about getting into the right state of mind.

Re: One of the Best Bits of Programming Advice I ever Got

#13
Amazing 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?

Re: One of the Best Bits of Programming Advice I ever Got

#14

I 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…

I was going to write basically the same thing. I used to combine data and action in the same classes but recently have begun refactoring them out into separate data and "-er" classes. Maybe somewhere an OOP purist is frowning, but I really prefer this naming convention. My FlowchartShape class included methods for formatting and positioning. I now have a FlowchartShapeFormatter class and a FlowchartShapePositioner class. Guess what they do?

Re: One of the Best Bits of Programming Advice I ever Got

#15
I am unconvinced. Any absolute deserves close scrutiny, and "real nouns only" is an absolute. In this case, it fails my test. I find that many things I work with (especially huge Java libraries) tend to have convoluted and difficult-to-understand webs of classes with the most confusing pieces named things like "FooManager" or "FooController". So the author of this piece is reacting to a genuine excess.

But 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

#17
post #5

Even 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.

I'm overreacting mainly because these last days I saw code with some Java classes just acting as data holders. It's verbose and obscures the intend.

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

#18
post #6

I 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"...?

what do the controllers actually do? Synchronize state? Verify that constraints are met?

Re: One of the Best Bits of Programming Advice I ever Got

#19

I 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…

He does say, at the end of the piece, that nouns that happen to end in -er are an exception.

Re: One of the Best Bits of Programming Advice I ever Got

#20

Amazing 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?

Avoid the passive voice.
Post reply on HN