← 输入框|github.com|刷新
Skip to content

object oriented mode #60

Closed
Closed

Description

@darvin

Object Oriented mode

Make 2 modes in application:
Procedure - current
Object Oriented.
It will be swiched in menu (?)

When OO mode is swiched, turtle widget blanks.
then we can use OO approach:

mike = Turtle()
mike.go(30)
mike.turn(60)

gandalf = Turtle(x=50, y=40)
gandalf.go(90)


class JumpingTurtle(Turtle):
     def jump(self):
          self.go(50)

 froggy = JumpingTurtle()
 froggy.jump()

It will be coolest education application ever!

Activity

  1. darvin commented on Sep 29, 2010

    @darvin
    Author

    almost done, one fix needed.
    after every change, i need type send() in python console.
    please, help me
    http://github.com/darvin/PythonTurtle/blob/master/src/animals.py
    ###FIXME!!!
    # locals()"send"

    this line must call send_report from turtleprocess.py.
    then objective-oriented turtles will work! )

  2. cool-RR commented on Sep 29, 2010

    @cool-RR
    Member

    Very cool idea!

    Let me look at that problem.

  3. cool-RR commented on Sep 29, 2010

    @cool-RR
    Member

    I think the problem is that you're not calling .send_report() in your animals. Note that in the original turtle, every time it does something it calls .send_report(). This makes the screen draw the current position. It even calls .send_report() multiple times in every action so the movement will be smooth.

    (Note: Classes should have a Capitalized name.)

  4. darvin commented on Sep 29, 2010

    @darvin
    Author

    i know about send report, i trying to call it, but i cant. please help me! )

    this is correct place to call send report:

    http://github.com/darvin/PythonTurtle/blob/master/src/animals.py
    ###FIXME!!!

    locals()"send"

    i have no idea

  5. cool-RR commented on Sep 29, 2010

    @cool-RR
    Member

    Why do you think that the right place to call it is in __setattr__? I don't understand. The .send_report() method should be called in the go and turn functions. I think you have removed these calls when you duplicated my_turtle.py to animals.py, so try to bring them back.

    And please explain your reasoning regarding __setattr__.

  6. darvin commented on Sep 29, 2010

    @darvin
    Author

    in go and turn self.position and self.orientation changes, so setattr will trigg at proper place (i checked)

    real problem is that .sendreport() in turtleprocess.py, and old go() turn() etc was in turtleprocess. but now, go, turn etc in animal.py and i have no idea how to call method of animal.py from animals.py

  7. cool-RR commented on Sep 29, 2010

    @cool-RR
    Member

    (Note: Please wrap code segments with backticks (Character to left of "1") for readability.)

    I understand the problem now. (Nice idea with __setattr__ by the way.)

    I think I have a solution. First, rename .send_report() to ._send_report(). (Should be done anyway.) Now, in TurtleProcess.run() you do Animal._send_report = self.send_report. (The name will have a leading underscore only on Animal.)

    Now you could call self._send_report() from any animal, I think.

  8. darvin commented on Sep 29, 2010

    @darvin
    Author

    i ll try

  9. darvin commented on Sep 29, 2010

    @darvin
    Author

    cool! it works well!
    fixed in my dev branch

  10. cool-RR commented on Sep 29, 2010

    @cool-RR
    Member

    Getting rid of my_turtle and migrating to animals is fine. There's no concept of backward-compatibility on this software either, so a deprecation period is not needed, we can just move.

    I think that letting users switch modes would be slightly confusing. (Remember, little children.) What I think would be good is a combination of both modes: The OOP mode will be on but a turtle will be created at startup, and the go and turn functions will be bound to its respective methods. What do you think?

  11. darvin commented on Sep 29, 2010

    @darvin
    Author

    i do not think so.
    it be confusing:
    d = Turtle()
    d.go(10)
    go(10)
    `
    i sure that modes is better.

  12. darvin commented on Sep 29, 2010

    @darvin
    Author

    in oop mode, if there is not objects - no turtles. it is clear

  13. cool-RR commented on Sep 29, 2010

    @cool-RR
    Member

    The snippet of code you gave is indeed a bit confusing; The go function will be tied to the initial turtle. But I think that it's not so hard to get used to.

    Giving modes is problematic. Remember this should be usable by a young child who doesn't know what programming is, let alone what OOP is. Even the concept of changing modes might be hard for him. He might not even think to check the menu for it. Also, if you have two separate modes, what will you do with the drawing and existing turtles when the user switches mode? Destroy them? Not nice.

  14. darvin commented on Sep 29, 2010

    @darvin
    Author

    understanding OOP, when we have global function with same name that object method is hard.
    i think, we can make 2 "levels"
    or 2 modes: "One Turtle (light mode)"
    "Many Animals (hard mode)"

  15. darvin commented on Sep 29, 2010

    @darvin
    Author

    by default, we run in "One Turtle (light mode)". If kid is smart, it checks menu.
    We can even show warning window:
    You select Many Animals (hard mode). If you do not know, what is Object-Oriented Programming,
    visit http://our_wikiexplainingsomethings (or may be local help file)
    Are you sure that you want to leave "One Turtle (light mode)" and switch to "Many Animals (hard mode)"
    yes no

  16. cool-RR commented on Sep 29, 2010

    @cool-RR
    Member

    Can you please explain thoroughly what are the advantages of having a separation between the two modes, in contrast to having both of them at the same time?

    You gave one argument up to now, that it will be confusing that there is both go and Turtle.go. That's true. But it will be much more confusing, for example, to have two different sets of documentation.

    Can you please explain the advantages of your approach?

    Here are the advantages of the combined approach:

    • The child doesn't need to understand the concept of different modes.
    • We don't have to program the user interface needed for two modes, and solve all the bugs that that will involve.
    • We don't have to maintain two sets of documentation.
    • There will not be a case where the child writes down a piece of code only to be disappointed by it not working because he was in the wrong mode.
    • There will not be a case where the child writes down a piece of code only to be disappointed by it not working because he was mixing code from the two different modes.
  17. darvin commented on Sep 30, 2010

    @darvin
    Author

    i understand. may be we make "settings" or command-line argument for pure OOP mode?

  18. cool-RR commented on Sep 30, 2010

    @cool-RR
    Member

    Ah, so by default it will be procedural+OOP, and only with the special setting it will be pure OOP? Sounds okay. Having a menu check-box to do it sounds good. (It can be called "Pure OOP Mode (Delete initial turtle)").

    A command-line argument for pure OOP can also be added (in addition to the menu setting), I'm okay with that.

  19. darvin commented on Sep 30, 2010

    @darvin
    Author

    we can make two options in menu:
    Reset
    Reset (Delete initial turtle)

  20. cool-RR commented on Sep 30, 2010

    @cool-RR
    Member

    I'd want to change "Reset (Delete initial turtle)" to "Reset and delete initial turtle". That will be alright with me.

  21. darvin commented on Sep 30, 2010

    @darvin
    Author

    ok.
    i will add GUI options.
    can you implement reset python enviroment function? i have no idea how to start

  22. cool-RR commented on Sep 30, 2010

    @cool-RR
    Member

    I have no time to implement anything regarding PythonTurtle. I can only guide you in implementing it.

    I don't see any problem with resetting the process. You terminate the existing process with .terminate(), create a new one, create a queue-pack for it and plug it into the shell. (I'm not sure this is 100% correct, but probably.) If you have any problems with it I'll help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions