From: Tom Cloyd Date: 2008-12-08T02:54:10+09:00 Subject: Re: class vrs. method Nice addition to the discussion. I haven't yet set up a module, but I've been looking at it. Your point is well taken (assuming I correctly grasp it). Thanks! t. David A. Black wrote: > Hi -- > > On Sun, 7 Dec 2008, Tom Cloyd wrote: > >> I've been thinking about this question for days, and have yet to come >> up with a satisfactory answer. I have deep respect for the "smarts" >> available on this list, so I'll toos the question out here. I've been >> programming in Ruby for possibly a couple of years, learning what I >> need to know to get something done, at the time I need to know it. I >> don't have much time for pure Ruby-study, although I much wish I did. >> I'm presently writing database program in ruby, using only ruby (no >> database engine), which will manage a network of nodes (labels) and >> relationships (also labels). It's simple, but potentially very >> powerful, and a great opportunity for me to push into new territory >> with Ruby. It's coming along well, and I'm much enjoying the experience. >> >> I'm getting it done by writing a number of methods. I keep looking at >> other people's programming, and I see many, many classes. Some of >> these classes look pointless to me. A mere method would have done the >> trick. Why a "class"? I personally feel no need whatsoever to >> actually USE one. I'm getting everything done easily and artfully >> with mere methods. I simply don't get it - about classes. It looks >> like an elegant idea, and in more complex programming I can imagine >> why one might use them, but...I've simply cannot find a reason to >> bother. >> >> I've read a lot about them, but...here's my question: >> >> Am I missing something? Can anyone give me a compelling reason to >> write fewer methods and more classes? >> >> If anyone's interested, the program to which I referred may be >> examined at >> >> http://tomcloyd.com/misc/setnet.txt >> >> (I had to change the file extension to txt, as 'rb' refused to load >> in my browser, and might well do that in yours as well.) >> >> As I've puzzled about this for days, I'm very interested to see what >> better informed people have to say about this question. Please >> understand that I do grasp the basics, but do NOT see what the >> compelling reason is to use a class in a reasonably simple program. >> Thanks! > > I'll just add to the answers you've already received by saying: > remember that classes are not the whole story behind a more > object-oriented approach. Objects are :-) There are ways you can > engineer objects that don't necessarily use classes, but that do give > you the advantages of the kind of encapsulation and stylistic gains > that people have been talking about. > > In particular, I'm thinking of modules, which can be used to add > functionality to a particular object as well as to all instances of a > particular class. And/or just defining one or more methods on a > particular object. > > > David >