POV-Ray : Newsgroups : povray.advanced-users : Object Oriented POV code Server Time
21 Nov 2026 19:40:47 EST (-0500)
  Object Oriented POV code (Message 51 to 100 of 179)  
<<< Previous 50 Messages Goto Latest 50 Messages Next 50 Messages >>>
From: Dan P
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 10:50:15
Message: <40362cb7$1@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message
news:4035eb87@news.povray.org...
> Darren New <dne### [at] sanrrcom> wrote:
>
> > Imagine Java with no inheritance of functions, only "inheritance" of
> > what java calls interfaces. Does it stop being "object oriented"? Most
> > people working in the field of designing programming languages I think
> > would say "no, it's still OO".  It still has objects, dynamic dispatch,
> > memory management, classes, instances, etc. Just not inheritance.
>
>   If you inherit class X from class Y you are saying "X is a Y" (that is,
> it implements everything Y implements and behaves like Y).
>   Y may be completely abstract, meaning that it does not implement
anything
> itself. However, deriving a class from it still means that the derived
> class "is a Y".
>   If you make a class which implements an interface you are doing
inheritance.
> Limited perhaps, but still inheritance.

I have to disagree with this: If X derives Y, X is still X, but inherits the
methods and members of Y. Also, Y is not an X -- for example, if Y was a
Stream and X was a RandomAccessStream, A RandomAccessStream contains methods
and members of a Stream, but it is still a RandomAccess Stream. A Stream is
not a RandomAccessStream from the other way around as well so X cannot
actually be Y. The Stream may contain functionality to connect to some
device, but doesn't have the capability of randomly accessing it. The
RandomAccessStream has ability to connect to some device because it
inherited that ability from a Stream. That is why the use words like
"instanceof" instead of "equals" to check if a class inherits from another
class.


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 11:48:41
Message: <40363a68@news.povray.org>
Dan P <dan### [at] yahoocom> wrote:
> 32 comparisons for /one lookup/. Multiply that by, say, 100,000 lookups for
> fur.

  Using 'new' will not help. There will still be 100000 lookups in a loop
regardless of whether there's a 'new' or not.

  The whole point in this is whether 'new' is useful or not. It isn't.

  Besides, there's no need to initialize an instance with the = operator.
You don't have to do that in C++ so why would you need to do it in this
scripting language?
  You can simply say:

  Color myColor(.1, .2, .3);

  (Instead of "Color myColor = Color(.1, .2, .3);")

  No need for 'new', and there's no ambiguity.

> >   There's a reason why in Java everything is not an instance of a class.

> I think everything should have been.

  Really? Then good luck trying to write things like "a = b+c;" in Java...

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 11:51:42
Message: <40363b1e@news.povray.org>
Dan P <dan### [at] yahoocom> wrote:
> I have to disagree with this: If X derives Y, X is still X, but inherits the
> methods and members of Y. Also, Y is not an X -- for example, if Y was a
> Stream and X was a RandomAccessStream, A RandomAccessStream contains methods
> and members of a Stream, but it is still a RandomAccess Stream. A Stream is
> not a RandomAccessStream from the other way around as well so X cannot
> actually be Y.

  Then perhaps you should read some book about OO programming.

  The "is-a" relation between inherited classes is one of the fundamental
properties of object-oriented programming. If you don't understand that
then you still have much to study.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Dan P
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 12:25:39
Message: <40364313$1@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message
news:40363a68@news.povray.org...
> Dan P <dan### [at] yahoocom> wrote:
> > 32 comparisons for /one lookup/. Multiply that by, say, 100,000 lookups
for
> > fur.
>
>   Using 'new' will not help. There will still be 100000 lookups in a loop
> regardless of whether there's a 'new' or not.
 >
>   The whole point in this is whether 'new' is useful or not. It isn't.
>
>   Besides, there's no need to initialize an instance with the = operator.
> You don't have to do that in C++ so why would you need to do it in this
> scripting language?
>   You can simply say:
>
>   Color myColor(.1, .2, .3);

For the initial instance, sure; that's why C++ didn't both putting a new
there. But, what about assigning myColor again? Are you saying just do
another Color myColor(.1, .2, .3)? I'd find that just confusing. But, that's
me.

>   (Instead of "Color myColor = Color(.1, .2, .3);")
>
>   No need for 'new', and there's no ambiguity.
>
> > >   There's a reason why in Java everything is not an instance of a
class.
>
> > I think everything should have been.
>
>   Really? Then good luck trying to write things like "a = b+c;" in Java...

Smalltalk does that nicely... I don't see the problem.

One of the disconnects here is that I keep thinking in terms of a compiled
language, not a scripting language. It would be nice if we could compile
parts of our scenes into objects. But, I fear I'm opening a Pandora's box
even suggesting such a thing. It would make for interesting conversation, I
think (but most likely, just flames).


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 13:24:03
Message: <403650c2@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> >   In what basis can you call it an OO language?

> That it has objects. Classes are a help, too.

  Then a modular language like Modula3 would be an OO language. It isn't.

> >   Having modules is not sufficient.

> OO without inheritance != modules. That's kind of the point I'm making.

  Classes without inheritance is simply a modular language.

  Don't get confused by the *name* "object-oriented". It's just a name
picked for shortness and clarity. It does not mean that having "objects"
is enough for a language to be object-oriented. The term means a lot
more than that.
  If you have modules only, that's not object-orientedness.

> >   If you inherit class X from class Y you are saying "X is a Y" (that is,
> > it implements everything Y implements and behaves like Y).

> Yes? So?

  So you are inheriting, thus you have inheritance, thus object-orientedness.

> That may be how you define it. However, note that with only interfaces, 
> you can't get a heirarchy like you're talking about.

  If you can't inherit one interface from another, thus being able to
construct a hierarchy, then it's not an object-oriented language.
What you have is basically a modular language with simple interfaces.

> >   If you make a class which implements an interface you are doing inheritance.
> > Limited perhaps, but still inheritance.

> And it's also possible to have OO languages in which there is no 
> inheritance. "Delegation-based OO" is what it's called.

  I believe you can make a hierarchy of more specific classes depending
on more abstract classes with that, can't you?

> >   (By the way, what does memory management have to do with OO?)

> The same thing modularity does. If you have to know what the lifetime of 
> an object and all its sub-objects are, then you've broken the 
> modularity. If I have to know whether my "window" instance holds onto a 
> reference to the "bitmap" item inside my "picture" instance, then the 
> author of "efficient_window" is not free to cache that information in an 
> implementation that inherits from "window".

  I may be unusually dumb today, but I did not understand anything of that.

  You are making some point about someone breaking modularity by bad
object-oriented design, or something similar. What escapes me completely
is what this has to do with object-oriented languages. (OO languages
provide you the tools; OO design is a completely different issue.)

> FWIW, Alan Kay, the guy who invented "OO", decided that dynamic dispatch 
> and memory management were the two requirements for OO.

  Those may be *minimum* requirements, but are they *sufficient*
requirements? I strongly don't think so.
  If a language doesn't even have the concept of a "module" in any shape
or form, then that language simply can't be an OO language.
  Modules are an essential tool for encapsulation and abstraction.
You simply can't have objects if you don't have modules.

  It would be quite funny to have an object-oriented language with
no objects whatsoever.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Dan P
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 14:32:46
Message: <403660de@news.povray.org>
"Darren New" <dne### [at] sanrrcom> wrote in message
news:403646af$1@news.povray.org...
> Dan P wrote:
> > However, it is
> > certainly true that if all primitives were represented by a class, it
would
> > take more memory,
>
> Actually, it's not. Especially not for compiled, strongy-typed languages.

Even better! :-)


Post a reply to this message

From: Dan P
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 14:45:13
Message: <403663c9$1@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message
news:40363b1e@news.povray.org...
> Dan P <dan### [at] yahoocom> wrote:
> > I have to disagree with this: If X derives Y, X is still X, but inherits
the
> > methods and members of Y. Also, Y is not an X -- for example, if Y was a
> > Stream and X was a RandomAccessStream, A RandomAccessStream contains
methods
> > and members of a Stream, but it is still a RandomAccess Stream. A Stream
is
> > not a RandomAccessStream from the other way around as well so X cannot
> > actually be Y.
>
>   Then perhaps you should read some book about OO programming.
>
>   The "is-a" relation between inherited classes is one of the fundamental
> properties of object-oriented programming. If you don't understand that
> then you still have much to study.

Let's think of it in more familiar terms because computer-science is
confusing. When mom squirted you out, you became an object derived from
attributes of your mom and your dad. Are you your mom or your dad? If you
were to clone yourself, is that clone a clone of your mom or your dad? If
you have a child, is that child you? No, although the child may inherit some
of your traits, like your eye color and sunny disposition, that child is not
you, it just inherits some attribute from you. Now, let's say the world sees
your son and asks, "Is he a Warp?" They would be asking, "Is he your child,"
or, "Is he in Warp's family?" That is the sense in which a person talks
about an object "being" another object.


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 15:31:24
Message: <40366e9c@news.povray.org>
In article <4035e6de@news.povray.org> , Warp <war### [at] tagpovrayorg>  wrote:

>> I think it would be a really good idea to make everything an instance of a
>> class.
>
>   There's a reason why in Java everything is not an instance of a class.

Well, it is certainly possible to make every type a class.  You just need a
fair amount of compiler/interpreter magic to handle with sufficient
efficiency what would be PODs in most languages.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 16:06:06
Message: <403676be@news.povray.org>
Dan P <dan### [at] yahoocom> wrote:
> Let's think of it in more familiar terms because computer-science is
> confusing. When mom squirted you out, you became an object derived from
> attributes of your mom and your dad.

  You clearly need a lot more studying of OOP. You are confusing the
word "inheritance" as used in colloquial language with what it means
in object-oriented programming.

  Base classes are more abstract/generic than derived classes. When you
create a class derived from another class, you are making a specialization
of that more abstract class. The derived class *is* of the same type as
the base class, but more specialized.

  The above paragraph probably doesn't tell much, so let's look at an
example:

  Suppose you have a class called LivingEntity which has certain properties
(such as whether the current instance is alive or dead).

  Now you can derive for example two classes from it: Plant and Animal.
They implement everyting LivingEntity implements (eg. the knowledge of
being alive or dead) plus more. 'Plant' has specific information common
to all plants and 'Animal' common to all animals.
  'Plant' *is a* LivingEntity because it implements everything the latter
does and can be handled as an insteance of the latter. The same goes
for 'Animal'. 'LivingEntity' is more abstract than either one because
it does not specify as much as them.

  Now suppose you inherit the classes 'Mammal' and 'Fish' from 'Animal'.
  'Fish' *is an* 'Animal', and it also *is a* 'LivingEntity' now. It's more
specific than either one because it contains more specialized info common
to all fish (but not common to eg. mammals).

  Now suppose you inherit 'Dog' from 'Mammal'.
  'Dog' is a 'Mammal', an 'Animal' and a 'LivingEntity'. 'Dog' is
more specific than 'Mammal' because it contains specific info common
to all dogs.

  If you have some function which for example handles LivingEntities,
you can give it a 'Dog' because 'Dog' *is a* 'LivingEntity'. You can also
give it a 'Fish'.

  If you have a function which handles Mammals you can also give it a 'Dog'
because 'Dog' *is a* 'Mammal'. However, you can't give it a 'Fish' because
it's not a 'Mammal'.

  'Dog' is a very specialized version of 'LivingEntity' (etc. all the
way down in the inheritance hierarchy).

  Now if you have a "mom" Dog, you can't inherit a "child" Dog from it
because the "child" Dog *is not* a "mom" Dog.
  You can create a new 'Dog' instance using the info in "mom" Dog, but
that's not inheritance.

  Inheritance should always happen like that, from a more abstract
concept to a more specialized concept. You should always be able
to say that the derived class "is a" base class. If you can't say
that, then you have a flaw in your OO design.

  For example, if you want a 'Car' class having a 'Motor', inheriting
'Car' from 'Motor' would be a flawed OO design because 'Car' *is not*
a 'Motor'.
  In this case 'Car' *has a* 'Motor', so compositionality is the tool
to use.

  Of course all this is very basic OO stuff which should be clear to
everyone making object-oriented design and programs.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 16:16:32
Message: <40367930@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> >   I may be unusually dumb today, but I did not understand anything of that.

> I'm saying that if an object's lifetime is controlled by code outside 
> the object, then you have lost the modularity. Objects are no longer 
> independent reusable items.

  Well, that's a question of good modular design. I still don't understand
how it is related to whether a specific language is OO or not.

> Not at all. I'm making a point about languages that don't do memory 
> management aren't OO, exactly because then you no longer have modules.

  So are you saying C++ is not an OO language because it doesn't have
an automatic memory management system?

> >   Modules are an essential tool for encapsulation and abstraction.
> > You simply can't have objects if you don't have modules.

> However, the term "module" is so vague as to be useless. Is UCSD Pascal 
> "modular"? How about machine code? What if each object is in a separate 
> process, so the only communication between them really is "message 
> passing", yet each object is written in a language without modules?

  Defining a module is rather simple: A module is an encapsulated entity
which has a state defined by its member attributes and a public
interface to handle that state.

  In a good OO language the state of the module can (or even better, must)
be private to the module (ie. not accessible from outside the module),
and can be handled only through the public interface.

  A module might not have a state at all (if it doesn't have any
member attributes) but it can have if needed.

  You can have instances of modules and each instance can have its own
state (independent of the other instances). These instances are called
objects.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 16:33:33
Message: <40367d2d@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> >   You can create a new 'Dog' instance using the info in "mom" Dog, but
> > that's not inheritance.

> No, that's delegation, and it's a perfectly valid way of building an 
> object-oriented language with dynamic dispatch, modularization, and all 
> those other goodies. :-)

  Creating a new instance using the data from another instance is
certainly not delegation. It's just (partial) copying.

  If you make string a="abc"; string b=a; you are *copying* the
contents of a to b. That's not delegation.

> >   Of course all this is very basic OO stuff which should be clear to
> > everyone making object-oriented design and programs.

> Yes, but the range of possibilities is wider when you start designing 
> object-oriented languages and paradigms.

  Sure you can misuse inheritance in all kind of ways, but that doesn't
mean all those wrong ways of using it are what inheritance was created
for.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 16:41:12
Message: <40367ef8@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> >   Well, that's a question of good modular design.

> Right. And if your language doesn't support modularization, it can't be 
> OO, right? :-)

  You don't need the compiler to have some automatic memory management
system in order for the language to be object-oriented.

> You can do OO programming in C++, by implementing your own memory 
> management.

  If you don't implement your own memory management that doesn't mean C++
is not an OO language. It just means your OO design is crappy, that's all.
  C++ is an OO language regardless of how someone uses it.

> Just like you can do OO programming in C by implementing 
> your own memory management and dynamic dispatch.

  You can simulate a kind of poor OO in C, but I would not call it
an OO language.
  For instance, C's "modules" (structs) can't have a public interface
and a private part and you must make quite ugly hacks to implement
dynamic binding and inheritance.

> >   In a good OO language the state of the module can (or even better, must)
> > be private to the module

> Which is exactly what the automatic memory management addresses.

  Now you completely lost me.
  What the h*** does the state of a module have to do with memory
management?

  I think you are *completely* misunderstanding what the state of
a module instance is.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 20 Feb 2004 18:52:35
Message: <40369dc3@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> myWindow.setBitmap(myBitmap);

> Does the window have a pointer to my bitmap, or did it copy the bitmap 
> into its own instance variable? In the latter case, I can free my 
> bitmap. In the former case, I cannot. That's what the internal state of 
> a module (in this case an object instance) has to do with memory management.

  If you have to wonder about things like that, then the abstraction
level of the code is not good enough.

  But anyways, the state of an object is defined by the value of its
member attributes.
  Whether or not it uses pointers or whatever to handle memory and how
you should use the class for it to work properly is irrelevant.

  To better understand what the "state" of an object means, suppose
that you can ask a LivingEntity object "are you alive?" and it
returns true or false.
  One LivingEntity can be "alive" while another can be "dead". That
is their state (or part of it).
  *How* they internally implement this information is irrelevant.

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: Tek
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 01:47:07
Message: <4036feeb$1@news.povray.org>
>   Don't confuse modules with object-orientedness.

Hmm... I just checked online and I failed to find a definition of OO which
doesn't mention inheritance, so it would appear you're right.

The thing is, my understanding was always that the fundamental part of OO is the
concept of objects, not class inheritance, hence it being called "object"
orientation, not "inheritance" orientation. I thought it was about the concept
of objects as instances of a class with associated methods, interfacing with
other objects. Modular code doesn't have instancing, at least not the way I
understand it, it just groups together associated functions and has similar
private/public philosphy.

Ah heck, I know what I want to do, and I'm gonna do it. People can classify it
later! :)

>   So basically you will have interfaces (such as in Java) but no inheritable
> classes?

No, my point is I don't need inheritance, though I think my system will be quite
capable of doing it (I've not got as far as coding that yet).

>   The problem with that is that it forces code repetition

It only forces code repetition if I want to share code, which I don't. I want to
share interfaces. Though I'll probably write some form of inheritance anyway.

> (in other words, when you make code which handles objects of
> the type of a certain interface you just have to trust that the inherited
> class implements all of its methods properly; you can't force a certain
> method to work always in a certain way).

good point, though my specific problem will only implement methods for things
that are different between objects, I'm going to allow public variables in the
interface class so the code that's processing the objects can just perform
standard manipulations itself. Not true OO philosphy, of course, but it gets the
job done, which is after all why I'm doing any of this!

-- 
Tek
www.evilsuperbrain.com


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 12:31:50
Message: <cjameshuff-00F753.12323121022004@news.povray.org>
In article <4035eb87@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

>   The "is-a" (and "has-a") relation between classes is a fundamental
> property of object-orientedness.

Minor correction: classless OO languages exist (look at prototype based 
object oriented langauges), and they do have inheritance. Inheritance is 
a necessary aspect of OOLs...if it doesn't have inheritance, it isn't 
OO. Other requirements are polymorphism and encapsulation. Modular 
programming languages have encapsulation of some kind, but lack in one 
or both of the others.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 12:42:40
Message: <cjameshuff-BF3530.12432121022004@news.povray.org>
In article <40343bd7@news.povray.org>, "Tek" <tek### [at] evilsuperbraincom> 
wrote:

> Sometimes I think it's worth reading the manual to find out what it does,
> sometimes I decide I'd rather not know. I don't think OO would make this much
> worse.


It would make it better...as Warp said, abstraction is a key feature of 
object orientation. Say someone makes a lens flare include. Internally 
it make use of all sorts of advanced tricks. You don't have to know a 
thing about that...you just use it as you would any other object.

Say you then decide you want to extend it somehow...make some aspect of 
the lens flares customized. You make a new object based on the lens 
flare object that does what you want. You don't have to know anything 
about how the lens flare object works to do this, you only have to know 
the methods by which you can interact with lens flare objects. The main 
point is that you don't have to worry about as many things at once. A 
side effect is that things get much, much shorter and simpler...instead 
of a long string of macro calls and includes, you put a few objects 
together.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 12:58:03
Message: <cjameshuff-C7CB41.12584421022004@news.povray.org>
In article <4033d465$1@news.povray.org>,
 "Dan P" <dan### [at] yahoocom> wrote:

> object ColoredSphere (v, c) inherits Sphere
> {
>     pigment
>     {
>         color = c
>     }
> }
> 
> object red_sphere = new ColoredSphere (<1, -2, 3>, new Color(1, 0, 0))
> object green_sphere = new ColoredSphere (<2, -2, 3>, new Color(0, 1, 0))

Ugh...don't blindly copy other langauges without understanding why they 
do the things they do. Your "new" statements are completely useless, 
they do nothing. Anyway, my idea of the syntax would be more like this:

def ColoredSphere: derive sphere {
    ColoredSphere(cent, rad, col) {
        sphere {cent, rad pigment {col}}
    }
}

def RedSphere: ColoredSphere {< 1,-2, 3>, 1, color < 1, 0, 0>}

ColoredSphere {< 1,-2, 3>, 1, color < 1, 0, 0>}

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 14:30:26
Message: <cjameshuff-0EC12E.14310521022004@news.povray.org>
In article <403### [at] hotmailcom>,
 andrel <a_l### [at] hotmailcom> wrote:

> Just kidding, I understand what you mean. My first reaction would be
> that pigments can be much more complicated than just a simple color.
> That is what POV makes exciting. I do not immediately see how you can
> handle that complexity in a understandable way. I will think about that
> (later).

This is not a problem. All pigments are pigments, but you can have solid 
pigments, patterned pigments with color maps, patterned pigments of 
pigments, etc...object orientation simply provides a clean way of 
classifying and managing the types of things.

red_sphere.pigment = solid_pigment {color rgb < 1, 0, 0>}

And now make it dark red:

red_sphere.pigment.color = color < 0.5, 0, 0>;

Or make it darker, no matter what color it currently is:

red_sphere.pigment.color *= 0.5;

Of course, trying to get the color of a patterned pigment is ridiculous, 
and would produce an error...POV would tell you that the pigment doesn't 
have a color. And if you want to get the color of a pigment at a certain 
point, you would do it the same way, without having to think about what 
kind of pigment it is. To use an example in current POV:

#declare MyObj = object {MyObj translate y*2}

This translates MyObj by y*2, no matter what MyObj is. It doesn't matter 
if it's a sphere or box. Now that's a bit awkward, an OO version would 
be more like:

MyObj translate: y*2;

or (Java/C++ style):

MyObj.translate(y*2);

Is that harder to understand? It simply translates MyObj, rather than 
redeclaring MyObj as a translated version of itself.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 14:35:43
Message: <4037b30f@news.povray.org>
Christopher James Huff <cja### [at] earthlinknet> wrote:
> def ColoredSphere: derive sphere {

  Is 'derive' any common OO term?

  The keyword I personally would like the most would be 'is_a', even
though I can be happy with just 'inherits'.

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 14:45:44
Message: <cjameshuff-E1A69D.14462521022004@news.povray.org>
In article <4033cd99@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

> Tom Melly <pov### [at] tomandlucouk> wrote:
> > There's a challenge... Warp? What would, IYHO, a bit of Pov-OO look like?
> 
>   If it were solely up to me, it would look as much as C++ as possible.
> 
>   However, it's not up to me. (Fortunately? ;) )

Very much so... ;-)

POV OO doesn't have the same needs, so it could be simplified quite a 
bit. No need to have any static binding, for one thing. Dynamic typing, 
much less worrying about what type something is. No need for multiple 
inheritance. Forget about templates, don't need pointers, don't need 
primitive types. Pass everything by reference, don't need explicit pass 
by reference. Just straight public inheritance, probably with categories 
and interfaces. I'm undecided about private/protected access. They would 
be a good thing to have from the language design point of view, but 
aren't really necessary...

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 14:56:53
Message: <cjameshuff-BD8E51.14573421022004@news.povray.org>
In article <40362976$1@news.povray.org>,
 "Dan P" <dan### [at] yahoocom> wrote:

> >   In the same way, adding a new name to the set of existing names requires
> > at most 32 comparisons and other operations.
> 
> 32 comparisons for /one lookup/. Multiply that by, say, 100,000 lookups for
> fur.

And you end up doing 3200000 comparisons, which really won't take long. 
Photon mapping can handle similar searches through millions of photons 
for several lighting calculations per pixel, and still render an image 
with 768K pixels in reasonable time. And that's if it can't figure out 
you're using a type some other way.


> I think everything should have been. It was just a programmer's decision to
> do that, probably because of their C/C++ experience. However, it is
> certainly true that if all primitives were represented by a class, it would
> take more memory, and even though it might only take a slight bit more
> memory, with hundreds of thousands of instances that can show as well so it
> might be a good idea to use primitives in a ray-tracing context anyway.

But we (well, most of us) aren't going to be doing heavy raytracing with 
this language...just specifying a scene for a C++ engine to render. The 
overhead for these things is nothing compared to the overhead of the 
current parser...it could be made much faster and still have the 
flexibility and simplicity of runtime lookups.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 15:07:46
Message: <cjameshuff-AA4FEE.15082721022004@news.povray.org>
In article <40363a68@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

>   Color myColor(.1, .2, .3);
> 
>   (Instead of "Color myColor = Color(.1, .2, .3);")
> 
>   No need for 'new', and there's no ambiguity.

I think you meant "redundancy"...this is something that really annoys me 
about Java, and about C++ pointers. Though the syntax I favor is more 
like:

def myColor: Color(0.1, 0.2, 0.3);

No more redundant typing, but it always starts with the same keyword, so 
it's a little easier to read.


> > >   There's a reason why in Java everything is not an instance of a class.
> 
> > I think everything should have been.
> 
>   Really? Then good luck trying to write things like "a = b+c;" in Java...

That's not a problem with C++ objects, why should it be a problem with 
Java objects? Or are you assuming that this "Objective-Java" would still 
lack operator overloading?

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 15:15:09
Message: <cjameshuff-14F32E.15155021022004@news.povray.org>
In article <4037b30f@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

> Christopher James Huff <cja### [at] earthlinknet> wrote:
> > def ColoredSphere: derive sphere {
> 
>   Is 'derive' any common OO term?
> 
>   The keyword I personally would like the most would be 'is_a', even
> though I can be happy with just 'inherits'.

Subclasses are often called derived classes. And "inherits" doesn't seem 
to fit as well...ColoredSphere doesn't inherit sphere, it inherits from 
sphere. And is_a seems to fit better as a boolean:

if(ColoredSphere is_a sphere)
    ...do something...

Or you could do what java does, and use "extends", but that doesn't 
really fit with what I wrote, which declares the class as a value. Maybe 
"extend" would work, but it seems too close to "extends", people coming 
from Java would mistype it a lot. Of course, you could eliminate the 
keyword altogether:

class ColoredSphere: sphere {...

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 16:04:04
Message: <4037c7c4@news.povray.org>
Christopher James Huff <cja### [at] earthlinknet> wrote:
> don't need primitive types.

  I disagree with this. (Unless you are ready to add operator overloading.)

> Just straight public inheritance, probably with categories 
> and interfaces.

  I have no idea what "categories" are, but interfaces are obsolete.
If you want to make an "interface", just make an abstract class.

> I'm undecided about private/protected access. They would 
> be a good thing to have from the language design point of view, but 
> aren't really necessary...

  They are necessary, believe me... ;)

  I would even go so far that member variables are always private (ie.
you *can't* make them public).
  If this is too drastic, then the language would work so that a public
member variable can be moved to the private part and overloaded with
an accessor method (which is used in the same way as when accessing
the variable directly).
  That is, if you had this: class Foo { public: int i; };
you can now replace it with something like:
class Foo { public: int i(); private: int i_; }
  Accessing 'i' would still be the same (ie. eg. "instance.i") but after
the change it calls the method i() instead of reading the variable
directly.
  (For this to work you need to be able to call a method taking no
parameters without parentheses, which shouldn't be any problem.)

  (The idea of all this is, of course, that you can later change
the implementation of 'i' without breaking potentially tons of code.)

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: Patrick Elliott
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 16:09:04
Message: <MPG.1aa176babf5c7f9c9899b2@news.povray.org>
In article <40369dc3@news.povray.org>, war### [at] tagpovrayorg says...
> Darren New <dne### [at] sanrrcom> wrote:
> > myWindow.setBitmap(myBitmap);
> 
> > Does the window have a pointer to my bitmap, or did it copy the bitmap 
> > into its own instance variable? In the latter case, I can free my 
> > bitmap. In the former case, I cannot. That's what the internal state of 
> > a module (in this case an object instance) has to do with memory management.
> 
>   If you have to wonder about things like that, then the abstraction
> level of the code is not good enough.
> 

But it can happen. In VB you can define something as passed ByVal or 
ByRef. ByRef means it will directly manipulate the originally object. 
There are times you want to do this, though it would be patently stupid 
to do so in a case where it was even possible to have more than two 
processes manipulating the same object at the same time.

-- 
void main () {
  If Schrödingers_cat is alive  
    call functional_code()
  else
    call crash_windows();
}


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 19:08:34
Message: <4037f302@news.povray.org>
Patrick Elliott <sha### [at] hotmailcom> wrote:
> But it can happen.

  Of course it can happen. And it can also happen that a function
named "multiply" calculates the square root. But that doesn't mean
it's not avoidable. It just means the design of the program/library
has a flaw.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 20:47:12
Message: <cjameshuff-9C23F0.20475321022004@news.povray.org>
In article <4037c7c4@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

> Christopher James Huff <cja### [at] earthlinknet> wrote:
> > don't need primitive types.
> 
>   I disagree with this. (Unless you are ready to add operator overloading.)

I am. I definitely would want operator overloading. I've never seen a 
good argument against it..."you can make the plus operator multiply" is 
not a good argument. I can make a "plus()" method that multiplies as 
well...I can also do a lot of useful things with the ability to use 
operators with my own types.


> > Just straight public inheritance, probably with categories 
> > and interfaces.
> 
>   I have no idea what "categories" are,

Additions to the interface of a class after the main class has been 
defined. For example, a vector class may have an OpenGL category that 
implements methods useful for using vectors with OpenGL, but which isn't 
part of the core functionality of the class, and which does not work as 
a subclass.


> but interfaces are obsolete.
> If you want to make an "interface", just make an abstract class.

Interfaces are not obsolete. As for abstract classes...what are you 
talking about?


> > I'm undecided about private/protected access. They would 
> > be a good thing to have from the language design point of view, but 
> > aren't really necessary...
> 
>   They are necessary, believe me... ;)

Sorry, but I don't. I've never accidentally tried to access a private 
member. They do serve a documentation purpose, but IMO if a language has 
them, they should be defined in a separate place, with only the public 
interface in a header file. But for POV, this would be too restrictive 
and complex, IMO.


>   I would even go so far that member variables are always private (ie.
> you *can't* make them public).

I wouldn't care for this. Think of vector member access...vec.x, vec.y, 
etc...vec.x() just adds more visual noise.


>   If this is too drastic, then the language would work so that a public
> member variable can be moved to the private part and overloaded with
> an accessor method (which is used in the same way as when accessing
> the variable directly).

I have some misgivings about the idea of accessor methods of this type, 
though it makes more sense if you have no public variables. I've 
considered this approach for Ember, which could (eventually) optimize 
the overhead away.


> class Foo { public: int i(); private: int i_; }
>   Accessing 'i' would still be the same (ie. eg. "instance.i") but after
> the change it calls the method i() instead of reading the variable
> directly.

There's also a "modifier" feature I've seen...in Ruby, I think. 
Basically you define a "myMember=" method, and this:

myObject.myMember = foo;

is equivalent to:

myObject.myMember=(foo);

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Tek
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 21:32:36
Message: <403814c4$1@news.povray.org>
"Christopher James Huff" <cja### [at] earthlinknet> wrote in message
news:cjameshuff-9C23F0.20475321022004@news.povray.org...
> I am. I definitely would want operator overloading. I've never seen a
> good argument against it..."you can make the plus operator multiply" is
> not a good argument. I can make a "plus()" method that multiplies as
> well...I can also do a lot of useful things with the ability to use
> operators with my own types.

Well, I know a good argument against it. So good in fact that it's the reason
why every games programmer I know doesn't use operator overloading: It hides
processing.

i.e. when you compile a+b, you expect it to compile to a simple add instruction,
and these days most processors can do vector maths so I'd certainly support it
being used for them. The problem is if you've defined your own type of data that
has a "+" function, you incur the cost of a function call invisibly in your
code. This is a very bad thing for time-critical applications like computer
games. Things like this make optimising an absolute nightmare.

Of course, for less speed critical stuff like describing POV scenes, I'd
wholeheartedly support it. But I'm just saying there *is* a good argument
against it.

-- 
Tek
www.evilsuperbrain.com


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 21 Feb 2004 22:26:17
Message: <cjameshuff-FA7CA8.22265921022004@news.povray.org>
In article <403814c4$1@news.povray.org>, "Tek" <tek### [at] evilsuperbraincom> 
wrote:

> Well, I know a good argument against it. So good in fact that it's the reason
> why every games programmer I know doesn't use operator overloading: It hides
> processing.

So do functions.


> i.e. when you compile a+b, you expect it to compile to a simple add 
> instruction,

If I'm adding things that the processor can add.


> and these days most processors can do vector maths so I'd certainly support 
> it being used for them.

And that could be done, as well.


> The problem is if you've defined your own type of data that has a "+" 
> function, you incur the cost of a function call invisibly in your 
> code.

No I don't. I'd have to call that function anyway, so there is precisely 
zero overhead. Even if I was wrapping numeric types that the processor 
could work on directly, the compiler would inline the code, getting rid 
of the function call.


> Of course, for less speed critical stuff like describing POV scenes, I'd
> wholeheartedly support it. But I'm just saying there *is* a good argument
> against it.

I still haven't heard one yet.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Andreas Kaiser
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 00:10:11
Message: <n8ag309hemfhpmj8jnt5j5s3k8gr66rm62@4ax.com>
On Sat, 21 Feb 2004 22:26:59 -0500, Christopher James Huff
<cja### [at] earthlinknet> wrote:

>In article <403814c4$1@news.povray.org>, "Tek" <tek### [at] evilsuperbraincom> 
>wrote:
>
>> Well, I know a good argument against it. So good in fact that it's the reason
>> why every games programmer I know doesn't use operator overloading: It hides
>> processing.

This might be a 'learning' problem if you aren't aware of the
operators 'hidden' complexity. 

>So do functions.

Yes, same problem here. There's no correlation between length of
function name and complexity. 
If you call a Trace() function you should know why.
May be to write a trace record to a log file, may be to start a render
that will be finished some months later.

>[...]

>> Of course, for less speed critical stuff like describing POV scenes, I'd
>> wholeheartedly support it. But I'm just saying there *is* a good argument
>> against it.

May be, but it isn't speed.
For example, I have rewritten POV-Ray's core using VECTOR, COLOUR and
some other classes (with appropriate operators).
It was as fast as the original version but shorter and IMHO much more
readable.
The macros required to do trivial colour/vector arithmetic are
'information hiding' in the worst sense. They blow up source code and
add visual noise which makes it sometimes almost impossible to see
what's going on.
OK, I'll stop now ;-)

>I still haven't heard one yet.


-- 
Andreas


Post a reply to this message

From: Tek
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 04:11:47
Message: <40387253$1@news.povray.org>
> >> Well, I know a good argument against it. So good in fact that it's the
reason
> >> why every games programmer I know doesn't use operator overloading: It
hides
> >> processing.
>
> This might be a 'learning' problem if you aren't aware of the
> operators 'hidden' complexity.

My point is that a+b takes a different length of time according to the types of
a and b, where as MyMatrixAddFunction(a,b) takes the same length of time always,
plus you can search for it to see where it's executed in the code, plus you can
stick a nice big comment on the prototype of it saying "//avoid calling this
unless really necessary, it's very slow" so that anyone who doesn't know how to
add these two things has to look up the function prototype and read the comment
and reconsider the code they're writing.

I'm not trying to suggest the source looks nicer with more function calls, it
certainly doesn't. I'd even say I like operator overloading a lot, it's
extremely useful in high-level programming applications. I'm merely saying that,
in practice, it makes it easier to write code that is much more complex to
execute than it is to read or write. This is both it's strongest and weakest
point.

> The macros required to do trivial colour/vector arithmetic are
> 'information hiding' in the worst sense. They blow up source code and
> add visual noise which makes it sometimes almost impossible to see
> what's going on.

As I said, I support using + for vectors since that's what it will compile to.
Although I don't really see your point about visual noise, function calls
certainly make it harder to write clearly readable code but since it's harder
all it takes is more effort. Programming isn't about making things easier for
the programmer, it's about making the end result better. In application software
or high level programming these two ideas are very compatible, but in time
critical stuff like game engines people like me have to give ourselves headaches
trying to optimize out one cycle in a render loop in order to improve the
performance of the game. Operator overloading hinders us in this quest.

Damn that made me sound so cool...

-- 
Tek
www.evilsuperbrain.com


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 05:49:40
Message: <40388944@news.povray.org>
Christopher James Huff <cja### [at] earthlinknet> wrote:
> I am. I definitely would want operator overloading. I've never seen a 
> good argument against it...

  Ask Java worshippers. They know. ;)

  I personally am all for operator overloading in the same way as you,
and it's one thing why I hate Java so much.

> > but interfaces are obsolete.
> > If you want to make an "interface", just make an abstract class.

> Interfaces are not obsolete. As for abstract classes...what are you 
> talking about?

  Interfaces are obsolete of you can make abstract classes. And why
wouldn't you (unless you want to make the language so that it does
not support virtual functions, which would limit its OO capabilities
by a whole lot).

  A class is abstract if it has pure virtual functions (that is,
the class does not implement the virtual function(s) and thus cannot
be instantiated because of this; it can only be used through
inheritance so that the derived class implements the virtual
function(s) in question).
  If every member function it has is purely virtual, then it's basically
the same thing as an interface. (This is how "interfaces" are done in C++
if you *really* need to make one.)

> >   They are necessary, believe me... ;)

> Sorry, but I don't. I've never accidentally tried to access a private 
> member.

  That's right. *You*. But that's ok only for as long as you don't
distribute that library of yours containing public member variables...
Someone will inevitably use it in the wrong way and his code can then
break with an updated version of the library.

> They do serve a documentation purpose

  That's not their purpose at all. Public and private parts have clear
maintainability, abstraction and safety purposes.
  If you can't use the library in the wrong way (ie. the compiler does
not allow you to), then you will not use it in the wrong way.

> but IMO if a language has 
> them, they should be defined in a separate place, with only the public 
> interface in a header file.

  Well, that's just a question of implementation of the interpreter/compiler.
If you can implement the interpreter so that the private part does not need
to be specified at the same place as the public part, good thing. (In C++
this is not possible for technical reasons, but in an interpreted
scripting language it may very well be possible.)

> But for POV, this would be too restrictive 
> and complex, IMO.

  What do you mean "restrictive"?
  That's like saying #local is too restrictive. It doesn't make sense.

  The private part of a class has the same visibility purpose as for
example #local has: It's safer to use #local whenever possible than
always using #declare.

> >   I would even go so far that member variables are always private (ie.
> > you *can't* make them public).

> I wouldn't care for this. Think of vector member access...vec.x, vec.y, 
> etc...vec.x() just adds more visual noise.

  If you read my article completely I suggested adding support for calling
member functions without parentheses (supposing they don't take parameters).
There's nothing problematic with that.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 06:07:31
Message: <40388d73@news.povray.org>
Tek <tek### [at] evilsuperbraincom> wrote:
> i.e. when you compile a+b, you expect it to compile to a simple add instruction,
> and these days most processors can do vector maths so I'd certainly support it
> being used for them. The problem is if you've defined your own type of data that
> has a "+" function, you incur the cost of a function call invisibly in your
> code. This is a very bad thing for time-critical applications like computer
> games. Things like this make optimising an absolute nightmare.

  This may have been true 10 years ago.

  Current compilers can usually optimize the overhead (eg. the function
call) away completely (supposing the operator function is inline).
If you make a class which uses operator overloading for simple tasks
(such as adding two internal values together) you should definitely
make them inline, after which the compiler will be able to optimize
all the overhead away.

  For example, suppose you have this (in C++):

class MyInt
{
    int value;

 public:
    MyInt(int init=0): value(init) {}

    int operator+(const MyInt& rhs) const { return value+rhs.value; }
};

  Now if you do something like this:

MyInt a=1, b=2, c;
c = a+b;

I would be very surprised if the code generated by a modern compiler
would be any different from the code which it would generate if you
replace the MyInt class with:

typedef int MyInt;


  PS. In fact, I just tested this with gcc. I added the following
method to the MyInt class for easier usage:

    operator int() { return value; }

and then made a code like this:

int foo()
{   
    MyInt a=1, b=2, c;
    c = a+b;
    return c;
}

  Using the MyInt class or typedeffing MyInt to int resulted in identical
assembler code (when using optimizations):

.LLFB3:
        !#PROLOGUE# 0
        !#PROLOGUE# 1
        retl
        mov     3, %o0

  This is sparc asm, and if we "translate" it back to C++ it means
the same thing as:

int foo()
{
    return 3;
}

  So using a class with operator overloading did not ask any overhead
*at all* to the code.

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: Tek
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 06:51:35
Message: <403897c7$1@news.povray.org>
>   This may have been true 10 years ago.

But I wasn't programming games 10 years ago.

>   Current compilers can usually optimize the overhead (eg. the function
> call) away completely (supposing the operator function is inline).

Couldn't compilers inline functions 10 years ago?

Anyway, my point isn't just the function call overhead, it's the fact that it's
not an operator internally supported by the compiler with a bunch of rules, it's
a series of instructions of unspecified length elsewhere.

> If you make a class which uses operator overloading for simple tasks
> (such as adding two internal values together) you should definitely
> make them inline, after which the compiler will be able to optimize
> all the overhead away.

Well, it can lose the function call overhead, but not the overhead of it being a
function (i.e. several instructions) rather than a simple instruction (which is
really my point).

What I'm saying is I want "+" to produce the same amount of assembler code
whenever I use it.

>   For example, suppose you have this (in C++):

Aha! but you'd never define an object for a type inherently supported by the
compiler, only for types which require something more complex. So you end up
with "+" becoming different amounts of compiled code depending on the context in
which it's used. This makes it harder to optimise code, since it is harder to
keep track of where the more complex + functions are being invoked.

Plus when someone is writing the code if they have to call
PerformReallySlowAndComplicatedAddition( a, b ) rather than a+b it tends to make
people more aware of what they're doing. It doesn't completely solve the problem
of writing optimised code, I'm just saying it makes it easier to keep track of
what's actually going on at the lowest level.

>   So using a class with operator overloading did not ask any overhead
> *at all* to the code.

I think you've missed my point, I'm not saying operator overloading does
anything different to function calls, I'm saying addition functions for two
matrices are different to addition functions for the processor's inbuilt types,
and it is useful when optimising to keep track of this difference.

Operator overloading is great if you want to code at a higher level without
being bogged down by thinking about what's happening at the lowest level, but
when optimising code you want to do the opposite! Heck, if were even remotely
feasible we'd write everything in assembler...

-- 
Tek
www.evilsuperbrain.com


Post a reply to this message

From: Andrew C on Mozilla
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 07:13:48
Message: <40389cfc@news.povray.org>
>>I wouldn't care for this. Think of vector member access...vec.x, vec.y, 
>>etc...vec.x() just adds more visual noise.
> 
>   If you read my article completely I suggested adding support for calling
> member functions without parentheses (supposing they don't take parameters).
> There's nothing problematic with that.

Eiffel does this...

(Can be slightly confusing at times... but then, so can most things!)

Not sure what you do about vec.x := 7... (But then, for certain objects 
it might be that you can't change one attribute without changing another 
as well... can't think of a good example right now...)


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 07:15:07
Message: <40389d4b@news.povray.org>
Tek <tek### [at] evilsuperbraincom> wrote:
> Well, it can lose the function call overhead, but not the overhead of it being a
> function (i.e. several instructions) rather than a simple instruction (which is
> really my point).

  The only alternative to operator overloading is to use a member function.
So how is that any different?

> >   For example, suppose you have this (in C++):

> Aha! but you'd never define an object for a type inherently supported by the
> compiler, only for types which require something more complex. So you end up
> with "+" becoming different amounts of compiled code depending on the context in
> which it's used. This makes it harder to optimise code, since it is harder to
> keep track of where the more complex + functions are being invoked.

  You missed my point completely.

  I just gave a simple example and wanted to point out that using operator
overloading does not add any overhead whatsoever to regular function calls.
  If you want to make, for example, a rational number type (which contains
two integers), then it doesn't matter if you use it with operators or with
regular member function calls: Using operators is not any slower.

> Plus when someone is writing the code if they have to call
> PerformReallySlowAndComplicatedAddition( a, b ) rather than a+b it tends to make
> people more aware of what they're doing.

  So you are saying that even if the addition would be extremely fast you
still should not use operator overloading? Why?

  Using operators makes the code cleaner and easier to read with complex
expressions.
  (This is IMHO a true problem in Java. You can't make in Java things like
"a = b + c*(d*c-e);" with your own defined type.)

> Operator overloading is great if you want to code at a higher level without
> being bogged down by thinking about what's happening at the lowest level, but
> when optimising code you want to do the opposite! Heck, if were even remotely
> feasible we'd write everything in assembler...

  If you don't know what operator+() does with the type you are using,
then you should seek another job, IMHO.
  If you are making speed-critical code then you should know your tools.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Andrew C on Mozilla
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 07:15:26
Message: <40389d5e$1@news.povray.org>
> IMHO this comes down to 'pov ain't oo' - I don't think anyone denies 
> that oo capabilities in pov wouldn't be at the very least interesting, 
> but that's not the issue....

POV sure ain't OO. No doubt about it ;-)

(...unless you start getting into an argument about what OO "is"... *sigh*)

Question: what IS the issue? (Maybe I'm just slow...)

Andrew @ home on Mozilla.


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 07:21:57
Message: <40389ee5$1@news.povray.org>
In article <403897c7$1@news.povray.org> , "Tek" <tek### [at] evilsuperbraincom> 
wrote:

> Couldn't compilers inline functions 10 years ago?

Not as well, no.

> Anyway, my point isn't just the function call overhead, it's the fact that
> it's not an operator internally supported by the compiler with a bunch of
> rules, it's a series of instructions of unspecified length elsewhere.

There is no such difference.

> Well, it can lose the function call overhead, but not the overhead of it being
> a function (i.e. several instructions) rather than a simple instruction (which
> is really my point).

No, there won't be additional instructions if a function is inlined.  For
any (not ten year old) compiler the overhead of inlining a function will be
exactly zero compared to direct insertion of the code.

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 07:27:27
Message: <4038a02f@news.povray.org>
Christopher James Huff <cja### [at] earthlinknet> wrote:
> Pass everything by reference

  That can be problematic.

  Suppose you have something like this:

class ItemContainer
{
 private:
    Int numberOfItems;

 public:
    ...
    Int size() { return numberOfItems; } // <- returns a reference
    ...
};
...


ItemContainer container;
// add things to 'container'

Int foo = container.size(); // <- gets a *reference*
foo -= 100; // Ooops! The container breaks badly!

  The thing is that in principle the code is not doing anything malign
on purpose. It's only natural that you take eg. the size of the container
to a variable and then use this variable for example as a loop counter
(eg. to go through all the items in the container).
  The big problem is that since your variable is actually a reference
to the original 'numberOfItems' variable, you'll end up breaking the
container.

  I don't know enough about Java to know how this problem is avoided
there.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 07:28:45
Message: <4038a07d@news.povray.org>
Andrew C on Mozilla <voi### [at] devnull> wrote:
> Question: what IS the issue? (Maybe I'm just slow...)

  If I'm not completely mistaken, I think that the basic issue here
is which OO properties POV-Ray's scripting language would benefit from
and which would be unnecessary.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Tek
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 08:13:42
Message: <4038ab06$1@news.povray.org>
>   I just gave a simple example and wanted to point out that using operator
> overloading does not add any overhead whatsoever to regular function calls.

I never said it did.

Oh dear, oh dear, I seem to have confused you. I'll try to explain:

What I said is that if you have a + between two ints it compiles to less code
than if you have a + you've defined as an overload operator *for a more complex
type*.

i.e. the code looks the same, but it does more stuff (because the data it's
operating on is more complex). This is *good* from an OO point of view, because
you don't need to know about the implementation of the object in order to use
it, but bad from an optimisation point of view, because you do need to know
about the implementation in order to be able to use it *efficiently*.

>   Using operators makes the code cleaner and easier to read with complex
> expressions.

So what if it's easier to read? A good programmer can deal with code that's hard
to read, it's good if it's readable but not if you've lost some information you
might want.

>   If you don't know what operator+() does with the type you are using,
> then you should seek another job, IMHO.
>   If you are making speed-critical code then you should know your tools.

Right, lets say your product ships in two weeks time, and you've discovered that
the physics guy who got sacked last week was a moron. Hey, it happens. You need
to go through his code and find everywhere that he's performing a matrix*vector
multiply, in order to replace it with a more efficient piece of code.

How do you do that?

-- 
Tek
www.evilsuperbrain.com


Post a reply to this message

From: Tek
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 08:29:10
Message: <4038aea6$1@news.povray.org>
> > Anyway, my point isn't just the function call overhead, it's the fact that
> > it's not an operator internally supported by the compiler with a bunch of
> > rules, it's a series of instructions of unspecified length elsewhere.
>
> There is no such difference.

Okay, remove the word "elsewhere" and you might see what I mean.

> > Well, it can lose the function call overhead, but not the overhead of it
being
> > a function (i.e. several instructions) rather than a simple instruction
(which
> > is really my point).
>
> No, there won't be additional instructions if a function is inlined.  For
> any (not ten year old) compiler the overhead of inlining a function will be
> exactly zero compared to direct insertion of the code.

ffs, I know that! I know what inline does! I'm talking with the premise that you
won't write a function to do something you can already do in one line of code.

i.e. if anyone, anywhere, ever writes a function:
add(a,b)
{
    return a+b;
}

that person should be dragged out into the street and shot*. So, ON THAT
PREMISE, if you have decided to write an inline function there will be an
"overhead of it being a function (i.e. several instructions) rather than a
simple instruction", by which I mean you have decided to write a function that
is more than one instruction.

I just explained that *really* badly yet again...

What I'm saying is, quite simply, we like to make a distinction between "+" and
any more elaborate function. Because doing so prevents people writing lines like
a = b + 3*(c-d), which looks perfectly innocent, but could be a major
bottleneck.


I'm not saying overload operators are a bad thing, I'm just presenting the
reasons why we don't generally use them in game coding. I think for simple types
which are well suited to the compiler you could define some more (like vectors),
but I'd still make a distinction between that and a significantly greater amount
of processing.

We like the clunkier syntax *because* it is harder to use and requires more
thought from the programmer. In our situation this is a good thing.

-- 
Tek
www.evilsuperbrain.com

*I bet someone's now going to come up with a perfectly good reason why they
might do this, but it's 5:20am and I can't think of one!


Post a reply to this message

From: Tek
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 08:34:10
Message: <4038afd2$1@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message news:4038a07d@news.povray.org...
> Andrew C on Mozilla <voi### [at] devnull> wrote:
> > Question: what IS the issue? (Maybe I'm just slow...)
>
>   If I'm not completely mistaken, I think that the basic issue here
> is which OO properties POV-Ray's scripting language would benefit from
> and which would be unnecessary.

Well the original issue was me saying "I want to do some OO-style pov code. Has
anyone done this before?". Although the thread seems to have drifted away from
that... :)

-- 
Tek
www.evilsuperbrain.com


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 09:20:17
Message: <4038baa0@news.povray.org>
Tek <tek### [at] evilsuperbraincom> wrote:
> What I said is that if you have a + between two ints it compiles to less code
> than if you have a + you've defined as an overload operator *for a more complex
> type*.

  Actually, that's not always so.

  In my example the + between the two class instances generated no code
at all, while a + between two ints may generate an addition asm code
(when the compiler can't do it at compile time)... :)

> i.e. the code looks the same, but it does more stuff (because the data it's
> operating on is more complex). This is *good* from an OO point of view, because
> you don't need to know about the implementation of the object in order to use
> it, but bad from an optimisation point of view, because you do need to know
> about the implementation in order to be able to use it *efficiently*.

  You need to know about how a library function is implemented anyways,
regardless of how it is called, if you want to make as optimal code as
possible.

  If you are using class instances you know that calling the operator+
for them will (potentially) generate a function call. If you don't know
that, you don't have business making highly-optimized hacker code.

  Besides, it's true what they say that optimization should firstly be
made at algorithmical level. Only when the algorithms and data containers
are as efficient as possible and the code still is too slow, then one should
try to look what is taking so long.
  Optimizing a function call away won't help you if your algorithm is
a thousand times slower than a completely different algorithm which makes
the same thing. :)

> >   Using operators makes the code cleaner and easier to read with complex
> > expressions.

> So what if it's easier to read?

  If you make write-and-forget code then it doesn't matter. However, if
you make code which potentially needs to be enhanced/fixed in the future
(and specially by someone else than you), then clarity is a big plus.

> A good programmer can deal with code that's hard
> to read

  Yes, after cursing you and your family for making it so hard to read.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

From: Warp
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 09:21:56
Message: <4038bb04@news.povray.org>
Tek <tek### [at] evilsuperbraincom> wrote:
> We like the clunkier syntax *because* it is harder to use and requires more
> thought from the programmer. In our situation this is a good thing.

  Good luck trying to maintain and enhance such code in the future then.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 09:36:30
Message: <4038be6e$1@news.povray.org>
In article <4038bb04@news.povray.org> , Warp <war### [at] tagpovrayorg>  wrote:

>   Good luck trying to maintain and enhance such code in the future then.

If you write games, you don't have to, I suppose.  All you need is a few
patches later on when bad coding style produced plenty of bugs in the
initial release version ;-)

    Thorsten

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

From: Dan P
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 09:52:22
Message: <4038c226@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message
news:4037f302@news.povray.org...
> Patrick Elliott <sha### [at] hotmailcom> wrote:
> > But it can happen.
>
>   Of course it can happen. And it can also happen that a function
> named "multiply" calculates the square root. But that doesn't mean
> it's not avoidable. It just means the design of the program/library
> has a flaw.

Holy cow, this thread grew a lot. I was in bed all Saturday (not sick, just
very, very tired) and missed out on the fun. I have too much to do to catch
up.


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 11:29:18
Message: <cjameshuff-5800AC.11300022022004@news.povray.org>
In article <4038a02f@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

> Christopher James Huff <cja### [at] earthlinknet> wrote:
> > Pass everything by reference
> 
>   That can be problematic.
...snip...
> Int foo = container.size(); // <- gets a *reference*

No, that initializes an Int named foo to the object returned by 
container.size. Not a problem.
This was a problem in Sapphire...not a major one, but it required 
annoying additional code to create a copy. Now I have an additional 
syntax for creating variables:

def foo: val; //defines a variable foo attached to the value val
def foo = val; //defines a variable foo attached to a copy of val


>   The big problem is that since your variable is actually a reference
> to the original 'numberOfItems' variable, you'll end up breaking the
> container.

You could also introduce const references...not sure if its worth the 
trouble.

>   I don't know enough about Java to know how this problem is avoided
> there.

Java passes everything by value. Objects are only handled through 
references, those references are passed by value. And it will break in 
the way you describe above, but it isn't very common...in this case, you 
would use the primitive int type instead of an integer object.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 11:45:27
Message: <cjameshuff-1CDA31.11460922022004@news.povray.org>
In article <403897c7$1@news.povray.org>, "Tek" <tek### [at] evilsuperbraincom> 
wrote:

> Couldn't compilers inline functions 10 years ago?

Not as intelligently.


> Anyway, my point isn't just the function call overhead, it's the fact 
> that it's not an operator internally supported by the compiler with a 
> bunch of rules, it's a series of instructions of unspecified length 
> elsewhere.

Which you have to call no matter what. It being done through an operator 
function rather than through an explicit member function call makes 
exactly zero difference.


> Well, it can lose the function call overhead, but not the overhead of 
> it being a function (i.e. several instructions) rather than a simple 
> instruction (which is really my point).

Zero overhead. None. Nada. Not one extra instruction.


> What I'm saying is I want "+" to produce the same amount of assembler code
> whenever I use it.

Well, you can't. Adding some things takes more work. Using member 
functions doesn't help this at all.


> >   For example, suppose you have this (in C++):
> 
> Aha! but you'd never define an object for a type inherently supported by the
> compiler, only for types which require something more complex.

Actually, iterators often do exactly this, being a thin wrapper over a 
pointer.


> So you end up with "+" becoming different amounts of compiled code 
> depending on the context in which it's used. This makes it harder to 
> optimise code, since it is harder to keep track of where the more 
> complex + functions are being invoked.

Just be aware of what you're adding. It's no harder than keeping track 
of a bunch of methods named add(), mult(), etc, and the code is much 
easier to read.


> I think you've missed my point, I'm not saying operator overloading does
> anything different to function calls, I'm saying addition functions for two
> matrices are different to addition functions for the processor's inbuilt 
> types, and it is useful when optimising to keep track of this difference.

How is this so? If you need to add two matrices, you need to add two 
matrices. You can't do this with the same code for adding two integers.


> Operator overloading is great if you want to code at a higher level without
> being bogged down by thinking about what's happening at the lowest level, but
> when optimising code you want to do the opposite! Heck, if were even remotely
> feasible we'd write everything in assembler...

No...then you run into the "can't see the forest for the trees" problem. 
You'll spend too much time optimizing tiny little things, and completely 
miss larger optimizations that can have a huge impact. And I still 
haven't seen an argument against including operator overloading in a 
language...even if this were true, it would apply only to specific 
projects.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Object Oriented POV code
Date: 22 Feb 2004 11:59:06
Message: <cjameshuff-EB5744.11594822022004@news.povray.org>
In article <4038aea6$1@news.povray.org>, "Tek" <tek### [at] evilsuperbraincom> 
wrote:

> that person should be dragged out into the street and shot*. So, ON THAT
> PREMISE, if you have decided to write an inline function there will be an
> "overhead of it being a function (i.e. several instructions) rather than a
> simple instruction", by which I mean you have decided to write a function 
> that is more than one instruction.

__normal_iterator& operator++() { ++_M_current; return *this; }

That's the ++ operator for one of the STL iterators. And it does make 
sense to do it this way...other operators have to do more complex 
things, but it still makes sense to have a ++ operator.


> What I'm saying is, quite simply, we like to make a distinction 
> between "+" and any more elaborate function. Because doing so 
> prevents people writing lines like a = b + 3*(c-d), which looks 
> perfectly innocent, but could be a major bottleneck.

All the coder has to do is look at the types being worked on. And this 
still isn't an argument against the existance of operator overoading.


> We like the clunkier syntax *because* it is harder to use and requires more
> thought from the programmer. In our situation this is a good thing.

But it requires more thought about the wrong things...I don't see how it 
can help.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

<<< Previous 50 Messages Goto Latest 50 Messages Next 50 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.