Welcome, Guest. Please login or register.

Author Topic: Which is better? OS 4 or Morph OS . . .  (Read 11173 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« on: October 08, 2005, 08:07:40 PM »
Quote

Piru wrote:

In fact, I'm yet to see any feasible explanation why interfaces would give any benefit over other methods of handling library calls.


Speaking personally, I like interfaces for several reasons, mostly due the the fact that they share several important conceptual features with C++ classes:

1) An interface defines a namespace. This allows me to create my own interfaces that have function names that would otherwise clash with the OS ones. IKarl->AllocVec() is totally different from IExec->AllocVec(). Both can happily coexist in the same source.

2) Depending on what your interface designed is for, you can happily create multiple instances of a particular interface. Each instance has its own data area. Whilst this doesn't really apply to the legacy OS interfaces, thinking forwards it is very useful.
For example, I might design some strange hardware abstraction layer where each device has a common interface, say IKarlDevice. Let's assume I have defined an Initialize() method for this interface. I can have an instance per device since I'm no longer dealing with global functions. So I can happily iterate my way down a List of instances of IKarlDevice and call their individual Initalize() methods.

3) Builds on points (1) and (2) really. There is no reason why I can't have several libraries that implement a particular interface. So my system might load several different implementations of my device interface for specific devices. Or to make it a bit shorter, interfaces are inherently polymorphic.

As a more tangible example, consider MUI/Reaction etc. The BOOPSI calling mechanism is just awful. Reimplementing them using interfaces would likely give more compact code that could run a hell of a lot faster. I am sure a button->DoLayout() is an order of magnitude faster than a DoMethod() call via the boopsi dispatcher :-)

Of course I don't expect that will happen, and really, nor should it. Might as well design a completely new, interface centric  system in future.

I'm not saying you cant reproduce some of this with OS3.x style libraries, but it is no where near as elegant to accomplish.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #1 on: October 08, 2005, 08:51:05 PM »
@Piru

Look at them all together rather than point by point. For example, who says IKarl has a global pointer? IKarl_AllocVec() implies some global scope function, interfaces, and consequently all their methods, can exist in any scope a variable can.

Unlike C++ namespaces, an interface method is actually a function pointer within the interface structure. You can't pollute it since a structure can only contain uniquely named members. When I said it defined a namespace, I meant IExec and IKarl are seperate structures that can freely contain identically named member functions.

As for the macro stuff, I prefer not to use it at all in clean OS4 compatible code. It is purely for 3.x source compatibility. If that is not important to you, you don't have to use it.

How easy is it to create a list of library instances within a single task, iterate the instances individually and call methods per instance? Sure it can be done, but how straightforward is it to do?

Again with the polymorphic stuff, you can do it using libries, I never said otherwise. Interfaces, however, bring all of these under a very simple to use and implement system.

Your counter arguments are remind me of those made by people comparing writing object oriented code in C versus C++. Nobody says you cant write object oriented code C, or structured code in pascal. It is a question of how straightforward and clean it is to accomplish.

As for your final point, libraries are also single system. They apply only to amigaos and compatibles, so that argument doesn't really apply, unless you want strict compatibility source with 3.x. In that case, sure you can just use the macro level stuff and do that. I've never yet failed to compile any 3.x stuff under 4.0.

Clearly you don't regard interfaces as a useful idea. That's your opinion and I respect that. However, I feel they are genuinely useful and have a lot of potential.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #2 on: October 08, 2005, 08:57:35 PM »
Quote

AMIGAZ wrote:
lol...is this the start of a computer-geek battle..
I´m glad I don´t know so much about programming :D


Not really, just a difference of opinion on something.

I've never cared a less about the red v blue thing.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #3 on: October 08, 2005, 09:00:40 PM »
Quote

Piru wrote:
@Karlos

Maybe it should be pointed out that I also find C++ horrible bloaty nonsense and broken by design aswell.

I'd happily take Java any day, instead.


:-D You know somehow I guessed.

Quote
That being said, I still consider the "interfaces" a bad idea, regardless, at least if you're concerned in moving source between differnet platforms (that is different AmigaOS and compatibles).


How? If you write 3.x style code it compiles in OS4. Unless you are writing the libraries themselves rather than applications it need not affect you.

Quote
I firmly stand behind my claim that interfaces give absolutely no benefit at all over MorphOS.


I didn't say they did. I said I found Interfaces better by design than 3.x style libraries. I've nothing against MOS.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #4 on: October 08, 2005, 09:05:35 PM »
Quote

Piru wrote:
@AMIGAZ

Don't worry, this perfectly mature debate. People don't always need to agree.


I'm far too old for all that trolly nonsense :-D

Off topic a bit, what's your take on Objective C?
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #5 on: October 08, 2005, 09:11:53 PM »
Quote

Piru wrote:
@AMIGAZ

Don't worry, this perfectly mature debate. People don't always need to agree.


No it isn't and yes they do..

/* ducks */
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #6 on: October 08, 2005, 09:29:48 PM »
@Piru

True about the decision, but deciding to code anything for amigaos/like stuff is a decision in itself these  days :-(

I'd argue that interfaces are a little better than function pointer arrays (and hey, I am like the worlds biggest fan of function LUT, just ask Patrik) in that at least they are not anonymous. Give me blah->method(arg1, arg2) over table[n](arg1, arg2) anyday. Don't forget that a pointer to the instance of the interface is always passed to the function implicitly too (akin to the C++ 'this' pointer), which you'd explicitly have to do for normal function pointer.

What I'd like to see is the interface concept opened up for 3.x compatibles. That would really eliminate the major objection that interfaces force you to stay on one path. Of course, that decision is well and truly out of my hands.

-edit-

Actually, thinking about what you said of the macro stuff earlier, it occured that it doesent really clash. What I mean is:

AllocVec() is just a #define for IExec->AllocVec()

It shouldn't ever clash with any other interface's AllocVec() unless you want to macroize those interface calls too.

IKarl->AllocVec() would sit happily with AllocVec() (as a define). If I needed to make it 3.x source compatible, I could always #define KarlAllocVec().
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #7 on: October 08, 2005, 09:35:38 PM »
Actually it is precisely due to arguments such as these that I started my own C++ framework project in the first place :lol:

Except there it extends to rather more systems than the amiga compatibles :-)

These days I shudder when I see explicit OS calls :-D
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #8 on: October 08, 2005, 09:52:05 PM »
True, you just need a constant for n. My main point is that the interface is a bit more than a function pointer table. It is the instance data too and the calling semantics to ensure that the instance data is always passed transparently to any function. For example, IExec->AllocVec(size, flags) actually compiles to IExec->AllocVec(IExec, size, flags).

-edit-

Of course, the anonymity of function LUT is one of its principal advantages. I use them for all sorts of things (presently writing a VM where the opcode value looks up a handler function, for example)...
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #9 on: October 08, 2005, 10:05:42 PM »
Quote
Now, is it just me or doesn't this looks just like some half-assed OO implementation for C?


It does when you see the implementation of it, yes. Of course you don't see the implementation, which is the point.

If you compare what you have just written with a typical BOOPSI object, for example, can you claim this code is not an order of magnitude cleaner and simpler? True boopsi supports more runtime flexibility (closer to smalltalk than C++) but I have never seen anybody make use this.

Also your code means that foo() and bleh() are no longer nasty globals so it won't clash with the interface I might want to add. After all, foo() is the most fundamental method ever named :-D

-edit-

Surely you can see an inherent charm in the approach of your code over a 3.x library that defines a global foo() and bleh() ?

Namespacing aside, you implemented it totally in C, no asm, pragmas or other stuff. Hence it is potentially portable across more than the amiga range of platforms.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #10 on: October 08, 2005, 10:39:35 PM »
Quote

Piru wrote:

Nope, if it means you break all source code compatibily to old systems that had foo(), bar() and bleh() in the API using normal library. If this was some new library that actually benefited from the interface (different implementations used internally), then it would potentially pay off.


Now here, I think is the difference between us. For me, the backwards compatibility issue is an implementation detail. I'm more interested in what I can do with an interface rather than how it replaces the old library call. I look at them as a foundation for runtime loadable class implementations more than a simple library mechanism. That happens to holds a lot of interest for me.

Quote
You can implement library fully in C as you're aware, I'm sure. Pragmas, inlines and other stuff is easily generated from whatever "library definition" you might use (be it XML or fd + protos).


Yes, of course, but what I meant is, your example is portable and clean across multiple platforms without the need for these other components. The 3.x library interface s not.

Quote
Also, as a sidenote: if the original library defined the foo, bar and bleh functions, they really aren't global. They're actually the base + offset (and base can change per opener, like happens with bsdsocket!). You're not limited to using inlines, you can well use other means of calling them... Naturally if you use #define inlines then they're global namespace, but there is no need for this to be, nor is the limitation set by the actual library implementation in any way.


Yes but using these alternative mechanisms to access the library functions are no more 3.x source compatible than interfaces would be.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #11 on: October 08, 2005, 10:43:18 PM »
@Piru

:lol: we are so off topic :-D
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #12 on: October 08, 2005, 10:58:57 PM »
@Piru

Regarding the OS:

I don't argue with you that replacing the old mechanism causes some issues. I am sure that doing so, was to bring about a cleaner system in the long run. Phasing out old stuff gradually can be messy. Heck, I'm using windows here, the king of half baked transformation. They (the OS4 developers I mean) wanted something more powerful to replace libraries and took the opportunity to implement it at a time when the whole OS was undergoing fundamental rework anyway, so I don't begrudge them that decision.

Now as for benefits, I really do see things like heirarchial driver sets, plugins, datatypes, gui objects and all such things that are inherently OO by nature can benefit from the new model, since, well it is an OO design.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #13 on: October 08, 2005, 11:09:24 PM »
I was more thinking of new systems to usurp the old ones. Things like datatypes, in their present guise are fundametally flawed IMHO. But that is another discussion entirely and we are off topic enough already :-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show all replies
Re: Which is better? OS 4 or Morph OS . . .
« Reply #14 on: October 09, 2005, 12:42:23 PM »
@itix

To begin, I said interfaces share several important facets with C++ classes, I didn't say they were equivalent C++ classes. Therefore, inheritence is not something that is not implicit in the interface design as ultimately C is not an OO language. However, that doesn't mean it is not supported at all...

Quote
How inheritance would work? For example if you subclass root class and ad your own methods -- how root class is supposed to handle them?


Remember, a parent class never does have any knowledge of any of any of its childrens' unique methods or properties. Consider an actual C++ class heirarchy. If your parent class is HouseholdPet, and you have sublcasses of GoldFish, Cat, Dog, Budgie, etc, *only* the interface defined by HouseholdPet is common to all. Each implements the HouseholdPet interface and adds some unique methodst too. Dog might add a method chasePostman() to the existing set of methods it inherited from HouseholdPet.

You cant expect to call a Dog specific method such as chasePostman() via an "HouseholdPet* pet" (unless you use RTTI and do a dynamic_castpet and check it was valid) as your particluar pet might be an instance of GoldFish.

-edit-

Mind you, that would be something to see :roflmao:

-/edit-

In this regard, interfaces are no different to classes. I can't realistically call a method of a sub interface via a handle to the parent that the parent does not already advertise.

The second issue is polymorphism. Customising methods of the parent interface to suit the specific child so that different instances of an interface might perform the same method call differently. This is perfectly doable. Remember, the methods are really just embedded function pointers within the interface structure and can be changed. If I cloned an instance of IKarlDevice, I can provide my own function to handle the Initialize() method specifically for that one instance (similar to SetFunction() on a library).

Quote
On the other hand you need a class pointer to call super class. On the other hand you must access your local object data somehow


How do I call the 'parent' implementation's method within my method? Well, provided I just don't blitely throw the old pointer away, I can use it to call the original IKarlDevice's implementation too, if I need to. OK, this is not quite as nice as being able to do a java esque "super()" call but it is achievable without that much fuss. I dont see libraries having it any easier.

Furthermore, since interfaces are just structures, provided I give them unique names, I can create any number of cast compatible clones of struct IKarlDevice, eg struct IKarlKeyobard, struct IKarlMouse (adding any unique stuff only at the end of the structure, again like library bases do). Each of these can implemented by totally different libraries. This allows me, if I need to, to handle instances of totally different implementations (as opposed to just modifying a single instances function pointer) of an interface without having to exactly know what they are.

Quote
If you look into OS4 documentation you will find out interface has
a) function table at positive offset
b) data at negative offset

AmigaOS 3 library base has
a) function table at negative offset
b) data at positive offset


That's the implementation difference between them. How they can be used by the developer and they can assist the developer in achieving his goals are more important.

I stand by the observation that interfaces simpify the creation of this type of construct compared to achieving the same thing with 3.x libraries (or even boopsi classes).

If you prefer doing this type of thing with 3.x style library bases and the 3.x source compatible ways of calling their code, that is entirely up to you. I personally find it much less cumbersome to accomplish this type of thing with the interface syntax.
int p; // A