Re: [Tutor] A simple question about creating a program
On Mar 31, 2005, at 23:07, Alan Gauld wrote: And if Sun ever get round to finishing their JVM on a chip we'll have a chip that is both OO and procedural! At that point it would be a JRM, then, wouldn't it? :D -- Max maxnoel_fr at yahoo dot fr -- ICQ #85274019 "Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?" ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A simple question about creating a program
Just to be picky... > code to be executed by the processor. Machine language is not > object-oriented. In some cases it is. The Rekursiv computer by Linn systems had a CPU that had an OO machine language which supported parallelism by exposing 'threads' as active objects at the machine code level. But if we leave experimental architectures aside and deal with the 99.99% of mainstream you are of coure correct :-) > It's not even procedural, or anything. And again some chips have been built with Forth as their native machine code (or more accurately with a FOrth intetpreter as their microcode) and it is procedural. And again such chips, while available commercially never exactly made it to mainstream. And if Sun ever get round to finishing their JVM on a chip we'll have a chip that is both OO and procedural! > Any program can be written in any (Turing-complete) programming > language. And again thats only true for algorithmically biased programs, event driven code integrated with the external environment needs to be more than simply Turing complete. A Turing complete language may have no I/O capability or interface to OS or hardware events, thus making event driven code impossible. But again I'm being picky, it must be the time of night! Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A simple question about creating a program
> I was wondering, can you make a program the uses alot of classes do > the exact same thing with out useing classes? Yes you can always write a program without classes but it may be a lot more work and its likely to be a lot harder to maintain. Especially if its a big program. However if you use a language like Python its very difficult to write a program that doesn't use any classes because the built in types are clases, or objects. And many of the modules in the library have classes in them so you would need to reinvent all of that functionality yourself! Alan G Author of the Learn to Program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A simple question about creating a program
On Wed, 30 Mar 2005, Kevin wrote: > I was wondering, can you make a program the uses alot of classes do the > exact same thing with out useing classes? Hi Kevin, Yes. We can even do a lot of object oriented programming without classes, although it might be slightly painful. You asked an earlier question about constructors, so I'll try to flesh that out too. Let's use a small toy example. If we have a Person class: ## class Person: def __init__(self, name): self.name = name self.friends = [] def addFriend(self, otherPerson): self.friends.append(otherPerson) def sayHelloToAll(self): for friend in self.friends: print "hi", friend.name, "it is I,", self.name ## then we can just play with it: ## >>> alan = Person("alan") >>> tim = Person("tim") >>> alan.addFriend(tim) >>> alan.sayHelloToAll() hi tim it is I, alan ## But we can write fairly close code that just uses functions! ## def makePerson(): return {'name': None, 'friends' : None} def initPerson(self, name): self['name'] = name self['friends'] = [] def addFriend(self, otherPerson): self['friends'].append(otherPerson) def sayHelloToAll(self): for friend in self['friends']: print "hi", friend['name'], "it is I,", self['name'] ## Let's see how this might work: ## >>> (kevin, danny, sean) = (makePerson(), makePerson(), makePerson()) >>> initPerson(kevin, "Kevin") >>> initPerson(danny, "Danny") >>> initPerson(sean, "Sean") >>> addFriend(kevin, danny) >>> addFriend(kevin, sean) >>> sayHelloToAll(kevin) hi Danny it is I, Kevin hi Sean it is I, Kevin ## What's different here from the code with the explicit 'class' stuff is only mere appearance. Syntactially, it has the appearance of: verb(subject, object) If we were to use classes, things would look more like: subject.verb(object) which some people prefer to read. But it's a bit clunky to do this all by hand. As a concrete example, Python's class support automatically does stuff like makePerson() for us: we just have to write an appropriate initializer to shape the object the way we want. When we do something like this with Classes: ## personUsingClasses = Person("Kevin") ## we are actually doing two things: we first "construct" an object, and then we "initialize" it to fill the object in. In the function code above, we can see these two steps: ## personUsingFunctions = makePerson() initPerson(personUsingFunctions, "Kevin") ## It's a common idiom to do construct-and-init, since an uninitialized object is pretty useless, so Python's class support always does construction for us. This allows us to concentrate on the part that's really important to us --- the initializer. If we use Python's class support, stuff like this tends to be briefer and easier to read. So a little bit of Python's class support is syntax to make it nicer to write code that focuses on "objects". Does this make sense so far? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A simple question about creating a program
On Mar 30, 2005, at 23:00, Kevin wrote: I was wondering, can you make a program the uses alot of classes do the exact same thing with out useing classes? Yes. At some point, a program always has to be translated to machine code to be executed by the processor. Machine language is not object-oriented. It's not even procedural, or anything. Therefore, OO programming is just a more convenient way to write the code. Any program can be written in any (Turing-complete) programming language. -- Wild_Cat maxnoel_fr at yahoo dot fr -- ICQ #85274019 "Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?" ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] A simple question about creating a program
Yes you can, but if an app uses a lot of classes, chances are that it's the simplest way to do it. OOP is really just a convenient way to work with code. On Wed, 30 Mar 2005 16:00:03 -0500, Kevin <[EMAIL PROTECTED]> wrote: > I was wondering, can you make a program the uses alot of classes do > the exact same thing with out useing classes? > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to take the consequences. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
RE: [Tutor] A simple question about creating a program
Sure. Thanks, Ryan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kevin Sent: Wednesday, March 30, 2005 4:00 PM To: tutor@python.org Subject: [Tutor] A simple question about creating a program I was wondering, can you make a program the uses alot of classes do the exact same thing with out useing classes? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] A simple question about creating a program
I was wondering, can you make a program the uses alot of classes do the exact same thing with out useing classes? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor