Arc Forumnew | comments | leaders | submitlogin
1 point by binx 6117 days ago | link | parent

In OO languages, methods implicitly bind self and the object to which the message is sent. Should we modify them to let self be explicitly bound?


5 points by raymyers 6117 days ago | link

Most OO languages don't just "implicitly bind" self; self (or this) is usually a reserved word. A conflict with another variable is made impossible because you can't say "int this = 4" in Java or C++. As pointed out, Python already makes the binding explicit.

Further, let us imagine for a moment that lambda closures and class instances are ... different things.

-----

4 points by cooldude127 6117 days ago | link

not all of them. python, for example, does it explicitly. self is a convention, but you can call it anything you want.

and arc shouldn't do something just because other languages do it. it should do things based on whether they are the best way to do it. and i personally think it's a bad idea to introduce those kind of automatic symbol bindings into constructs which are so fundamental to the language, like fn and if.

-----

2 points by vrk 6116 days ago | link

Pardon the tangent, but in Perl 5 what you call the instance of the class is up to you. Conventionally it's $self, and the constructor is often new(), but these can be whatever you want. Unless you use a special CPAN module that does the work for you, the common idiom in declaring methods is

  sub method {
    my $self = shift;
    ...
  }
You could name it $myself, $this, or even $the_object if you wanted.

-----