Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

matters of faith, python and perl

infidelinfidel Posts: 2,900Member
: Bah...we've hit the 10 reply deep limit again...

If replies = 10 Then GoTo Top

: Hmmm...I see. Sounds a bit "New Age"ish to me - god is in everything kinda thing...

Egads no. "New Age" ish stuff makes me puke. Neopagan nonsense. This is simply stating that "God" is not a separate thing from the Universe.

: Or maybe it's more like the "we collectively are god" thing.

Sort of. More than just "we", though. Everything.

: The scientific version is, as you say, more interesting though. Not sure the only way we can get to know it is science though, unless you broaden your definition of science...

Science seeks to understand what is. If all that is is God, then science is the way to understand God.

: : : OK. I believe THAT God exists and that he had a son called Jesus
: : : who was crucified, rose again in three days and saved my butt in
: : : doing so. Happy?
: :
: : Sorry, doesn't work that way :-P
: And...uh...why? I believe in big bang theory. I belive that there is
: a God. I believe that the big bang happened. I belive in God. Notice
: we can convert from in to that by changing "in" to "that" and adding
: a...verb? Plus a few padding words to make the English read a bit
: better.

Ok, bad example then. You can change the words all you like, but the point is that there are two wholly different categories of "belief". The "that" vs. "in" is just an illustration. One kind is testable, falsifiable, repeatable... the other is none of those.

: : : Ok, on "revelation" too.
: : Now you're talking...
: Which is a wholly unreliable method for obtaining truth.
It could be true though!

Or sleep deprivation or d r u g-induced hallucination or schizophrenia or...

: : Naw, in Python you can add new methods and members to objects at
: : runtime and you need not be cunning at all, nor use metaclasses.
: You can also compile the code for a method on-the-fly if need be, and
: generate property accessors on the fly.

Yep and yep.

: : Yeah, Python is all references and namespaces.
: Can you have more than one class per namespace? Unless there's
: something I don't know, you can't in Perl...

Absolutely. A module can have as many classes, functions, or variables as you like. You just can't have the same name for two objects in the same namespace.

: Newer versions of Python allow you to subclass built-in types like
: dictionaries (hashes) and lists, etc.
Sounds interesting... Does Python have value types as well as variable types? E.G. int, str, etc... Perl 6 is getting them, optionally of course. Chances are I'll use them.

Not sure what distinction there is between value types and variable types. In Python, the type of a variable isn't determined until it's set to something. Once it's set, however, the type is important. You can't, for instance, add an integer and a string with the + operator (type mismatch). You can, though, add (concatenate) two strings or even multiply a string by an integer (repeats the string N times).

: : Nice who Perl uses three existing concepts to implement it's OOP.
: : If that ain't a good example of code re-use, I don't know what is!
: Or a way to confuse people. :-P
Only if they're stuck in the idea that OOP is done in the VB/C# etc. style, where you create a variable of type "classname".

If I had a class named Foo, to create an object of type Foo I would do:

f = Foo()

Now I have an object named "f" in the current namespace that references a Foo object. Never had to declare f, though. I could immediately set f = 3 and have an integer variable.


[size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Comments

  • JonathanJonathan Posts: 2,914Member
    : : Bah...we've hit the 10 reply deep limit again...
    : If replies = 10 Then GoTo Top
    You do know that using BASIC syntax and the goto keyword is going to give me nightmares? :-P

    : : Hmmm...I see. Sounds a bit "New Age"ish to me - god is in
    : : everything kinda thing...
    :
    : Egads no. "New Age" ish stuff makes me puke. Neopagan nonsense.
    : This is simply stating that "God" is not a separate thing from the
    : Universe.
    Nah, I'm not a fan of "New Age" ish stuff either. :-) Whether God is a seperate thing from the universe isn't a question I'd really thought about before though.

    : : Or maybe it's more like the "we collectively are god" thing.
    : Sort of. More than just "we", though. Everything.
    OK, I see what you're getting at. Different from new age thing that says that god is *in* everything, that's where I got it wrong.

    : : The scientific version is, as you say, more interesting though.
    : : Not sure the only way we can get to know it is science though,
    : : unless you broaden your definition of science...
    : Science seeks to understand what is. If all that is is God, then
    : science is the way to understand God.
    Sounds to me like this is turning science into a religion...

    : : : : OK. I believe THAT God exists and that he had a son called Jesus
    : : : : who was crucified, rose again in three days and saved my butt in
    : : : : doing so. Happy?
    : : :
    : : : Sorry, doesn't work that way :-P
    : : And...uh...why? I believe in big bang theory. I belive that there is
    : : a God. I believe that the big bang happened. I belive in God. Notice
    : : we can convert from in to that by changing "in" to "that" and adding
    : : a...verb? Plus a few padding words to make the English read a bit
    : : better.
    :
    : Ok, bad example then. You can change the words all you like, but
    : the point is that there are two wholly different categories
    : of "belief". The "that" vs. "in" is just an illustration. One kind
    : is testable, falsifiable, repeatable... the other is none of those.
    The only reason we can't test whether there is a God or not is becasue we don't know how to. Just because we don't know HOW to do something doesn't mean it can't be done.

    : : : : Ok, on "revelation" too.
    : : : Now you're talking...
    : : Which is a wholly unreliable method for obtaining truth.
    : It could be true though!
    : Or sleep deprivation or d r u g-induced hallucination or
    : schizophrenia or...
    God.

    : : : Naw, in Python you can add new methods and members to objects at
    : : : runtime and you need not be cunning at all, nor use metaclasses.
    : : You can also compile the code for a method on-the-fly if need be, and
    : : generate property accessors on the fly.
    :
    : Yep and yep.
    Through eval style constructs?

    : : : Yeah, Python is all references and namespaces.
    : : Can you have more than one class per namespace? Unless there's
    : : something I don't know, you can't in Perl...
    : Absolutely. A module can have as many classes, functions, or
    : variables as you like. You just can't have the same name for two
    : objects in the same namespace.
    That's possibly something over Perl there; I don't know that you can have more than one class per namespace (called a package in Perl), as the object is created by taking a reference to a data structure and associating it with a given package (e.g. all the subs in that package).

    : Not sure what distinction there is between value types and variable
    : types.
    I think of it as variable type is the type of the container, and value type is the type of the value inside the container. I think maybe using variable type to describe hashes, arrays and scalars might well be an abuse of the term variable type, though. :-)

    : In Python, the type of a variable isn't determined until
    : it's set to something. Once it's set, however, the type is
    : important. You can't, for instance, add an integer and a string
    : with the + operator (type mismatch). You can, though, add
    : (concatenate) two strings or even multiply a string by an integer
    : (repeats the string N times).
    Seems like a curious half way house to me. A variable's type isn't important till it's set to something, which may often happen at runtime. Thus, you end up with a kind of strictish typing in some places, but don't gain the benefits of compile time type optimisation in (most,any) cases? Taking the integer and string example, what if the function that read data in gave you a string and you wanted to add it to another number? Is there a numification operator or do you have to cast it or what? (This is another good reason for having different operators for concatenation and addition).

    : : : Nice who Perl uses three existing concepts to implement it's OOP.
    : : : If that ain't a good example of code re-use, I don't know what is!
    : : Or a way to confuse people. :-P
    : Only if they're stuck in the idea that OOP is done in the VB/C# etc.
    : style, where you create a variable of type "classname".
    :
    : If I had a class named Foo, to create an object of type Foo I would
    : do:
    :
    : f = Foo()
    Is it me, or does that look an awful lot like a function call, collecting the return value in f? Or does it work on the basis that a class has a constructor that is the same name as the class and the constructor actually returns the object?

    : Now I have an object named "f" in the current namespace that
    : references a Foo object. Never had to declare f, though. I could
    : immediately set f = 3 and have an integer variable.
    Yeah, you can do that kinda thing in Perl. In Perl6 though you will be able to forbid stuff like that, and have proper typing. Which is a Good Thing for helping prevent stupid bugs and stuff, though I'm pleased it's an option, and not enforced! :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • infidelinfidel Posts: 2,900Member
    : : : Bah...we've hit the 10 reply deep limit again...
    : : If replies = 10 Then GoTo Top
    : You do know that using BASIC syntax and the goto keyword is going to give me nightmares? :-P

    HA!

    : Nah, I'm not a fan of "New Age" ish stuff either. :-) Whether God is a seperate thing from the universe isn't a question I'd really thought about before though.

    Glad I could expand your horizons :-)

    : : : The scientific version is, as you say, more interesting though.
    : : : Not sure the only way we can get to know it is science though,
    : : : unless you broaden your definition of science...
    : : Science seeks to understand what is. If all that is is God, then
    : : science is the way to understand God.
    : Sounds to me like this is turning science into a religion...

    That's certainly an inherent risk in this type of thinking.

    : The only reason we can't test whether there is a God or not is becasue we don't know how to.

    And because it wouldn't matter if we did. Have I ever told you that I have a dragon living in my garage? Would you like to see it? Sorry, he's invisible. Would you like to see his footprints? Sorry, he floats. Would you like to touch him? Sorry, he's incorporeal. Would you like to see food disappear that he's eating? Sorry, he gets his energy trhrough non-physical means. See? For every possible test, there's an excuse.

    : Just because we don't know HOW to do something doesn't mean it can't be done.

    True, but not the point.

    : : : : : Ok, on "revelation" too.
    : : : : Now you're talking...
    : : : Which is a wholly unreliable method for obtaining truth.
    : : It could be true though!
    : : Or sleep deprivation or d r u g-induced hallucination or
    : : schizophrenia or...
    : God.

    Occam's Razor is not on your side here.

    : : : You can also compile the code for a method on-the-fly if need be, and
    : : : generate property accessors on the fly.
    : :
    : : Yep and yep.
    : Through eval style constructs?

    I think so. This isn't something I've ever done before. I may be overstating Python's capabilities here without having a good idea what we're talking about. I can research if you like.

    : That's possibly something over Perl there; I don't know that you can have more than one class per namespace (called a package in Perl), as the object is created by taking a reference to a data structure and associating it with a given package (e.g. all the subs in that package).

    Python has modules (files) that can be imported and treated sort of like global objects. A module, though, can contain as many classes as you like.

    : : Not sure what distinction there is between value types and variable
    : : types.
    : I think of it as variable type is the type of the container, and value type is the type of the value inside the container. I think maybe using variable type to describe hashes, arrays and scalars might well be an abuse of the term variable type, though. :-)

    In that case I would say that Python has no variable types, but has strict value typing. Variables are just names which point to values. Python has lists and dictionaries and scalar types, but any name can reference any of them.

    : : In Python, the type of a variable isn't determined until
    : : it's set to something. Once it's set, however, the type is
    : : important. You can't, for instance, add an integer and a string
    : : with the + operator (type mismatch). You can, though, add
    : : (concatenate) two strings or even multiply a string by an integer
    : : (repeats the string N times).
    : Seems like a curious half way house to me. A variable's type isn't important till it's set to something, which may often happen at runtime. Thus, you end up with a kind of strictish typing in some places, but don't gain the benefits of compile time type optimisation in (most,any) cases? Taking the integer and string example, what if the function that read data in gave you a string and you wanted to add it to another number? Is there a numification operator or do you have to cast it or what? (This is another good reason for having different operators for concatenation and addition).

    I agree that usually different operators for concatenation and addition is a good thing, but in Python's case I would disagree. Especially since you can multiply strings to repeat them. You can cast a string to a number using the int() function. Numbers can be cast to strings using either str() or back-ticks `100`. I've heard rumors that future versions of python may include compile-time typing, but I think I remember reading that Guido was against that. I'm not sure.

    : : If I had a class named Foo, to create an object of type Foo I would
    : : do:
    : :
    : : f = Foo()
    : Is it me, or does that look an awful lot like a function call, collecting the return value in f?

    That's exactly what it is. The () are bascially the "call" operator. Classes automatically have the call operator mapped to their constructor.

    : Or does it work on the basis that a class has a constructor that is the same name as the class and the constructor actually returns the object?

    Actually, constructors are always named __init__(). Maybe this will help the metaclasses thing become clearer. In Python, when you issue a "class" statement like this:

    [code]
    class Foo(object):
    a = 100
    b = 'cat'
    def __init__(self, foobar='foobar'):
    self.foobar = foobar
    def __repr__(self):
    return `self.foobar`
    def printme(self):
    print self.foobar
    [/code]

    ... the interpreter gathers the methods (def statements) and members (a, b) into a dictionary, makes a list of superclasses (object) and passes these two items plus the name ('Foo') to the metaclass constructor which creates an object named Foo that returns new instances of itself when it is called.

    Maybe that just confused things.

    Maybe it would help if you think of class statements as creating object factories? Objects that return new objects. Really, though, you don't have to think about all this stuff if you don't want to.

    : : Now I have an object named "f" in the current namespace that
    : : references a Foo object. Never had to declare f, though. I could
    : : immediately set f = 3 and have an integer variable.
    : Yeah, you can do that kinda thing in Perl. In Perl6 though you will be able to forbid stuff like that, and have proper typing. Which is a Good Thing for helping prevent stupid bugs and stuff, though I'm pleased it's an option, and not enforced! :-)

    I find Python to be very "zen". For all my career I've had languages enforce typing, and now Python has stripped away so much of that (artificial) structure. I love it.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

  • JonathanJonathan Posts: 2,914Member
    : : Nah, I'm not a fan of "New Age" ish stuff either. :-) Whether
    : : God is a seperate thing from the universe isn't a question I'd
    : : really thought about before though.
    :
    : Glad I could expand your horizons :-)
    Of course, if God is everywhere at once, then that means that (s)he must be in the universe... Or maybe it doens't work like that. :-)

    : : : : The scientific version is, as you say, more interesting though.
    : : : : Not sure the only way we can get to know it is science though,
    : : : : unless you broaden your definition of science...
    : : : Science seeks to understand what is. If all that is is God, then
    : : : science is the way to understand God.
    : : Sounds to me like this is turning science into a religion...
    :
    : That's certainly an inherent risk in this type of thinking.
    :
    Indeed. It's amazing how many people have blind faith in science too, which I'd say comes down to the same thing. I guess it's the way it's taught at school in part - as the truth. "Evolution theory is correct" vs "Evolution is the best theory we have at the moment".

    : : The only reason we can't test whether there is a God or not is
    : : becasue we don't know how to.
    :
    : And because it wouldn't matter if we did.
    Wouldn't it? What if we (somehow) found proof that there WAS a God? Don't you think a lot of people would all of a sudden take up some religion or other?

    : Have I ever told you that I have a dragon living in my garage?
    : Would you like to see it? Sorry, he's invisible. Would you like to
    : see his footprints? Sorry, he floats. Would you like to touch him?
    : Sorry, he's incorporeal. Would you like to see food disappear that
    : he's eating? Sorry, he gets his energy through non-physical means.
    : See? For every possible test, there's an excuse.
    And...uh...how do you propose to test whether God is there? If you come up with one, I'll try and come up with an excuse... ;-)

    : : Just because we don't know HOW to do something doesn't mean it
    : : can't be done.
    :
    : True, but not the point.
    :
    Why isn't it the point? If we could do a test to see whether there was a God, we probably wouldn't be having this discussion because the test would have given the answer. We don't currently know of a test we can carry out to answer that question.

    : : : : : : Ok, on "revelation" too.
    : : : : : Now you're talking...
    : : : : Which is a wholly unreliable method for obtaining truth.
    : : : It could be true though!
    : : : Or sleep deprivation or d r u g-induced hallucination or
    : : : schizophrenia or...
    : : God.
    : Occam's Razor is not on your side here.
    Nah, I felt God was necessary. :-P

    : : : : You can also compile the code for a method on-the-fly if need be, and
    : : : : generate property accessors on the fly.
    : : :
    : : : Yep and yep.
    : : Through eval style constructs?
    :
    : I think so. This isn't something I've ever done before. I may be
    : overstating Python's capabilities here without having a good idea
    : what we're talking about. I can research if you like.
    Only if you'd like to. :-) In Perl a "class" can have an AUTOLOAD method that is called if a method that is called cannot be found. Therefore you can compile that method "on the fly" and insert it into the namespace's symbol table. Good thing is that, AFAIK, once you've compiled it, future calls to it have no extra overhead that you would not get on a method compiled in the beginning. You can use these to save you writing a lot of property get/set style methods too! (Or you can read the instance data directly like I do, because method calls can't be interpolated in Perl5...nope, I wouldn't make an OO purist).

    : : That's possibly something over Perl there; I don't know that you
    : : can have more than one class per namespace (called a package in
    : : Perl), as the object is created by taking a reference to a data
    : : structure and associating it with a given package (e.g. all the
    : : subs in that package).
    :
    : Python has modules (files) that can be imported and treated sort of
    : like global objects. A module, though, can contain as many classes
    : as you like.
    So you must be able to declare a set of subs (methods) as belonging to a particular class. In Perl, you can only declare them as belonging to a particular namespace. You can however have more than one namespace defined in a single file. Convention is that you have a file for each though, and a matching directory structure.


    : : I think of it as variable type is the type of the container, and
    : : value type is the type of the value inside the container. I think
    : : maybe using variable type to describe hashes, arrays and scalars
    : : might well be an abuse of the term variable type, though. :-)
    :
    : In that case I would say that Python has no variable types, but has
    : strict value typing. Variables are just names which point to
    : values. Python has lists and dictionaries and scalar types, but any
    : name can reference any of them.
    Hmmm...in Perl an array is just a collection of scalars indexed by number and a hash is a collection of scalars indexed on a certain key. A scalar can hold a reference to another scalar, array, hashref, sub (named or anonymous) or typeglob. In Perl we have sigils though, e.g. $scalar, @array, %hash. I think Python doesn't have these?

    : : : In Python, the type of a variable isn't determined until
    : : : it's set to something. Once it's set, however, the type is
    : : : important. You can't, for instance, add an integer and a string
    : : : with the + operator (type mismatch). You can, though, add
    : : : (concatenate) two strings or even multiply a string by an integer
    : : : (repeats the string N times).
    : : Seems like a curious half way house to me. A variable's type
    : : isn't important till it's set to something, which may often happen
    : : at runtime. Thus, you end up with a kind of strictish typing in
    : : some places, but don't gain the benefits of compile time type
    : : optimisation in (most,any) cases? Taking the integer and string
    : : example, what if the function that read data in gave you a string
    : : and you wanted to add it to another number? Is there a
    : : numification operator or do you have to cast it or what? (This is
    : : another good reason for having different operators for
    : : concatenation and addition).
    :
    : I agree that usually different operators for concatenation and
    : addition is a good thing, but in Python's case I would disagree.
    : Especially since you can multiply strings to repeat them.
    You can do that with the x operator in Perl.
    print 'a' x 5; #print aaaaa
    I ain't used it all that much, though it's useful to have it there.

    : You can cast a string to a number using the int() function. Numbers
    : can be cast to strings using either str() or back-ticks `100`.
    Hehe...don't try that in Perl. Anything between back-ticks gets executed! Sounds a bit like VBs approach in a way. I still ain't decided how much I like the C# appraoch to casting...

    float a = 2;
    int b = (int) a;

    : I've heard rumors that future versions of python may include compile-
    : time typing, but I think I remember reading that Guido was against
    : that. I'm not sure.
    It's only going to be optional in Perl6. I'd be pretty upset if it was compulsary to use strict typing all the time!

    : : : If I had a class named Foo, to create an object of type Foo I would
    : : : do:
    : : :
    : : : f = Foo()
    : : Is it me, or does that look an awful lot like a function call,
    : : collecting the return value in f?
    :
    : That's exactly what it is. The () are bascially the "call"
    : operator. Classes automatically have the call operator mapped to
    : their constructor.
    Interesting. I've never known the () being thought of as a call operator...I guess it means you can't call parameterless methods without a () though? Curious, but makes a lot of sense.

    : : Or does it work on the basis that a class has a constructor that
    : : is the same name as the class and the constructor actually returns
    : : the object?
    :
    : Actually, constructors are always named __init__(). Maybe this will
    : help the metaclasses thing become clearer. In Python, when you
    : issue a "class" statement like this:
    :
    : [code]
    : class Foo(object):
    : a = 100
    : b = 'cat'
    : def __init__(self, foobar='foobar'):
    : self.foobar = foobar
    : def __repr__(self):
    : return `self.foobar`
    : def printme(self):
    : print self.foobar
    : [/code]
    What's __repr__?

    :
    : ... the interpreter gathers the methods (def statements) and members
    : (a, b) into a dictionary, makes a list of superclasses (object) and
    : passes these two items plus the name ('Foo') to the metaclass
    : constructor which creates an object named Foo that returns new
    : instances of itself when it is called.
    :
    : Maybe that just confused things.
    Maybe it was competing for the world's longest sentence? I sort of get it... The list of superclasses is essentially a list of objects instantiated from that class, and the dictionary contains the blueprint for the new object. The metaclass takes these, creates the object, adds it to the list of superclasses, and returns the object it's created? So basically the metaclass controls object construction for many classes?

    : Maybe it would help if you think of class statements as creating
    : object factories? Objects that return new objects.
    That's an easy enough concept, because you essentially write the code that manufactures the object in Perl.

    [code]#I'll call the constructor new; call it anything suitable.
    sub new {
    #Get invocant.
    my $invocant = shift;

    #Create a data structure of some sort.
    my %hash = (
    somekey => 'somevalue'
    );

    #Create a reference to it.
    my $hashref = %hash;

    #Bless the reference - that creates the object.
    bless $hashref, $invocant;

    #Return the created object.
    return $hashref;
    }[/code]
    You can write it more compactly, of course. :-)

    : Really, though, you don't have to think about all this stuff if you
    : don't want to.
    That's my problem. I LIKE to think about all this stuff!

    : : : Now I have an object named "f" in the current namespace that
    : : : references a Foo object. Never had to declare f, though. I could
    : : : immediately set f = 3 and have an integer variable.
    : : Yeah, you can do that kinda thing in Perl. In Perl6 though you
    : : will be able to forbid stuff like that, and have proper typing.
    : : Which is a Good Thing for helping prevent stupid bugs and stuff,
    : : though I'm pleased it's an option, and not enforced! :-)
    :
    : I find Python to be very "zen". For all my career I've had
    : languages enforce typing, and now Python has stripped away so much
    : of that (artificial) structure. I love it.
    Yeah, that's why I love Perl too. Freedom. Perl6 will be even better, as it allows me to be harsher on myself when appropriate by using strict typing, but without sacrificing the freedom I have to not care about typing when it's not going to cause any problems not caring. Long live languages like this. :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • infidelinfidel Posts: 2,900Member
    : Of course, if God is everywhere at once, then that means that (s)he must be in the universe... Or maybe it doens't work like that. :-)

    Your still thinking of God as separate from the universe. It's not easy shifting a paradigm that's a few millennia old.

    : Indeed. It's amazing how many people have blind faith in science too, which I'd say comes down to the same thing.

    Not exactly the same thing but close enough for this discussion.

    : I guess it's the way it's taught at school in part - as the truth. "Evolution theory is correct" vs "Evolution is the best theory we have at the moment".

    Well, it is correct so far as we know. This is one of the fundamental points that many anti-evolutionists just don't get. The theory of evolution is very accurate about many things. Any theory which would replace it must account for all of the things which it already has right as well as for new things which the current theory has wrong. I use the term "theory" loosely since Evolution is really an overarching concept embodied by many theories across many disciplines.

    : Wouldn't it? What if we (somehow) found proof that there WAS a God? Don't you think a lot of people would all of a sudden take up some religion or other?

    Most certainly.

    : And...uh...how do you propose to test whether God is there? If you come up with one, I'll try and come up with an excuse... ;-)

    I'm not the one claiming God is there.

    : Why isn't it the point? If we could do a test to see whether there was a God, we probably wouldn't be having this discussion because the test would have given the answer. We don't currently know of a test we can carry out to answer that question.

    Because there's no way to test something that is unfalsifiable!

    : : Occam's Razor is not on your side here.
    : Nah, I felt God was necessary. :-P

    Many people feel God is necessary. As in they can't (or won't, for various reasons) even hypothetically accept the idea of no God. I'm always rather terrified of the believer who says something to the effect of "if there were no God then I could do X" where X is anything one might consider "evil". Murder, theft, I've heard many variations of this statement. Tell me who is more "moral"... he who acts civilized because it is a Good Thing, or he who does so because he's afraid of eternal damnation?

    : Only if you'd like to. :-) In Perl a "class" can have an AUTOLOAD method that is called if a method that is called cannot be found. Therefore you can compile that method "on the fly" and insert it into the namespace's symbol table. Good thing is that, AFAIK, once you've compiled it, future calls to it have no extra overhead that you would not get on a method compiled in the beginning. You can use these to save you writing a lot of property get/set style methods too! (Or you can read the instance data directly like I do, because method calls can't be interpolated in Perl5...nope, I wouldn't make an OO purist).

    Ok, that sounds like what Python does. Python objects have a built-in method, __getattr__ which is called when you reference a name that the object doesn't contain. You can also at runtime add new methods to objects (not sure about classes, but probably) by assigning references to them.

    : : Python has modules (files) that can be imported and treated sort of
    : : like global objects. A module, though, can contain as many classes
    : : as you like.
    : So you must be able to declare a set of subs (methods) as belonging to a particular class. In Perl, you can only declare them as belonging to a particular namespace. You can however have more than one namespace defined in a single file. Convention is that you have a file for each though, and a matching directory structure.

    In python, functions are declared via the "def" statement. Classes are via the "class" statement. Class methods are just defs nested under a class.

    : Hmmm...in Perl an array is just a collection of scalars indexed by number and a hash is a collection of scalars indexed on a certain key. A scalar can hold a reference to another scalar, array, hashref, sub (named or anonymous) or typeglob.

    In Python a list is just a collection of items indexed by a number and a dictionary is a collection of items indexed by keys. Anything, including objects, can be an item or even a key in these constructs. There are also tuples which are immutable lists, meaning they are of a fixed size and the elements cannot be changed once set.

    : In Perl we have sigils though, e.g. $scalar, @array, %hash. I think Python doesn't have these?

    Correct. I personally find them distracting.

    : Hehe...don't try that in Perl. Anything between back-ticks gets executed! Sounds a bit like VBs approach in a way. I still ain't decided how much I like the C# appraoch to casting...

    The executing of expressions between backticks comes from UNIX shell scripting.

    :
    : float a = 2;
    : int b = (int) a;

    That's straight out of C.

    : : I've heard rumors that future versions of python may include compile-
    : : time typing, but I think I remember reading that Guido was against
    : : that. I'm not sure.
    : It's only going to be optional in Perl6. I'd be pretty upset if it was compulsary to use strict typing all the time!

    Definitely. It's so liberating to not have to.

    : Interesting. I've never known the () being thought of as a call operator...I guess it means you can't call parameterless methods without a () though? Curious, but makes a lot of sense.

    Exactly. Because without the (), it's just a name pointing to an object.

    [code]
    >>> def foo():
    ... print 'foo'
    ...
    >>> foo()
    foo
    >>> foo

    >>>
    [/code]

    Here I created a function named foo. With the call operator it executes, without the call operator I've basically got a pointer to a function object.

    Incidentally, the interactive interpreter is one of Python's neatest features compared to every other language I've used. The stuff after the >>> and ... prompts above is me typing statements and seeing the results immediately. Like VB's immediate window in debug mode, but far more useful.

    : What's __repr__?

    __repr__ is the built-in "toString()" method that returns a string [b]repr[/b]esentation of your object. I think you can also use __str__ because __repr__ is so unintuitive (a leftover from long ago).

    I just did a quick check and the results are curious:

    [code]
    >>> class A:
    ... def __str__(self): return 'A'
    ... def __repr__(self): return 'AAA'
    ...
    >>> a = A()
    >>> `a`
    'AAA'
    >>> str(a)
    'A'
    >>>
    [/code]

    Apparently __str__ and __repr__ are not the same. I'll have to look in to that.

    : Maybe it was competing for the world's longest sentence? I sort of get it... The list of superclasses is essentially a list of objects instantiated from that class,

    A list of classes which the new class will inherit from.

    : and the dictionary contains the blueprint for the new object.

    Basically.

    : The metaclass takes these, creates the object, adds it to the list of superclasses, and returns the object it's created?

    Correct except for the "adds it to the list of superclasses".

    : So basically the metaclass controls object construction for many classes?

    The metaclass controls class creation for many classes.

    : [code]#I'll call the constructor new; call it anything suitable.
    : sub new {
    : #Get invocant.
    : my $invocant = shift;
    :
    : #Create a data structure of some sort.
    : my %hash = (
    : somekey => 'somevalue'
    : );
    :
    : #Create a reference to it.
    : my $hashref = %hash;
    :
    : #Bless the reference - that creates the object.
    : bless $hashref, $invocant;
    :
    : #Return the created object.
    : return $hashref;
    : }[/code]
    : You can write it more compactly, of course. :-)

    This would be the python version of your constructor

    [code]
    def __init__(self):
    self.hash = {somekey = 'somevalue'}
    [/code]

    BTW, languages like C++ and Java (and I assume C#) have the implicit "this" reference. In Python, you explicitly name that reference ("self" is the typical convention but you could use any name).

    : : Really, though, you don't have to think about all this stuff if you
    : : don't want to.
    : That's my problem. I LIKE to think about all this stuff!

    Preach it, bro.

    : Yeah, that's why I love Perl too. Freedom. Perl6 will be even better, as it allows me to be harsher on myself when appropriate by using strict typing, but without sacrificing the freedom I have to not care about typing when it's not going to cause any problems not caring. Long live languages like this. :-)

    Amen.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

  • JonathanJonathan Posts: 2,914Member
    : : Of course, if God is everywhere at once, then that means that (s)he must be in the universe... Or maybe it doens't work like that. :-)
    :
    : Your still thinking of God as separate from the universe. It's not easy shifting a paradigm that's a few millennia old.
    :
    : : Indeed. It's amazing how many people have blind faith in science too, which I'd say comes down to the same thing.
    :
    : Not exactly the same thing but close enough for this discussion.
    :
    : : I guess it's the way it's taught at school in part - as the truth. "Evolution theory is correct" vs "Evolution is the best theory we have at the moment".
    :
    : Well, it is correct so far as we know. This is one of the fundamental points that many anti-evolutionists just don't get. The theory of evolution is very accurate about many things. Any theory which would replace it must account for all of the things which it already has right as well as for new things which the current theory has wrong. I use the term "theory" loosely since Evolution is really an overarching concept embodied by many theories across many disciplines.
    :
    : : Wouldn't it? What if we (somehow) found proof that there WAS a God? Don't you think a lot of people would all of a sudden take up some religion or other?
    :
    : Most certainly.
    :
    : : And...uh...how do you propose to test whether God is there? If you come up with one, I'll try and come up with an excuse... ;-)
    :
    : I'm not the one claiming God is there.
    :
    : : Why isn't it the point? If we could do a test to see whether there was a God, we probably wouldn't be having this discussion because the test would have given the answer. We don't currently know of a test we can carry out to answer that question.
    :
    : Because there's no way to test something that is unfalsifiable!
    :
    : : : Occam's Razor is not on your side here.
    : : Nah, I felt God was necessary. :-P
    :
    : Many people feel God is necessary. As in they can't (or won't, for various reasons) even hypothetically accept the idea of no God. I'm always rather terrified of the believer who says something to the effect of "if there were no God then I could do X" where X is anything one might consider "evil". Murder, theft, I've heard many variations of this statement. Tell me who is more "moral"... he who acts civilized because it is a Good Thing, or he who does so because he's afraid of eternal damnation?
    :
    : : Only if you'd like to. :-) In Perl a "class" can have an AUTOLOAD method that is called if a method that is called cannot be found. Therefore you can compile that method "on the fly" and insert it into the namespace's symbol table. Good thing is that, AFAIK, once you've compiled it, future calls to it have no extra overhead that you would not get on a method compiled in the beginning. You can use these to save you writing a lot of property get/set style methods too! (Or you can read the instance data directly like I do, because method calls can't be interpolated in Perl5...nope, I wouldn't make an OO purist).
    :
    : Ok, that sounds like what Python does. Python objects have a built-in method, __getattr__ which is called when you reference a name that the object doesn't contain. You can also at runtime add new methods to objects (not sure about classes, but probably) by assigning references to them.
    :
    : : : Python has modules (files) that can be imported and treated sort of
    : : : like global objects. A module, though, can contain as many classes
    : : : as you like.
    : : So you must be able to declare a set of subs (methods) as belonging to a particular class. In Perl, you can only declare them as belonging to a particular namespace. You can however have more than one namespace defined in a single file. Convention is that you have a file for each though, and a matching directory structure.
    :
    : In python, functions are declared via the "def" statement. Classes are via the "class" statement. Class methods are just defs nested under a class.
    :
    : : Hmmm...in Perl an array is just a collection of scalars indexed by number and a hash is a collection of scalars indexed on a certain key. A scalar can hold a reference to another scalar, array, hashref, sub (named or anonymous) or typeglob.
    :
    : In Python a list is just a collection of items indexed by a number and a dictionary is a collection of items indexed by keys. Anything, including objects, can be an item or even a key in these constructs. There are also tuples which are immutable lists, meaning they are of a fixed size and the elements cannot be changed once set.
    :
    : : In Perl we have sigils though, e.g. $scalar, @array, %hash. I think Python doesn't have these?
    :
    : Correct. I personally find them distracting.
    :
    : : Hehe...don't try that in Perl. Anything between back-ticks gets executed! Sounds a bit like VBs approach in a way. I still ain't decided how much I like the C# appraoch to casting...
    :
    : The executing of expressions between backticks comes from UNIX shell scripting.
    :
    : :
    : : float a = 2;
    : : int b = (int) a;
    :
    : That's straight out of C.
    :
    : : : I've heard rumors that future versions of python may include compile-
    : : : time typing, but I think I remember reading that Guido was against
    : : : that. I'm not sure.
    : : It's only going to be optional in Perl6. I'd be pretty upset if it was compulsary to use strict typing all the time!
    :
    : Definitely. It's so liberating to not have to.
    :
    : : Interesting. I've never known the () being thought of as a call operator...I guess it means you can't call parameterless methods without a () though? Curious, but makes a lot of sense.
    :
    : Exactly. Because without the (), it's just a name pointing to an object.
    :
    : [code]
    : >>> def foo():
    : ... print 'foo'
    : ...
    : >>> foo()
    : foo
    : >>> foo
    :
    : >>>
    : [/code]
    :
    : Here I created a function named foo. With the call operator it executes, without the call operator I've basically got a pointer to a function object.
    :
    : Incidentally, the interactive interpreter is one of Python's neatest features compared to every other language I've used. The stuff after the >>> and ... prompts above is me typing statements and seeing the results immediately. Like VB's immediate window in debug mode, but far more useful.
    :
    : : What's __repr__?
    :
    : __repr__ is the built-in "toString()" method that returns a string [b]repr[/b]esentation of your object. I think you can also use __str__ because __repr__ is so unintuitive (a leftover from long ago).
    :
    : I just did a quick check and the results are curious:
    :
    : [code]
    : >>> class A:
    : ... def __str__(self): return 'A'
    : ... def __repr__(self): return 'AAA'
    : ...
    : >>> a = A()
    : >>> `a`
    : 'AAA'
    : >>> str(a)
    : 'A'
    : >>>
    : [/code]
    :
    : Apparently __str__ and __repr__ are not the same. I'll have to look
    : in to that.
    Or more to the point, maybe `...` and str(...) are not the same? Could be be a difference of stringification and serialization?

    : : Maybe it was competing for the world's longest
    : : sentence? I sort of get it... The list of superclasses is
    : : essentially a list of objects instantiated from that class,
    :
    : A list of classes which the new class will inherit from.
    Ahhhhh...so it's about inheritence. OK!

    : : and the dictionary contains the blueprint for the new object.
    : Basically.
    :
    : : The metaclass takes these, creates the object, adds it to the list
    : : of superclasses, and returns the object it's created?
    :
    : Correct except for the "adds it to the list of superclasses".
    Yep, I see if more clearly now. Can you actually do things with metaclasses other than get them to create the object for you?

    : : So basically the metaclass controls object construction for many
    : : classes?
    :
    : The metaclass controls class creation for many classes.
    But you just said it returns objects created "from" the classes?

    : : [code]#I'll call the constructor new; call it anything suitable.
    : : sub new {
    : : #Get invocant.
    : : my $invocant = shift;
    : :
    : : #Create a data structure of some sort.
    : : my %hash = (
    : : somekey => 'somevalue'
    : : );
    : :
    : : #Create a reference to it.
    : : my $hashref = %hash;
    : :
    : : #Bless the reference - that creates the object.
    : : bless $hashref, $invocant;
    : :
    : : #Return the created object.
    : : return $hashref;
    : : }[/code]
    : : You can write it more compactly, of course. :-)
    :
    : This would be the python version of your constructor
    :
    : [code]
    : def __init__(self):
    : self.hash = {somekey = 'somevalue'}
    : [/code]
    If it's compact you're after:-
    [code]sub new {
    return bless { somekey => 'somevalue' }, $_[0];
    }[/code]

    : BTW, languages like C++ and Java (and I assume C#) have the
    : implicit "this" reference. In Python, you explicitly name that
    : reference ("self" is the typical convention but you could use any
    : name).
    Just like in Perl. The first argument of any method call is the invocant (ref to the object that called (invoked) the method).

    : : : Really, though, you don't have to think about all this stuff if you
    : : : don't want to.
    : : That's my problem. I LIKE to think about all this stuff!
    :
    : Preach it, bro.
    ;-)

    : : Yeah, that's why I love Perl too. Freedom. Perl6 will be even
    : : better, as it allows me to be harsher on myself when appropriate
    : : by using strict typing, but without sacrificing the freedom I have
    : : to not care about typing when it's not going to cause any problems
    : : not caring. Long live languages like this. :-)
    : Amen.


    Have a good weekend!

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • infidelinfidel Posts: 2,900Member
    : Yep, I see if more clearly now. Can you actually do things with metaclasses other than get them to create the object for you?

    I don't know. I'm just beginning to understand what they are in the first place.

    : : The metaclass controls class creation for many classes.
    : But you just said it returns objects created "from" the classes?

    Yes, metaclasses create classes, which are themselves a form of object, which when called return new instances of their type.

    : If it's compact you're after:-
    : [code]sub new {
    : return bless { somekey => 'somevalue' }, $_[0];
    : }[/code]

    cool.

    : : BTW, languages like C++ and Java (and I assume C#) have the
    : : implicit "this" reference. In Python, you explicitly name that
    : : reference ("self" is the typical convention but you could use any
    : : name).
    : Just like in Perl. The first argument of any method call is the invocant (ref to the object that called (invoked) the method).

    cool again!




    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

  • JonathanJonathan Posts: 2,914Member
    : : Yep, I see if more clearly now. Can you actually do things with
    : : metaclasses other than get them to create the object for you?
    :
    : I don't know. I'm just beginning to understand what they are in the
    : first place.
    Have fun learning...it's got me intriuged enough to try to find more time to give Python a try.

    : : : The metaclass controls class creation for many classes.
    : : But you just said it returns objects created "from" the classes?
    :
    : Yes, metaclasses create classes, which are themselves a form of
    : object, which when called return new instances of their type.
    Or is it more like all classes inherit implicitly from a base class?

    : : If it's compact you're after:-
    : : [code]sub new {
    : : return bless { somekey => 'somevalue' }, $_[0];
    : : }[/code]
    :
    : cool.
    Naturally. It's Perl. ;-)

    : : : BTW, languages like C++ and Java (and I assume C#) have the
    : : : implicit "this" reference. In Python, you explicitly name that
    : : : reference ("self" is the typical convention but you could use any
    : : : name).
    : : Just like in Perl. The first argument of any method call is the
    : : invocant (ref to the object that called (invoked) the method).
    :
    : cool again!
    See? Perl IS cool!

    FYI, on the Perl6 internals list, which is basically the list for Parrot (a runtime engine that is designed to best support dynamically typed languages), someone (a couple of people maybe) are having a crack at implementing a Python compiler that targets Parrot. And guess what they called it? Pirate. Yup, Python-Parrot, Py-rot, Pirate. :-)

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • infidelinfidel Posts: 2,900Member
    : : : : The metaclass controls class creation for many classes.
    : : : But you just said it returns objects created "from" the classes?
    : :
    : : Yes, metaclasses create classes, which are themselves a form of
    : : object, which when called return new instances of their type.
    : Or is it more like all classes inherit implicitly from a base class?

    Well sort of. All classes (in newer versions of Python) inherit from "object" which is itself a metaclass. There's more than just inheritance involved, though.

    : : : If it's compact you're after:-
    : : : [code]sub new {
    : : : return bless { somekey => 'somevalue' }, $_[0];
    : : : }[/code]
    : :
    : : cool.
    : Naturally. It's Perl. ;-)

    But it's still harder to read than Python. :-)

    : : cool again!
    : See? Perl IS cool!

    Of course, dynamically typed scripting languages are the coolest. Not sure about Ruby, though :-P

    : Yup, Python-Parrot, Py-rot, Pirate. :-)

    LOL.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

  • JonathanJonathan Posts: 2,914Member
    : Well sort of. All classes (in newer versions of Python) inherit
    : from "object" which is itself a metaclass. There's more than just
    : inheritance involved, though.
    Interesting... Maybe one day you (and maybe I) will be blessed with fully understanding of metaclasses. :-)

    : : : : If it's compact you're after:-
    : : : : [code]sub new {
    : : : : return bless { somekey => 'somevalue' }, $_[0];
    : : : : }[/code]
    : : :
    : : : cool.
    : : Naturally. It's Perl. ;-)
    : But it's still harder to read than Python. :-)
    Yeah, but aren't the underscores in Python ugly? Admittedly, the bless keyword isn't obvious in it's function, though.

    : : : cool again!
    : : See? Perl IS cool!
    : Of course, dynamically typed scripting languages are the coolest.
    I guess we could call them evolved scripting languages; I tend to consider Perl a fully fledged programming language these days.

    : Not sure about Ruby, though :-P
    Haven't seen much of it. Somebody once described it as "OO Perl", but I think there's something more to it than that!

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • infidelinfidel Posts: 2,900Member
    : Yeah, but aren't the underscores in Python ugly? Admittedly, the bless keyword isn't obvious in it's function, though.

    Ugly? I don't think so. Maybe I'm just used to them. And it's only on "special" methods of classes that they are required.

    : : Of course, dynamically typed scripting languages are the coolest.
    : I guess we could call them evolved scripting languages; I tend to consider Perl a fully fledged programming language these days.

    Absolutely. Same with Python.

    : : Not sure about Ruby, though :-P
    : Haven't seen much of it. Somebody once described it as "OO Perl", but I think there's something more to it than that!

    Not from what I've seen. It's like they took Python and gave it Perl syntax. Took away the "ugly" underscores and gave it @s and $s, etc. There are Ruby fans who are so anti-Python, they claim that Ruby is SO much easier to understand than Python. I think they're a bit loopy.




    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

Sign In or Register to comment.