Re: Pass by address
- Posted by Andy Cranston <Andy.Cranston at EUPHONY.CO.UK> Aug 17, 2000
- 501 views
David Cuny wrote (and not in this order): <SNIP> >Rather than pass by reference, Euphoria allow a sort of dot notation. Most >of the time, you're only passing one object to be altered. So: > > a.bar( b, c ) > >would be shorthand for: > > a = bar( a, b, c ) > >if bar was a function, and shorthand for: > > bar( a, b, c ) > >if bar was a procedure. That way, you could write: > > window.center_window() > >and it would behave *properly*, as if it were a reference, without actually >introducing reference passing to the language. No special keywords, no >question about if a variable is a value or a reference. The syntax is >natural: > > myWindow.make_visible() > myPoint.add_point( 12, 32 ) > myAccount.debit( 5000.00 ) > myShape.draw() > >It looks like it's OOP, but it's not. It's just syntactic sugar. <SNIP> That's a very elegant proposal and applicable to alot of procedural languages that have assignment and functions - not just Euphoria. Full marks! <SNIP> and then call it like this: window = center_window( window ) I'm cringing just writing that code. *bleah* After coding in C, QBasic and Java, this just feels unnatural. <SNIP> As code like this has such an adverse effect on you (re: *bleah* I'll have to make a mental note not to show you any of my code It's littered with this sort of stuff. Can you believe that most of my C programs have things like: var = var + 1 !!! Maybe I just like torturing myself Actually my coding style (if it can be called a style!) is on the "baby" side. I heard the term "baby programming" a few years back and liked it because it described my programming style very well. One look at any of my code and other programmers instantly react with things like "it's better if you do it like this - less code, more elegant, etc. etc.". The point is that although the code is longer than it needs to be, might not exploit handy features of the language and what not the code is instantly readable (well almost). The fact than another programmer can take one look at my code and immediately grasp what I trying to do and come up with more succint and elegant ways to do it is, for me, actually a compliment. I've written something that is understandable - maybe pretty ugly but understandable never the less. Of course I'd never get away with this if I coded for a living - I'd starve for a start. But for my requirements right now I'll continue with the "baby programming". Regards, Andy Cranston.