List Info

Thread: "ocaml_beginners"::[] polymorphic methods (and I've read the same named section of the manual :-)




"ocaml_beginners"::[] polymorphic methods (and I've read the same named section of the manual :-)
user name
2006-07-27 18:08:39
On Thu, 27 Jul 2006, vincent.aravantinos wrote:

> --- In ocaml_beginners@yahoogroups.com, Richard Jones
<rich...> wrote:
>
>> In general you might want to avoid using objects,
>
> Should I always try to avoid objects ? Why are they a
"bad" thing ?

Certainly not. It's more that there are so many
"popular" languages where 
you are forced to use them simply to emulate the following:
- records,
- closures,
- modules

I find the following aspects of the OCaml objects useful:
- using them as records when performance (memory and speed)
is not
   critical, but differents types of objects may share
fields with
   identical names
- immediate objects can be used as records without a type
declaration or
   tuples with labels (mostly to return multiple items from
a function)
- class inheritance (very useful when needed but very rarely
needed)
- objects with a mutable state, a standard set of methods,
plus possibly
   non-standard methods: see h
ttp://www.ocaml-programming.de/rec/IO-Classes.html


>> particularly for containers - I mean who needs a
"container" object
>> for lists?  Just use a list.
>
> Of course my example is useless, it's just to explain
my problem.


--
Martin Jambon, PhD
http://martin.jambon.fre
e.fr


Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 


"ocaml_beginners"::[] polymorphic methods (and I've read the same named section of the manual :-)
user name
2006-07-28 07:37:28
--- In ocaml_beginners@yahoogroups.com, Martin Jambon 
<martin_jambon...> wrote:

> > Should I always try to avoid objects ? Why are
they a "bad" 
thing ?
> 
> Certainly not. It's more that there are so many
"popular" languages 
where 
> you are forced to use them simply to emulate the
following:
> - records,
> - closures,
> - modules
> 
> I find the following aspects of the OCaml objects
useful:
> - using them as records when performance (memory and
speed) is not
>    critical, but differents types of objects may share
fields with
>    identical names
> - immediate objects can be used as records without a
type 
declaration or
>    tuples with labels (mostly to return multiple items
from a 
function)
> - class inheritance (very useful when needed but very
rarely needed)
> - objects with a mutable state, a standard set of
methods, plus 
possibly
>    non-standard methods: see http://www.oc
aml-programming.de/rec/IO-
Classes.html

I understand better now. In general the only usefull thing
about 
object is inheritance. The problem is that when OO languages
arrived, 
they came with things such as templates or spacenames, so
that people 
now make an amalgamate between all those notions.

But something else comes into game to my eyes :
syntactically, you 
call an object using
  obj#method params (1)
while if you implemented it as a package you would do
something like
  method obj params (2)

There is much "psychological" impact on the
programmer between the 
two syntax : in (1) we see that the method is intimately
bound to obj 
while in (2) obj is just a parameter among others.
I really believe this encourages people to use objects more
than 
classical structures, even though they don't necessarily
need 
inheritance which is intrinsic to objects.

The problem there is that I have to make a compromise
between 
understandibility of my code and its performance (as you
seem to say 
that object is slower than others). It's a pity because to
my eyes 
one of the best features of ocaml is that I can make a
program easy 
to understand but very fast indeed.


Do you agree with all that ?

Thank you all,
Vincent






Archives up to August 22, 2005 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http:/
/groups.yahoo.com/group/ocaml_beginners/

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 



[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )