forum-msg-id-130627-edit

Original date:2016-12-13 14:10:50 Edited by: petelomax Subject: Re: docs (OE,Phix) ? benefits of OOP but simpler

[quote _tom] I removed this OOP reference from the HOPL wiki pages.

Pete: you have the same statement in your "Introduction" page of the Phix documentation. [/quote] I'm not convinced it is an entirely bad thing to say. Anyway, regarding the original question:

Off the top of my head I might say:

Object orientation is typically described as encapsulation, inheritance, and polymorphism.

In Phix, encapsulation is achieved simply by placing code in a separate file. Unless you explicitly declare identifiers as global, they are invisible to the outside world, and of course you can modify anything private at any time and nothing else will ever know.

Phix programs are naturally polymorphic. For instance the standard sort() can accept integers, floating points, strings, and/or nested sequences, or any mix of them, without any trouble. In particular you simply do not need umpteen versions of a routine, one that accepts an integer, one a float, yet another one that takes a double, ad nauseum. And for the same reason, there simply is no need for generics, because Phix programs are naturally generic. Try making a list of mixed floats and strings in other programming languages and you will regret it.

In recent years, the latest catchphrase is "favour composition over inheritance", so the lack of any form of inheritance in Phix could even be viewed as an asset, and the ability to store anything at all as an element of a sequence means composition is a given, though it would need to be an index of some kind, rather than the whole thing.

It is fair to say that Phix does not provide any automated form of dynamic despatch, but it is not especially difficult to maintain a table of routine_ids - no more than, say, to declare all the available virtual methods in a separate header file. If you are a strong advocate of object orientated methodology, you may baulk at replacing thing.method() with having to select and include an oo framework and calling vproc(thing,"method",{}). More can and should be done on that front - as much as I may personally believe that it is all hogwash and snake oil, it is in fact a reasonable paradigm and a blanket refusal to add even "oo-lite" features into the core language is not exactly helpful. Note however that it is highly unlikely that Phix will ever enforce oo like some other programming languages do.

Ultimately, of course, if you are already married to the "one true way", whatever that may be in your opinion, no other language will replace the one you already love.

The truth is not that Phix can do all those wacky inside-out things that oop needs, but that it simply does not need them.

Disclaimer: the above may sound too apologetic over the lack of oo features, and we probably don't want that. Maybe the best strategy for Phix/OE is to catch those who fall off the oo bandwagon and offer them something simpler but just as capable?

Pete

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu