OO vs. procedural programming

“Peter Ensch” nobody@bogus.com schrieb im Newsbeitrag
news:b6cdeh$i8v$1@tilde.itg.ti.com

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. :slight_smile:

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. :slight_smile:

Regards

robert

I people don’t always write OO programs in Ruby, how do
they decide when to do so?
[…]
then you automatically have to code the OO way.

Hey it didn’t force me into that! :slight_smile:
(…it just slipped in silently – or does its slippery constantly)

···

On Wed, Apr 02, 2003 at 01:47:15AM +0900, Robert Klemme wrote:


---- WBR, Michael Shigorin mike@altlinux.ru
------ Linux.Kiev http://www.linux.kiev.ua/

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? :slight_smile:

robert
···

On Wednesday, April 2, 2003, 2:47:15 AM, Robert wrote:

Hi –

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

:slight_smile:

David

···

On Wed, 2 Apr 2003, Gavin Sinclair wrote:

On Wednesday, April 2, 2003, 2:47:15 AM, Robert wrote:


David Alan Black
home: dblack@superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

MyApp.main

at the end.

You don’t come from the Java camp, do you? :slight_smile:

I do believe there was a precedent to Java’s “main()”… =D

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 :slight_smile: 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

MyApp.main

at the end.

You don’t come from the Java camp, do you? :slight_smile:

“Mike Campbell” michael_s_campbell@yahoo.com schrieb im Newsbeitrag
news:NFBBKBEMGLGCIPPFGHOLMEPGDGAA.michael_s_campbell@yahoo.com

MyApp.main

at the end.

You don’t come from the Java camp, do you? :slight_smile:

I do believe there was a precedent to Java’s “main()”… =D

Hm… CCCant remember… :-))

However: C did not define main() as part of a class, or did I miss
something?

Cheers

robert

MyApp.main

at the end.

You don’t come from the Java camp, do you? :slight_smile:

I do believe there was a precedent to Java’s “main()”… =D

Hm… CCCant remember… :-))

However: C did not define main() as part of a class, or did I miss
something?

Since C doesn’t HAVE classes… =)

C++ doesn’t have it as a class method either. Something I to this
day find more intuitive, actually.

···

Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more