From: Yuh-Ruey Chen Date: 2008-11-02T06:53:56+09:00 Subject: Re: How to access to local variables in enclosing scopes? On Nov 1, 6:54 am, Stefan Lang wrote: > 2008/11/1 Yuh-Ruey Chen : > > > Replying to multiple posts: > > > On Oct 31, 5:19 pm, Stefan Lang > > wrote: > >> In the end, you'll find out what looks like a big problem now > >> actually isn't. The most important usecase for your desired > >> scoping rules would be nested functions, and Ruby doesn't > >> have them. And for the other use cases, constants, class- > >> and module instance variables suffice. OTOH, you can nest > >> blocks as much as you like and scoping is what you expect. > > > I recognize that access to nonlocal vars can be simulated with > > instance variables. > > Instance variables don't simulate anything. I mean that whatever you could do with access to nonlocal vars you could do with a class with instance variables design. Just a different programming methodology. > > It does seem weird to allow two different > > paradigms that interact with each other in a confusing - or at the > > least non-trivial - matter (just look at my confusion). > > It seems to me you are confused because you are learning by > posting questions on mailing lists instead of following > some coherent book or introduction material. I actually held off from posting here for a while during my experimenting and reading of online docs. > > I guess my big beef with Ruby is that it is too complex and bloated > > with features that often are inconsistent or lack symmetry with each > > other. It's too "magical", making it hard to learn exactly how the > > language works. From a language design perspective, Ruby really seems > > like a mess to me, although with moments of brilliance. Most of the > > time, when I'm metaprogramming, I'm guessing and looking at the > > output, hoping I got so-and-so quirk correct. > > Then stop guessing and learn first. Start with Programming Ruby, > here's an older version online:http://ruby-doc.org/docs/ProgrammingRuby/ > > And search ruby-doc.org for more material. Seriously, you sound > like you're parroting some preconceived views about Ruby I've > seen before from other Python programmers, without even trying > to learn. Aside: I don't have any "preconceived" views on Ruby. I've heard about how elegant it is, and indeed I found most of the syntax examples elegant in some way or fashion. I'm also not primarily a Python programmer, although I greatly admire how it integrates iteration so well into the language. I work with all sorts of languages: C, Java, Python, JS, or whatever else I find fascinating to experiment in. I do feel that there are several aspects of Ruby that could be simplified. It feels like Ruby has been influenced a lot by Perl, and I absolutely loath Perl. But there are several aspects of Ruby that I do admire: everything being an object, open classes, how the block syntax meshes with a function call, the various function calling sugar like omitting parenthesis (although I think I slightly prefer Python's sugar with regards to * and **).