From: Josh Cheek Date: 2012-02-09T18:34:18+09:00 Subject: Re: Using _ like in Scala? --f46d0442816a3b7cc004b884b7c6 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Feb 9, 2012 at 2:42 AM, Robert Klemme wrote: > On Thu, Feb 9, 2012 at 1:39 AM, Josh Cheek wrote: > > Yes, what I want is an editor feature (it's also a cognitive aid, even > > without an editor to take advantage of it), but it requires a language > > feature to enable. > > OK, just trying to clarify. You wrote > > > Although what I'd really like would be a syntax for naming inline blocks, > > then my editor could fold the block body inside the name, something like > > %w[apple banana orange].each display > > > > And it would expand to something like > > %w[apple banana orange].each { |display -> fruit| puts fruit } > > Somehow I didn't understand what you meant by "syntax for naming > inline blocks" because it did not occur to me that you might be > missing something we actually do have already: > > irb(main):001:0> display = ->(x) { puts x } > => # > irb(main):002:0> %w[apple banana orange].each &display > apple > banana > orange > => ["apple", "banana", "orange"] > > Now, what is missing? > > Yeah, I gave that example in my first response, just before "But never found anything I was very happy with" :) It is pretty rare, though, to encounter a situation where placing a lambda in a local var is less clutter than inlining it. As a general opinion, I find that I have an aversion to local variables, they make code harder to read, there are a lot of ways to get around them, hence the other alternative I showed (but also ultimately disliked) of placing the lambda in some other method. Another thing I will frequently do is have the body of the block delegate to some method. That provides a nice abstraction like what I'm wanting, but it leads to lots of methods which clutter the class, making it again less readable (which in turn leads to more objects with more specific responsibilities). What I suppose I really want is a language that is not in plain text, but stored in some sort of abstraction such that a method only invoked in one place can be hidden from everywhere, but examined and altered at will. Like you only see some file if you're in it's containing directory, but when you're in the directory, you can just look at it's name, and cat it to see its contents. Seeing some other method's helper methods is like seeing other directories' files. Storing them in local variables is like seeing the contents of all the files in your directory every time you cd or ls. I would like the language itself to abstract away such things, hide that code away where I only see it if I explicitly want to. But I imagine any such language would be problematic because you could then only edit it in IDEs that understood the data format. This "naming blocks" seemed like a nice compromise that would enable any normal editor to achieve similar abstractions, while enhancing readability, maintaining plain text, and requiring almost nothing to change within the language. --f46d0442816a3b7cc004b884b7c6--