"Readability" inflation

N

Nikolai Weibull

I love the current Ruby syntax.
=20
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=E2=80=99d be happy. That, a=
nd
M17N...and perhaps keyword arguments ;-D,
nikolai

--=20
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}
 
G

gwtmp01

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

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)
 
J

Joel VanderWerf

Nikolai said:
Joe Van Dyk wrote:
=20
=20
=20
=20
I agree. If all Ruby 2.0 brought was a VM I=E2=80=99d be happy. That,= and
M17N...and perhaps keyword arguments ;-D,
nikolai
=20

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.

--=20
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
 
D

Daniel Schierbeck

Pete said:
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.
 
G

gabriele renzi

Trans ha scritto:
Daniel Schierbeck wrote:




Ruby the Can-Do langauge :)




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)
 
G

gabriele renzi

Nikolai Weibull ha scritto:
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..)
 
R

Robert Klemme

Ron M said:
For us people with less broad exposure to esoteric languages, this:
c.map{|b| b.meth}
really isn't as intuitive as you'd think.

If I were to ask people around the office, I'd expect guesses
like these for "c.map{|b| b.meth}":

? It defines a function with the funny name "c.map" that takes
no arguments; that pipes the variable b it's input to b and
then to b.meth (like MSFT's Monad shell's pipe operator)?

? It uses "c" to return a hashtable ("map" sounds like HashMap
in Java) with one element with name "b" and value "b.meth"?

? It takes the locations in the object "c" and plots
the meth labs on the google-map "b"?

Well, *did* you actually ask? What about showing your colleagues a short
Ruby program that contains this like of code and collecting their
interpretation? That would certainly be interesting to hear. IMHO context
helps a great deal in understanding previously unknown concepts.
In defense of "{|x| ...}", I really like it over C-style for
loops. But readability for new users certainly isn't one of
it's strengths.



Consider Microsoft's Monad's

get-childitem | sort-object extension | foreach { $_.filename}

vs Ruby's

get-childitem.sort_by{|child| child.extension}.map{|child|
child.filename}
Msh makes Ruby's 4-time repetition of "child" look quite tedious,
without adding any readability that I can see over the Microsoft
version.

Well, it depends: your line full of pipe symbols looks like a line from a
bourne shell script to me... :) I guess you really need some kind of basic
knowledge in either case.
I'd reiterate that I think it's the opposite. Newbies without
the theoretical CS backgrounds are complaining about the parts
that they find confusing or tedious.

It interesting to see how people make different observations: to me it looks
as if I more often read "wow, Ruby is so cool and I can even read it
although I'm a newby".
The one really great part about Ruby, though; is that almost any
time someone complains, someone else posts some magical addition
to some module that gives the complainer almost exactly what he
wanted -- so I'd tend to agree the language shouldn't need many
of these changes.
Agreed.

But I think what's driving the increased requests are mostly
things that people find hard to read, rather than clean
things that people are getting bored with.

Maybe it's not exactly boredom but the human drive to constantly improve
things which is especially strong in engineers and similar folks. While
this force is often good there are many places where too much degrades
things (I'm thinking of the over engineered cars of some German
manufacturers...). That hard part is to identify the optimum and stick with
that. Also, the optimum may change over time, as requirements change.

A general advantage of conservatism is that it doesn't create too many
different variants for the same or similar concept thus limiting the overall
size of the playing field. And this in turn helps people a lot to get
started. Just compare learning curves for natural languages with comlex
rules and syntax with those of languages with only few principles applied
consequently.

Kind regards

robert
 
M

Martin DeMello

David A. Black said:
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

The |a| adds absolutely nothing to the readability of the code. It's a
case of cluttering the simple case in order to support the complex one,
and ruby usually manages to do a pretty good job of keeping machinery
out of your way until you need it.

martin
 
T

Trans

Martin said:
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

;)

T.
 
B

Brian Schröder

Shall I be so bold:

ary.sort_by.meth

;)

T.

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. ;-)

best regards,

Brian
 
T

Trans

Brian said:
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. ;-)

Ahhhhh... but can you do:

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

T.
 
D

David A. Black

--8323328-1897556945-1130601894=:29661
Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-1897556945-1130601894=:29661"

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-1897556945-1130601894=:29661
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

Ahhhhh... but can you do:

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

Which would mean what?


David

--=20
David A. Black
(e-mail address removed)
--8323328-1897556945-1130601894=:29661--
--8323328-1897556945-1130601894=:29661--
 
S

Stefan Lang

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

Perhaps he means something like:

% cat sort_by.rb
module Enumerable
alias _core_sort_by sort_by
def sort_by(*args, &block)
if args.empty?
_core_sort_by(&block)
else
_core_sort_by { |a| a.__send__(*args, &block) }
end
end
end

if $0 =3D=3D __FILE__
class Factor
attr_reader :number
def initialize(number)
@number =3D number
end
def apply_to(other_number)
@number * other_number
end
end
list =3D [Factor.new(-2), Factor.new(3)]
p list.sort_by:)number)
p list.sort_by:)apply_to, -1)
end
% ruby sort_by.rb
[#<Factor:0x401c0520 @number=3D-2>, #<Factor:0x401c050c @number=3D3>]
[#<Factor:0x401c050c @number=3D3>, #<Factor:0x401c0520 @number=3D-2>]

=2D-=20
Stefan
 
D

Dominik Bathon

Ahhhhh... but can you do:

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

So, what we really need is the implicit block variable, because it can do=
=20
all that ;-)

ary.sort_by { it.meth }

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

and even:

ary.sort_by { some_hash[it] }


Dominik
 
B

Brian Schröder

Ahhhhh... but can you do:

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

So, what we really need is the implicit block variable, because it can do
all that ;-)

ary.sort_by { it.meth }

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

and even:

ary.sort_by { some_hash[it] }


Dominik

What is so bad about

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

Then you can even make your sourcecode readable by putting information
into the it

playlist.sort_by { | track | track.meth(foo, bar, wack!) }
instead of
playlist.sort_by { it.meth(foo, bar, wack!) }

where it is unclear what the it is.

regards,

Brian
 
D

David A. Black

--8323328-789305799-1130609703=:27369
Content-Type: MULTIPART/MIXED; BOUNDARY="8323328-789305799-1130609703=:27369"

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

--8323328-789305799-1130609703=:27369
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

Hi --

Brian Schr=F6der 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. ;-)

Ahhhhh... but can you do:

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

So, what we really need is the implicit block variable, because it can d= o
all that ;-)

ary.sort_by { it.meth }

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

and even:

ary.sort_by { some_hash[it] }


Dominik

What is so bad about

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

Then you can even make your sourcecode readable by putting information
into the it

playlist.sort_by { | track | track.meth(foo, bar, wack!) }
instead of
playlist.sort_by { it.meth(foo, bar, wack!) }

where it is unclear what the it is.

I agree; I think a loop/block variable with a real name is a step
forward from one without one. And yes, you could do:

track =3D it

but I'd rather not have the problem to solve in the first place. I
think it's been solved already by Matz :)


David

--=20
David A. Black
(e-mail address removed)
--8323328-789305799-1130609703=:27369--
--8323328-789305799-1130609703=:27369--
 
D

Daniel Schierbeck

Brian said:
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. ;-)

Ahhhhh... but can you do:

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

So, what we really need is the implicit block variable, because it can do
all that ;-)

ary.sort_by { it.meth }

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

and even:

ary.sort_by { some_hash[it] }


Dominik


What is so bad about

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

Then you can even make your sourcecode readable by putting information
into the it

playlist.sort_by { | track | track.meth(foo, bar, wack!) }
instead of
playlist.sort_by { it.meth(foo, bar, wack!) }

where it is unclear what the it is.

regards,

Brian

I agree. `it' would seem to refer to the playlist itself, not the
playlist item. This would be good too:

playlist.sort_by :track_length


Cheers,
Daniel
 
T

Trans

Dominik said:
So, what we really need is the implicit block variable, because it can do
all that ;-)

ary.sort_by { it.meth }

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

and even:

ary.sort_by { some_hash[it] }

Uh oh...

ary.whatever_by { |it1, it2| ... }

Now we're one step away from the from "ducking" it all:

ary.whatever_by { %1.foo ... %2.bar }

T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top