I’m just getting started w/ Ruby having worked with perl
for the past few years. I don’t have much experience with
pure OO programming and I’m wondering if, when using a
pure OO language like Ruby, I should should make all my
programs OO.
I people don’t always write OO programs in Ruby, how do
they decide when to do so?
Since ruby is pure OO we don’t have to decide.
Seriously: that’s not easy answered. Since you will be using the ruby std
lib which is in fact a collection of modules and classes then you
automatically have to code the OO way.
The more interesting question to answer might be, when to start writing
your own classes. That depends on the application. A simple file filter
(aka grep and similar) can be written without the intervention of new
classes. But even for this it might be reasonable to create your own
class. For example, if you have to read the whole file before you can
process it it is often reasonable to create one or more classes that hold
the data from the file in a format that makes access convenient.
So, I guess it boils down to: we don’t decide when, we just always do.
I tend to create classes even for really simple apps, because Ruby
executes everything as it finds it, meaning procedural code needs to
be organised bottom-up.
Putting things in classes (including a method “main”) allows you to
organise your code how you like, and then just call
MyApp.main
at the end.
Gavin
···
On Wednesday, April 2, 2003, 2:47:15 AM, Robert wrote:
The more interesting question to answer might be, when to start writing
your own classes. That depends on the application. A simple file filter
(aka grep and similar) can be written without the intervention of new
classes.
“Gavin Sinclair” gsinclair@soyabean.com.au schrieb im Newsbeitrag
news:15081712235.20030402193331@soyabean.com.au…
I tend to create classes even for really simple apps, because Ruby
executes everything as it finds it, meaning procedural code needs to
be organised bottom-up.
That’s an interesting point of view I’ve never thought of.
Putting things in classes (including a method “main”) allows you to
organise your code how you like, and then just call
MyApp.main
at the end.
You don’t come from the Java camp, do you?
robert
···
On Wednesday, April 2, 2003, 2:47:15 AM, Robert wrote:
The more interesting question to answer might be, when to start writing
your own classes. That depends on the application. A simple file filter
(aka grep and similar) can be written without the intervention of new
classes.
I tend to create classes even for really simple apps, because Ruby
executes everything as it finds it, meaning procedural code needs to
be organised bottom-up.
Putting things in classes (including a method “main”) allows you to
organise your code how you like, and then just call
MyApp.main
at the end.
True, but so does:
def main
…
end
main
David
···
On Wed, 2 Apr 2003, Gavin Sinclair wrote:
On Wednesday, April 2, 2003, 2:47:15 AM, Robert wrote:
Yeah, Java was perhaps my most-practiced language before Ruby,
although there was a brief stopover at Perl.
I use the convention above not for any love of Java, but for the sake
of having a convention And the word “main” has stuck with me for
many years now.
Gavin
···
On Wednesday, April 2, 2003, 10:30:47 PM, Robert wrote:
“Gavin Sinclair” gsinclair@soyabean.com.au schrieb im Newsbeitrag
news:15081712235.20030402193331@soyabean.com.au…
On Wednesday, April 2, 2003, 2:47:15 AM, Robert wrote:
I tend to create classes even for really simple apps, because Ruby
executes everything as it finds it, meaning procedural code needs to
be organised bottom-up.
That’s an interesting point of view I’ve never thought of.
Putting things in classes (including a method “main”) allows you to
organise your code how you like, and then just call