Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object oriented mode #60

Closed
darvin opened this issue Sep 29, 2010 · 22 comments
Closed

object oriented mode #60

darvin opened this issue Sep 29, 2010 · 22 comments

Comments

@darvin
Copy link

darvin commented Sep 29, 2010

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!

@darvin
Copy link
Author

darvin commented Sep 29, 2010

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! )

@cool-RR
Copy link
Member

cool-RR commented Sep 29, 2010

Very cool idea!

Let me look at that problem.

@cool-RR
Copy link
Member

cool-RR commented Sep 29, 2010

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.)

@darvin
Copy link
Author

darvin commented Sep 29, 2010

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

@cool-RR
Copy link
Member

cool-RR commented Sep 29, 2010

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__.

@darvin
Copy link
Author

darvin commented Sep 29, 2010

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

@cool-RR
Copy link
Member

cool-RR commented Sep 29, 2010

(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.

@darvin
Copy link
Author

darvin commented Sep 29, 2010

i ll try

@darvin
Copy link
Author

darvin commented Sep 29, 2010

cool! it works well!
fixed in my dev branch

@cool-RR
Copy link
Member

cool-RR commented Sep 29, 2010

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?

@darvin
Copy link
Author

darvin commented Sep 29, 2010

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

@darvin
Copy link
Author

darvin commented Sep 29, 2010

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

@cool-RR
Copy link
Member

cool-RR commented Sep 29, 2010

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.

@darvin
Copy link
Author

darvin commented Sep 29, 2010

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)"

@darvin
Copy link
Author

darvin commented Sep 29, 2010

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

@cool-RR
Copy link
Member

cool-RR commented Sep 29, 2010

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.

@darvin
Copy link
Author

darvin commented Sep 30, 2010

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

@cool-RR
Copy link
Member

cool-RR commented Sep 30, 2010

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.

@darvin
Copy link
Author

darvin commented Sep 30, 2010

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

@cool-RR
Copy link
Member

cool-RR commented Sep 30, 2010

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

@darvin
Copy link
Author

darvin commented Sep 30, 2010

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

@cool-RR
Copy link
Member

cool-RR commented Sep 30, 2010

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.

This was referenced Mar 30, 2019
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants