and
So you are talking about an editor feature and not a language feature?
I am starting to get an idea of where I misunderstood you…
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.
Wouldn’t the general use case at issue here be addressed by adding
standalone versions of various functions traditionally associated with
collections so that one could call say reduce like “reduce myarray,
:+”?
I do not think it is a good idea as a general rule because that
totally breaks OO. And cluttering the global namespace with a ton of
methods which just delegate to instance methods with the same name
does not seem a good idea to me either.
As a general remark: we need to balance readability (which generally
benefits from making things explicit, but not too many things) and
writing efficiency (less text => more implicit).
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:
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.
Does TextMate have its own mechanism to name a folded block of code,
e.g. by providing the name in a comment? Maybe that would work for
you, although you’d have to place the block on multiple lines.
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.
e.g. by providing the name in a comment? Maybe that would work for
you, although you’d have to place the block on multiple lines.
I am pretty sure I’d have to hack the syntax file. I probably would if I
were more competent. The biggest reason that doesn’t seem like a
solution
is that I work on a team with other people. Also, I use Vim about half
the
time.