LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-05-2011, 07:44 AM   #1
Laythe
LQ Newbie
 
Registered: Nov 2010
Posts: 18
Blog Entries: 1

Rep: Reputation: 0
Does passing array to methods can lead to procedural paradigm?


Greetings EveryOne

Does passing array to methods can lead to procedural paradigm?

Is it better avoided or it can be done while preserving an oo design?

Thank You In Advance

Note for thous who might get annoyed this question been asked here
http://www.java-forums.org/new-java/...-paradigm.html

no one answered so i am asking again.
 
Old 12-05-2011, 08:51 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 1,160

Rep: Reputation: 258Reputation: 258Reputation: 258
There are other languages besides Java.

What does passing arrays as parameters have to do with procedural vs. OO?
 
Old 12-05-2011, 11:51 AM   #3
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 608

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Hi.
I think OP means something like this (from Wikipedia article)
Quote:
The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines, whereas in object-oriented programming it is to break down a programming task into data types (classes) that associate behavior (methods) with data (members or attributes). The most important distinction is whereas procedural programming uses procedures to operate on data structures, object-oriented programming bundles the two together so an "object", which is an instance of a class, operates on its "own" data structure.
Which way to prefer, I think, is a matter of taste and general architecture of your software.
 
Old 12-05-2011, 12:03 PM   #4
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by Laythe View Post
Does passing array to methods can lead to procedural paradigm?
What is the practical application of this question?

Quote:
Originally Posted by firstfire View Post
Hi.
I think OP means something like this
In C++ aside from one difference array is hardly distinguishable from instance of class that has operator[] defined.
The difference is that array cannot be passed by value and is passed by pointer instead. If language has a feature, it means there are situations when the feature is useful.

Last edited by SigTerm; 12-05-2011 at 02:19 PM.
 
Old 12-05-2011, 12:34 PM   #5
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 608

Rep: Reputation: 352Reputation: 352Reputation: 352Reputation: 352
Quote:
Originally Posted by SigTerm View Post
In C++ aside from one difference array is hardly distinguishable from object that has operator[] defined.
The difference is that array cannot be passed by value and is passed by pointer instead. If language has a feature, it means there are situations when the feature is useful.
I know that. Still, in C++ (or any OO language) you may implement, for example, sorting as a procedure or as a method of an array class. There are no general recipe of what to prefer.

Last edited by firstfire; 12-05-2011 at 12:38 PM.
 
Old 12-05-2011, 01:14 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by SigTerm View Post
What is the practical application of this question?


In C++ aside from one difference array is hardly distinguishable from object that has operator[] defined.
The difference is that array cannot be passed by value and is passed by pointer instead. If language has a feature, it means there are situations when the feature is useful.
In C++ object is a memory area (with some limitations).

Last edited by Sergei Steshenko; 12-05-2011 at 02:13 PM.
 
Old 12-05-2011, 01:15 PM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by Laythe View Post
Greetings EveryOne

Does passing array to methods can lead to procedural paradigm?

Is it better avoided or it can be done while preserving an oo design?

Thank You In Advance

Note for thous who might get annoyed this question been asked here
http://www.java-forums.org/new-java/...-paradigm.html

no one answered so i am asking again.
What is OO paradigm, why do you need it in the first place and why does array not fit OO paradigm ?
 
Old 12-05-2011, 02:01 PM   #8
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by Sergei Steshenko View Post
In C++ object is a memory area (with some limitation).
You might want to explain your remark - array is also a memory area.
 
Old 12-05-2011, 02:12 PM   #9
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by SigTerm View Post
You might want to explain your remark - array is also a memory area.
The remark is taken directly from the standard ('C++ Standard - ANSI ISO IEC 14882 2003.pdf', pages 4 .. 5) :

Quote:
1.8 The C++ object model [intro.object]
1 The constructs in a C++ program create, destroy, refer to, access, and manipulate objects. An object is a
region of storage
. [Note: A function is not an object, regardless of whether or not it occupies storage in the
way that objects do. ] An object is created by a definition (3.1), by a new-expression (5.3.4) or by the
implementation (12.2) when needed. The properties of an object are determined when the object is created.
An object can have a name (clause 3). An object has a storage duration (3.7) which influences its lifetime
(3.8). An object has a type (3.9). The term object type refers to the type with which the object is created.
4
 ISO/IEC ISO/IEC 14882:2003(E)
1 General 1.8 The C++ object model
Some objects are polymorphic (10.3); the implementation generates information associated with each such
object that makes it possible to determine that object’s type during program execution. For other objects,
the interpretation of the values found therein is determined by the type of the expressions (clause 5) used to
access them.
2 Objects can contain other objects, called sub-objects. A sub-object can be a member sub-object (9.2), a
base class sub-object (clause 10), or an array element. An object that is not a sub-object of any other object
is called a complete object.
3 For every object x, there is some object called the complete object of x, determined as follows:
— If x is a complete object, then x is the complete object of x.
— Otherwise, the complete object of x is the complete object of the (unique) object that contains x.
4 If a complete object, a data member (9.2), or an array element is of class type, its type is considered the
most derived class, to distinguish it from the class type of any base class subobject; an object of a most
derived class type is called a most derived object.
5 Unless it is a bit-field (9.6), a most derived object shall have a non-zero size and shall occupy one or more
4)
bytes of storage. Base class sub-objects may have zero size. An object of POD type (3.9) shall occupy
contiguous bytes of storage.
6 [Note: C++ provides a variety of built-in types and several ways of composing new types from existing
types (3.9). ]
.

What to explain ? It's the definition, and as such is learned by heart, and not explained. I.e. definitions are applied to objects (in the English sense of the word) - if an object matches a definition, it is the object defined by the definition - by definition of definition .

So, I truly do not understand the OP's question.
 
Old 12-05-2011, 02:23 PM   #10
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by Sergei Steshenko View Post
What to explain ?
Well, I wanted to know what you were getting at in post #8. It looks like your point is that array is a memory area which means it is an object according to definition in C++ standard. Is this what you meant to say?

P.S. It seems I used slightly incorrect terminology in #4. Fixed.
 
Old 12-05-2011, 02:28 PM   #11
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by SigTerm View Post
Well, I wanted to know what you were getting at in post #8. It looks like your point is that array is a memory area which means it is an object according to definition in C++ standard. Is this what you meant to say?

P.S. It seems I used slightly incorrect terminology in #4. Fixed.
First of all yes, array is an object in terms of C++. Secondly, I still don't get how using arrays contradicts OO paradigm.

It might contradict functional paradigm: http://citeseerx.ist.psu.edu/viewdoc...10.1.1.36.8500 , but we are not talking about it, are we ?
 
Old 12-05-2011, 02:36 PM   #12
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by Sergei Steshenko View Post
First of all yes, array is an object in terms of C++.
Okay then.

Quote:
Originally Posted by Sergei Steshenko View Post
Secondly, I still don't get how using arrays contradicts OO paradigm.
AFAIK, when talking about OOP, some people think that "object-oriented" == "has classes".
Array is not exactly a class, but can be thought of as class that has several operators defined.
 
Old 12-05-2011, 03:09 PM   #13
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 451Reputation: 451Reputation: 451Reputation: 451Reputation: 451
Quote:
Originally Posted by SigTerm View Post

...
AFAIK, when talking about OOP, some people think that "object-oriented" == "has classes".
Array is not exactly a class, but can be thought of as class that has several operators defined.
So what ? I.e. how about

Code:
class DummyIntArrayWrapper
  {
  public:
    int array_to_be_wrapped[10];
  };
? There is a (more or less useless) class here. The class is basically a namespace (I am not talking about strict C++ definition) here. Or a type name - again, this is not according to strict definition. Or one can see it as functionally/conceptually more or less like 'typedef' in "C".

Typically (but this is not required by strict definition) classes are "bags" for interrelated data and processing the data function items.
 
Old 12-05-2011, 11:51 PM   #14
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by Sergei Steshenko View Post
So what ?
*I* don't think that "OOP == classes",

Quote:
Originally Posted by Sergei Steshenko View Post
The class is basically a namespace
and *I* know/understand that, so ask OP instead. He seems to be the one confused.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing array from one perl script to another prasannarathi Programming 2 12-14-2010 08:02 PM
[SOLVED] Passing array to thread function zak100 Programming 4 08-12-2010 11:07 AM
Passing Array Elements to functions melikai Programming 4 10-31-2006 10:27 PM
passing int array to thread? Thinking Programming 2 09-21-2005 11:00 AM
segfault when passing array[] as argument froboozle Programming 11 06-28-2005 03:06 PM


All times are GMT -5. The time now is 04:17 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration