Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail From: Bernd Paysan Newsgroups: comp.lang.forth Subject: Re: Went open source with my GA144 simulator written in Factor Date: Sat, 27 Apr 2013 00:48:08 +0200 Organization: 1&1 Internet AG Lines: 63 Message-ID: References: <1cd5dbe8-f8c0-48c5-b673-2a12d7b776bd@googlegroups.com> <93974620-b0ac-481f-a659-3547f8921282@w1g2000vbw.googlegroups.com> <1cfe84c3-97aa-4f17-bdd3-db2a4cd8b631@a34g2000vbt.googlegroups.com> <_tadnVKPhZq9_eTMnZ2dnUVZ_gCdnZ2d@supernews.com> <3-mdndGBcPy2XOfMnZ2dnUVZ_j6dnZ2d@supernews.com> <517adbd7$0$32117$14726298@news.sunsite.dk> NNTP-Posting-Host: p4ffb94c2.dip0.t-ipconnect.de Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: online.de 1367016490 10561 79.251.148.194 (26 Apr 2013 22:48:10 GMT) X-Complaints-To: abuse@einsundeins.com NNTP-Posting-Date: Fri, 26 Apr 2013 22:48:10 +0000 (UTC) User-Agent: KNode/4.10.2 Xref: csiph.com comp.lang.forth:21951 Doug Hoffman wrote: > Perhaps you could explain to Andrew, and the rest of us, why it's good. When you do OOP programming, you usually refer to instance variables. If you use something like Mini-OOF, it's going to be :noname ( params ... this -- return ) { this } this x @ this y @ ... this bla ; your code is cluttered with "this". Many OOP packages therefore "hide" the local this, to make instance variable access use a local variable, but you still need this to call other methods. As we are programming Forth, our methods are factored into small one- or two-liners, which means we mostly call other methods or helper words dealing with the same object. With an explicit this, it means your code is full of "this" even when you hide it for instance variables. > Consuming a register seems a very large price to pay, if that is > required, and not likely to exist for very many Forths. You can use a user variable if your architecture is register starved (i.e. x86). Many OOP systems have some sort of current object pointer, and if you have enough registers, putting that into a register improves performance significantly (depends on the code generator, of course). > But I gather > it's not required. So maybe we should ignore that aspect for now. > > The >o and o> manipulations for the object stack is obviously more > effort for the programmer, so an explanation of the usage (when and why > use >o and o>) and the payback for the programmer would seem beneficial. When: When you switch the object used. Compared to actually *use* the object (as base pointer for instance variables or to call methods with it), this is the rare case. You should tune your tools for the common case, not for the rare case. Why: To tell the system that you switched the object used. When I talk about OOP programming, I often see that the Sapir-Worph hypothesis isn't that wrong. People use their own idiom, and it forms their code ("thinking"). When you suggest other idioms, you receive blank stares. People can't imagine the benefit of something they don't know, so any attempt at explaining it results in more blank stares. Something we Forthers are confronted with quite often ;-). So please try it, and check if it benefits your code, or if your coding style changes. I've tried both (as Mini-OOF was without current object), and my personal result was that OOP without current object is too cumbersome to use. Many OOP systems have a compromise, as I said, using the current object pointer for instance variables, but not for method invocation. This results in inconsistent code, which needs more explanation than consistent code. BerndOOF makes the >o o> manipulations implicit in many cases, but all this implicit magic might be overkill. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/