[plt-scheme] Re: [plt-edu] Re: animation projects, video-game and not

From: YC (yinso.chen at gmail.com)
Date: Sat Feb 7 13:38:52 EST 2009

On Sat, Feb 7, 2009 at 10:06 AM, Matthias Felleisen <matthias at ccs.neu.edu>wrote:

>
>
> Think of the World as an object for which you have three or four methods:
>
>  ;; tick :  World -> World
>  ;; click : World KeyEvent -> World
>  ;; clack : World MouseEvent - World
>  ;; draw :  World -> Scene
>  ;; stop? : World -> Boolean
>
> As you can see (1) these methods belong together, (2) in a functional
> language you must pass in the world, and (3) you usually destructure it via
> field access to the struct. So there is clearly a certain intellectual
> elegance to
>
>  (define World
>   (class ...
>     ;; -> World
>     (define/public (tick) ...)
>     ;; KeyEvent -> World
>     (define/public (click ke) ...)
>     ;; MouseEvent -> World
>     ... ))
>
> Pardon my Java :-) You see it's really about having classes around to
> organize your code. It has nothing to do with Java.
>
> Better still, you can use inheritance to prepare default behaviors and then
> quickly instantiate this anticipated scenarios. When I teach Softw Dev (~12
> Kloc to 18 Kloc of Java for the poor students who use Java), I actually use
> the PLT Scheme class system to write code like this.
>
>
Coming from the OOP practitioner world, I greatly value classes as an
organization, especially the constructor & destructor and the RAII idiom.
It's ironic that one of the points against Java is too much boiler plate
code, all of which helps the large program to organize themselves.

I am learning to use just plain modules and structs to achieve the
organization effect these days.  Module provides encapsulation.  And struct
provides basic inheritance, so what's missing is polymorphism, but that's
possible to achieve if the struct themselves carry the functions that they
need to call. Also I miss the destructor and explicit finalize.  Those comes
in very handy for external resource management.

I am probably reinventing the wheel, but that appears to be how I learn :)

yc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090207/4c6f56db/attachment.html>

Posted on the users mailing list.