"Readability" inflation

Martin DeMello wrote:

···

David A. Black <dblack@wobblini.net> wrote:
>
> I think what's happening is that people who've used Ruby for a while
> get used to it, and then they sort of shift their readability
> threshold. In other words, if you've seen this:
>
> a.map {|b| b.meth }
>
> for several years, then even though it looked beautiful and concise
> and transparent to you at first, it will start to look verbose and
> syntactically inefficient. So then you might want to have:

I usually come around to agreeing with you that so-and-so change adds
more line noise than is worth it, but this particular one I've disliked
right from the beginning. It's not just the visual clutter, it's the
conceptual overhead of introducing a new variable merely because ruby
has to attach a method to something. Note the progression from

ary.sort {|a,b| a.meth <=> b.meth}
ary.sort_by {|a| a.meth}
ary.sort_by :meth

Shall I be so bold:

  ary.sort_by.meth

:wink:

T.

Ryan,

All work and no play? :frowning:

T.

Trans wrote:

Case in point, what's the english equiv of #===. I'd really like to
have one.

"kind of equal to"? :slight_smile:

   pizza = Pizza.new :crust_thickness => :really_thick,
                     :toppings => [:pepperoni, :ham]

looks like a hash, if you ask me...

so what the extra keyword for ??

···

On Fri, 28 Oct 2005 19:27:03 +0200, Daniel Schierbeck <daniel.schierbeck@gmail.com> wrote:

Hugh Sasse wrote:

  # A factory method
  def create_pizza(t=[:pepperoni, :ham] named :toppings, c=[:thin] named :crust_thickness)
    imaginate(:pizza_factory).make_me(c,t) # [1]
  end
nice short vars for codeing, then # My toppings for today
  mt=[:ham, :cheese, :pineapple]
  pizza = create_pizza(mt named :toppings)

Looks interesting... I still think this is better, though

   class Pizza
     def initialize(named toppings, named crust_thickness = :thin)
       @toppings = toppings
       @crust_thickness = crust_thickness
     end
   end

   pizza = Pizza.new :crust_thickness => :really_thick,
                     :toppings => [:pepperoni, :ham]

Cheers,
Daniel

Trans wrote:

Does

    def foo(a:, b:, c:)

look any better? Not to me. To me it looks worse b/c of what :a and
a::b are.

I admit I haven't read all of the posts in the named parameter threads,
so I apologize if my question is answered there, but why does there
even need to be a new syntax for declaring methods with named
parameters at all? My first thought as to what "adding named
parameters to Ruby" means is that *any* method can be called using
named parameters or not. I.e., given a method:

def foo(a, b)
    a + b
end

It can be called in any of these ways:

foo(5, 3)
foo(a=5, b=3)
foo(b=3, a=5)

Why can't this be made to work?

How about "contains" or "includes"?

     String contains "abc"
     0..10 contains 5
     1,2,3,4 contains 3
     /^[a-z]*$/ includes "apple"

It would be nice if Array#=== was aliased to Array#include? So that

     somearray === someval

would check for membership. You can "cheat" a bit with the case
statement as follows:

     a = [1,2,3,4]
     b = 3

     case b
     when *a
       puts "match"
     else
       puts "no match"
     end

This works with any object that responds to to_a but of course
requires that an array be constructed instead of a more efficient
lookup into the object that could be done via a
customized === method.

See my recent posting about this (ruby-talk:162999)

···

On Oct 28, 2005, at 1:07 PM, Trans wrote:

Case in point, what's the english equiv of #===. I'd really like to
have one.

Nikolai Weibull wrote:

Joe Van Dyk wrote:

No, I do not think Ruby should stagnate and be dead. If 1.8.3 were
the last version, it would not stagnate and be dead, because people
*use* it and do things with it. The fact that, for me, that counts
as non-stagnation does perhaps mean that I am quite conservative
about language change. I don't think the language needs to change,
unless something is truly broken or missing.

I love the current Ruby syntax.

If 2.0 just contained a faster Ruby, and kept the same syntax, I'd be
overjoyed.

I agree. If all Ruby 2.0 brought was a VM I’d be happy. That, and
M17N...and perhaps keyword arguments ;-D,
        nikolai

And I'd be happy with just native threads. Nothing else.

I find it interesting that before 1.8 was released, I was frequently
installing the latest 1.7.x because it had some new feature I needed. I
kept that up for a while with 1.9.x just out of habit, but didn't really
need anything that was in 1.9 but not 1.8. I'm very happy with 1.8.2, in
fact.

···

On 10/28/05, David A. Black <dblack@wobblini.net> wrote:

--
      vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Trans ha scritto:

Daniel Schierbeck wrote:

I agree with you that many suggestions have arisen, but many of them are
simply a way to think outside the box (I hate myself for using that
phrase, but I can't think of anything better.)

Ruby the Can-Do langauge :slight_smile:

I think one of the many great things about Ruby is that each new
addition is carefully considered; does it correspond to the Ruby Way? It
it clear to me that `collection.every.method' does not. Neither do I
think the `->' lambda syntax does.

The { |x| ... } syntax never turned me on about Ruby. In fact, my
first thought what why not do(x) ... end. But it was the *utility* of
blocks that made the difference.

I agree with David in the general points, but for what is worth, I agree with TRANS on this, I always thought {|x|...} was unrubyish, even when I did'nt had a grasp of what rubyish could mean (and probably I still don't)

Nikolai Weibull ha scritto:

I love the current Ruby syntax.

If 2.0 just contained a faster Ruby, and kept the same syntax, I'd be
overjoyed.

I agree. If all Ruby 2.0 brought was a VM I’d be happy. That, and
M17N...and perhaps keyword arguments ;-D,
        nikolai

+1 (ok, I still would like multi methods, but nobody loves them..)

If you are so bold, I have to chime in again to say that

  ary.sort_by :meth

reads a lot better than

  ary.sort_by.meth

because we don't do method chaining here.

Sorry, could not resist. :wink:

best regards,

Brian

···

On 29/10/05, Trans <transfire@gmail.com> wrote:

Martin DeMello wrote:
> David A. Black <dblack@wobblini.net> wrote:
> >
> > I think what's happening is that people who've used Ruby for a while
> > get used to it, and then they sort of shift their readability
> > threshold. In other words, if you've seen this:
> >
> > a.map {|b| b.meth }
> >
> > for several years, then even though it looked beautiful and concise
> > and transparent to you at first, it will start to look verbose and
> > syntactically inefficient. So then you might want to have:
>
> I usually come around to agreeing with you that so-and-so change adds
> more line noise than is worth it, but this particular one I've disliked
> right from the beginning. It's not just the visual clutter, it's the
> conceptual overhead of introducing a new variable merely because ruby
> has to attach a method to something. Note the progression from
>
> ary.sort {|a,b| a.meth <=> b.meth}
> ary.sort_by {|a| a.meth}
> ary.sort_by :meth

Shall I be so bold:

  ary.sort_by.meth

:wink:

T.

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/

Hehehe, I'm just saying that I think these discussions get out of hand
occasionally.

I do take part in some Ruby Quizzes which I find both fun and useful.
The recent thread about finding non-unique array elements got pretty
long, but in the end we all learned quite a bit. Work and play can
sometimes be combined.

Ryan

···

On 10/29/05, Trans <transfire@gmail.com> wrote:

Ryan,

All work and no play? :frowning:

Daniel Schierbeck wrote:

Trans wrote:

Case in point, what's the english equiv of #===. I'd really like to
have one.

"kind of equal to"? :slight_smile:

"matches" ? or "case-matches", to be explicit?

···

--
      vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Selon Karl von Laudermann :

I admit I haven't read all of the posts in the named parameter threads,
so I apologize if my question is answered there, but why does there
even need to be a new syntax for declaring methods with named
parameters at all? My first thought as to what "adding named
parameters to Ruby" means is that *any* method can be called using
named parameters or not. I.e., given a method:

def foo(a, b)
    a + b
end

It can be called in any of these ways:

foo(5, 3)
foo(a=5, b=3)
foo(b=3, a=5)

Why can't this be made to work?

Because "a=5" is an expression that returns a value, and is thus allowed as an argument. That would create an ambiguity between "a=5" as an expression whose return value is used as argument and "a=5" as a named argument receiving a value.

Anyway, quite a few people, including myself, don't like the idea of all arguments being optionally named arguments. It obliges method arguments to be part of the method interface, and that should only happen *when the developer explicitly wants it that way.*

I know it's a feature of Python, and maybe it hasn't brought anything bad to it. However, it's one of the reasons why I quit learning the language. It wasn't the only syntax feature I disliked, but it didn't balance things out either.

···

--
Christophe Grandsire.

http://rainbow.conlang.free.fr

You need a straight mind to invent a twisted conlang.

Pete wrote:

   pizza = Pizza.new :crust_thickness => :really_thick,
                     :toppings => [:pepperoni, :ham]

looks like a hash, if you ask me...

so what the extra keyword for ??

In my example, the value :really_thick will be assigned to the method's local variable `crust_thickness', and `[:pepperoni, :ham]' to `toppings'. Otherwise, you would have to do the following:

   def initialize(opts)
     opts[:crust_thickness] ||= :thin
     @toppings = opts[:toppings]
     @crust_thickness = opts[:crust_thickness]
   end

Which of course would be even more confusing if there were a great many keywords.

Brian Schröder wrote:

If you are so bold, I have to chime in again to say that

  ary.sort_by :meth

reads a lot better than

  ary.sort_by.meth

because we don't do method chaining here.

Sorry, could not resist. :wink:

Ahhhhh... but can you do:

   ary.sort_by.meth(foo, bar, wack!)

T.

Ryan,

All work and no play? :frowning:

Hehehe, I'm just saying that I think these discussions get out of hand
occasionally.

I think this is nothing to worry about. After all, I'm a big fan of democracy and still think it's better than other forms of government (please don't take the discussion down *that* road too far). But the main point here is that it's everybody's own decision whether he / she participates in these threads. With a little experience you can easily detect those threads and ignore them if you feel like it. And since you're using gmail you don't have to worry about space and or bandwidth either, do you? :slight_smile:

I do take part in some Ruby Quizzes which I find both fun and useful.
The recent thread about finding non-unique array elements got pretty
long, but in the end we all learned quite a bit. Work and play can
sometimes be combined.

Definitely.

To sum up: I'm totally with David and I think we should take his statement for what it is: a warning notice, a reminder to maybe more often try to keep some focus but not more - especially not any form of censorship.

Kind regards

    robert

···

Ryan Leavengood <leavengood@gmail.com> wrote:

On 10/29/05, Trans <transfire@gmail.com> wrote:

And what does that mean and how often do I need it?

regards,

Brian

···

On 29/10/05, Trans <transfire@gmail.com> wrote:

Brian Schröder wrote:
> If you are so bold, I have to chime in again to say that
>
> ary.sort_by :meth
>
> reads a lot better than
>
> ary.sort_by.meth
>
> because we don't do method chaining here.
>
> Sorry, could not resist. :wink:

Ahhhhh... but can you do:

   ary.sort_by.meth(foo, bar, wack!)

T.

--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/

Hi --

···

On Sun, 30 Oct 2005, Trans wrote:

Brian Schröder wrote:

If you are so bold, I have to chime in again to say that

  ary.sort_by :meth

reads a lot better than

  ary.sort_by.meth

because we don't do method chaining here.

Sorry, could not resist. :wink:

Ahhhhh... but can you do:

  ary.sort_by.meth(foo, bar, wack!)

Which would mean what?

David

--
David A. Black
dblack@wobblini.net

So, what we really need is the implicit block variable, because it can do all that :wink:

ary.sort_by { it.meth }

ary.sort_by { it.meth(foo, bar, wack!) }

and even:

ary.sort_by { some_hash[it] }

Dominik

···

On Sat, 29 Oct 2005 17:52:05 +0200, Trans <transfire@gmail.com> wrote:

Brian Schröder wrote:

If you are so bold, I have to chime in again to say that

  ary.sort_by :meth

reads a lot better than

  ary.sort_by.meth

because we don't do method chaining here.

Sorry, could not resist. :wink:

Ahhhhh... but can you do:

   ary.sort_by.meth(foo, bar, wack!)

I think it'd rather be

ary.sort_by(:foo, :bar, :wack!)

This is definitely superior to chaining methods. For one, because chaining causes the wrong perception that the chain is executed once but in fact a proxy object is created behind the scenes that applies the rest of the chain to every instance. And also the proxy object might be slower than the direct execution of the chain. Just because it's possible it doesn't mean it's better or more readable. My 0.02 EUR...

Kind regards

    robert

···

Trans <transfire@gmail.com> wrote:

Brian Schröder wrote:

If you are so bold, I have to chime in again to say that

  ary.sort_by :meth

reads a lot better than

  ary.sort_by.meth

because we don't do method chaining here.

Sorry, could not resist. :wink:

Ahhhhh... but can you do:

   ary.sort_by.meth(foo, bar, wack!)