Re: But is it Object-Oriented?

Daniel Bonniot <[email protected]>
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
>(I do realize that the following was given as an example of adding an
>operation when "extending" existing code.)
>
>I'd think of this as an ADT style of programming, something I would do
>just the same in Modula-2:
>
>   public class StackUtils {
>      public static void clear(Stack s) {
>         while (! s.isEmpty())
>            s.pop();
>      }
>   }
>   StackUtils.clear(myStack)
>
>Even in Java wouldn't the OO style of programming be:
>
>   myStack.clear(); // inherit *instance method* clear() from Vector
>
>Like everything else in an OO language, the method 'clear' is a feature
>of an object (and that has it's pros & cons). 
>  
>
OK, it happens that clear() is defined in Vector, and that Stack extends 
Vector, so this was not the good exemple. My point was that if the 
designer left-out/forgot an operation related to a class, you cannot add 
naturally that operation in an importing package (while maybe that 
operation only makes sense there, if it doesn't have a general prupose). 
You could find plenty of examples dealing with strings (which is why you 
see so many StringUtils classes).

So I guess what it boilds down to is that one of the cons of 
mono-methods is that they limit the way you can define new operations 
and the way you organize your code in packages/modules.

BTW, what are their pros?

>(In contrast, Bjarne Stroustrup has argued that the methods which
>support the class invariant have to be encapsulated in the class, and
>other "utility methods" should be written as functions in the style you
>demonstrated.)
>
>AFAIK in Java or C# we can both have methods that are "encapsulated" in
>a class (in the OO style) and functions (in the ADT style).
>
>AFAIK in Nice, no methods are "encapsulated" in a class (or interface).
>Nice is a multimethod language - we use generic functions - and despite
>the syntax sugar, that makes it quite different from an OO language
>  
>
Yes. Fundamentally, I agree that Nice is based on a quite different form 
of OO (or different from class-based OO). The good part is that that 
form is more powerful; the bad part is that it's much less known, and so 
newcomers need to learn it. The whole question is: when and how?

My way to look at it is: multi-methods allow you to do everything that 
mono-methods do. So it's possible to "make them look like" mono-methods 
(that's the syntactic sugar), so that new users can feel at home and be 
able to write code very soon.

Besides that, multi-methods are usable in other situations where, 
without them, you would need to work around the limitations of 
mono-methods (visitor pattern, static methods, manual dispatch, ...). 
When you get there, this is the time to learn the features that you need 
(declare a method outside a class, dispatch on several arguments).

I think it is fair to say that a multi-method is exactly what you get 
when you take mono-methods, and you add them the ability to dispatch on 
several arguments and to be declared outside classes. Maybe the 
documentation is not telling this story, and maybe it should.

Furthermore, I agree this is not the most direct definition. So it could 
be worth to also present the "pure" view too, and that would be most 
suitable for beginer programmers and people not familiar with 
class-based OO. But for those that are familiar with class-based OO, I 
think the first presentation is more progressive, because it uses what 
they already know, and shows the difference. I don't think you really 
get a wrong picture. Still, it might be that when they are familiar with 
it, they can also take a look at the "pure" presentation, and they will 
see how this is a different, simpler way to look at the same thing.

>(and that has it's pros & cons). 
>  
>
What cons? ;-)

>The web presentation begins "Nice is a new object-oriented programming
>language based on Java." 
>
>IMO that sets the wrong expectations - it's misleading.
>  
>
Agreed. What about:

Nice is a new programming language. It extends the ideas behind 
object-orientation in order to better support modular programming and 
static type safety. it also incorporates features from functional 
programming, and puts into practice state-of-the-art results from 
academic research. This results in more expressivity, modularity and safety.

Cheers,

Daniel



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.