4 ms·
"Objects make good nouns" most 'objects' as they exist in today's OOP have methods, which makes them both nouns and verbs. Idiomatic code in most of today's ma
by dustingetz 13y ago
"Objects make good nouns"
most 'objects' as they exist in today's OOP have methods, which makes them both nouns and verbs. Idiomatic code in most of today's mainstream OO languages doesn't make heavy use of closures, mostly only Javascript.
Anyway, the closures vs methods debate has been going on for decades is not a closed topic[1], and the answer certainly depends on the language you're using.
[1] http://www.c2.com/cgi/wiki?ClosuresAndObjectsAreEquivalent http://www.c2.com/cgi/wiki?ClosuresAndObjectsAreEquivalent
- samatman 13y agoI don't believe this is a nitpick, but fully encapsulated OO provides only nouns and verb phrases that have a pre-specified noun. This is different from data structures (nouns) with collections of functions (verbs) that can act on many data structures in a consistent way.
- btilly 13y agoWhat you say works well if you already have your data nicely divided into different kinds of objects. However a useful technique with closures is a dictionary of closures allowing you to map things that may be of the same type to different behavior. Wrapping those in objects so that you can use method dispatch can be a lot of useless work. As a concrete example I point you at http://www.perlmonks.org/?node_id=34786 http://www.perlmonks.org/?node_id=34786 where I demonstrated how to take transform a markup language into HTML through the technique of grabbing a token, then passing to a closure that is associated with that token to consume a bit of the document. Porting that closure-based code to an OO style would be a nightmare.