POV-Ray : Newsgroups : povray.off-topic : Standard libraries : Re: Standard libraries Server Time
6 Sep 2024 09:18:22 EDT (-0400)
  Re: Standard libraries  
From: Darren New
Date: 9 Mar 2009 16:47:56
Message: <49b5807c$1@news.povray.org>
Warp wrote:
>   I surely can understand why such information could sometimes be useful,
> but it still sounds to me like you are accessing the internals of an object,
> bypassing its public interface, which is something that breaks the basic
> idea of modularity.

Here's an excellent example from Python:

http://qinsb.blogspot.com/2009/03/automatic-repr-and-eq-for-data.html

Translated for those who don't speak Python, this says "here's a mix-in 
multi-inheritance class that provides a 'show as a string' function. It 
examines the class and constructor arguments, so you can do something 
like[1] this (using C++-ish syntax):

class Alpha : Beta, ThisMixinClass {
   Alpha(int One, float Two) { ... }
}

And then call
   Alpha alpha(23, 75.2);
and then you can say
   string x = alpha.repr();
and have x get the value
   "<class Alpha One=23 Two=75.2>"


Not really breaking encapsulation at all. Just adding as a method 
functionality that you'd have to implement manually by hand in each class. 
Not really breaking modularity any more than a template that relies on a 
class having particular set of internal functions.

[1] The function __repr__() is what gets called on an instance to turn it 
into a string that when you evaluate it in Python you get back the value. In 
C++ terms, it would be like printing
    std::string("Hello")
for a std::string whose value is "Hello", rather than just Hello.
__init__() is the constructor, and there's only one and you can't overload it.


-- 
   Darren New, San Diego CA, USA (PST)
   My fortune cookie said, "You will soon be
   unable to read this, even at arm's length."


Post a reply to this message

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