• Lucid Dreaming - Dream Views




    Page 2 of 2 FirstFirst 1 2
    Results 26 to 28 of 28
    Like Tree2Likes

    Thread: Ask me about Python

    1. #26
      Banned
      Join Date
      Apr 2007
      Location
      Out Chasing Rabbits
      Posts
      15,193
      Likes
      935
      Quote Originally Posted by PhilosopherStoned View Post
      Of course polymorphism isn't loose typing. Polymorphism is one of the foundations of good design. void* is loose typing and I see it used all over the place (at least in C). "Exists in the language" means the language is not strongly typed. You may program in a subset of it that is (and I commend you for that) but you can't seriously claim that a language that lets you treat any type as any other type is strongly typed.
      You are confusing terms. Loose typing means that values can be implicitly converted between each other. void* is rarely used. It's purpose is mostly, for raw data buffers, or passing things into OOP libraries.

    2. #27
      Rational Spiritualist DrunkenArse's Avatar
      Join Date
      May 2009
      Gender
      Location
      Da Aina
      Posts
      2,941
      Likes
      1092
      Damn I'm rusty. I wouldn't access __dict__ directly here but use getattr instead. Also, I would equip it with a factory function to create instances. All it has to do is pass its arguments to the constructor for socket and wrap the result before it returns it.

      Code:
      class IrcSocket: #No need to extend object because this is p3k
          def __init__(self, id, socket):
               self.id = id
               self._socket = socket
       
          def send(self, bytes):
               log(bytes)
               socket.socket.sendall(self._socket, bytes)
       
          def accept(self, *args, **kwargs):
               tmp_socket = self._socket.accept(*args, **kwargs)
               return type(self)(some_id*args, tmp_socket)
       
          def __getattr__(self, attr):
              return getattr(self._socket, attr)
       
          @classmethod
           def new(cls, *args, **kwargs):
              return cls(socket.socket(*args, **kwargs))
      The classmethod is called on the class and not on instances. So you would call it like IrcSocket.new(*args, **kwargs) where args and kwargs are the arguments that you would use to construct the normal socket. If you need custom arguments, then let me know and I can show you how to do that.

      @ninja. I don't reallty want to debate this. The assertion that c++ is "the most strongly typed language behind only ada" is laughable. Python is much more strongly typed than c++. Haskell is even more so (and avoids the annoying type declarations in many cases). Arbitrary casting is weak typing as you implied a few posts ago. Granted, it's not as bad as PHP or Javascript (otherwise a great language) but it's still a weakly typed language. It's also a statically typed language. So it gets you all the inconvenience of a statically typed language with only a few of the benefits of strong typing. As I said though, it's possible to program in a strongly typed subset of it. If you do so, then great.

      At any rate, your whole argument is cast in terms of absolutes that are just wrong. This is typical of your thinking. I have not a shred of respect for you and am not interested in debating this point with you. Please GTFO my thread. Thanks.
      Previously PhilosopherStoned

    3. #28
      khh
      khh is offline
      Remember Achievements:
      1000 Hall Points Veteran First Class
      khh's Avatar
      Join Date
      Jun 2009
      Gender
      Location
      Norway
      Posts
      2,482
      Likes
      1309
      Thanks, it looks like it's working now. That __getaddr__ trick was cool.

      Quote Originally Posted by PhilosopherStoned View Post
      The classmethod is called on the class and not on instances. So you would call it like IrcSocket.new(*args, **kwargs) where args and kwargs are the arguments that you would use to construct the normal socket. If you need custom arguments, then let me know and I can show you how to do that.
      Ok, when is it best to use IrcSocket.new() and when is it all right to use s = IrcSocket()?
      And how can you get custom arguments for the socket, like defining the ID?
      April Ryan is my friend,
      Every sorrow she can mend.
      When i visit her dark realm,
      Does it simply overwhelm.

    Page 2 of 2 FirstFirst 1 2

    Similar Threads

    1. Pass Variables Between JavaScript and C++/Python?
      By youssarian in forum Tech Talk
      Replies: 6
      Last Post: 01-12-2010, 04:27 AM
    2. Halp! (Python)
      By ThreeLetterSyndrom in forum Tech Talk
      Replies: 5
      Last Post: 06-23-2009, 09:43 PM
    3. Tell me about Python
      By DuB in forum Tech Talk
      Replies: 9
      Last Post: 04-29-2009, 04:55 PM
    4. Python Reality Check Tester
      By Wesley_Gray in forum Lucid Aids
      Replies: 10
      Last Post: 08-01-2008, 02:16 AM
    5. Fav Python Quotes
      By Mystical_Journey in forum The Lounge
      Replies: 20
      Last Post: 05-12-2005, 09:50 PM

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •