Some comments on new 1.9 features

D

Domenico De Felice

Dale said:
Sorry for the misunderstanding.

I like the "local" and "share" directives. That would make it clear.

Using too many special characters clutter the code and worsen
readability.

Yes, something like

{ |a, b|
local a
share b
a = 1
b = 2
}

would look less weird. However it has the problem that in bigger blocks
the programmer would need to read back the top of the block when he
'forgets' which attributes are local and which shared.

Anyway both solutions seem quite good to me
 
T

Trans

Domenico said:
Yes, something like

{ |a, b|
local a
share b
a = 1
b = 2
}

would look less weird. However it has the problem that in bigger blocks
the programmer would need to read back the top of the block when he
'forgets' which attributes are local and which shared.

They would'nt *have* to be just at the top. You could even do it
conditionally, although usage is subtle:

x = false

a = 1
b = 2
lam1 = lambda { |a, b|
a = 2
b = 4
if x
share b
end
}
lam2 = lambda { b + 1}

lam1.call
lam2.call #=> 3

x = true

lam1.call
lam2.call #=> 5

Closure Magic, yes?

T.
 
D

Domenico De Felice

Trans wrote:
[CUT]
They would'nt *have* to be just at the top. You could even do it
conditionally, although usage is subtle:
[CUT]
lam1 = lambda { |a, b|
a = 2
b = 4
if x
share b
end
}
[CUT]

Yeah.. share and local directives could be used like any other
command.. this usage is nice. It wouldn't be possible using the special
character (at least not without doing weird things). However variables
scoping, when statically defined, will still be less intuitive than
using special char.
 
A

Austin Ziegler

Nikolai Weibull wrote:
[CUT]
The funny thing about this example is that the whole point of having
";;" be "end" is that you could write

class Foo
def foo; "foo" ;;
end
Why don't use just : for single statement methods?

class Foo
def foo: "foo"
end

or in this case

class Foo:
def foo: "foo"

It sounds more expressive than do .. ;;

...

It sounds too much like Python. Python's syntax is one of the reasons
I don't use Python.

-austin
 
N

Nikolai Weibull

Austin said:
It sounds too much like Python. Python's syntax is one of the reasons
I don't use Python.

Well, the idea was to give everyone the choice of what they wanted to
use, delimited blocks, or indentation blocks. The only issue with this
is that it adds complexity and one=E2=80=99d have to be able to stand rea=
ding
both ways of writing code. I read somewhere that the biggest problem
with C is that it doesn=E2=80=99t restrict the syntax enough:

if (<test>)
<statement a>
<statement b>

It=E2=80=99s an accident waiting to happen. And while having an expressi=
ve
syntax is sweet and all, it can cause problems that are hard to spot.
I=E2=80=99m certainly not in the =E2=80=9CThere=E2=80=99s Only One Way To=
Write It=E2=80=9D camp, but
there is some merit to having a simple, unambiguous syntax.

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

gabriele renzi

David A. Black ha scritto:
As a pointless no-op, it's great :) Is it really being considered as
a synonym for 'end'? I don't understand that at all.

For what I understand: not it was a joke, mostly like GOTO in yarv (hey,
that took me weeks to understand it :)
 
E

Eric Hodel

an people who don't like to move their fingers off of the

a s d f j k l ;

Your keyboard is broken, end is on the center row:

` 1 2 3 4 5 6 7 8 9 0 [ ]
' , . p y f g c r l / = \
a o e u i d h t n s -
; q j k x b m w v z
 
D

Domenico De Felice

Austin said:
..

It sounds too much like Python. Python's syntax is one of the reasons
I don't use Python.

I didn't mean a indentation-block as in Python, but just to use a colon
with one-statement blocks. Multi-statements blocks would look the same.

class Foo
def foo
a = "foo"
a
end
def bar: "bar"
end

The indentation of the statement following the colon would be ignored.
It looks prettier than the double semicolon to me.
With multilines blocks I can't see any reason to change the do .. end
syntax.
 
K

Kevin Brown

On Saturday 05 November 2005 07:45, Christian Neukirchen wrote:
*snip*
and one=E2=80=99d have to be able to stand reading both ways of writing c=
ode.
*snip*

And learn both. Yuck. That's the problem.
 
T

Trans

Matz has repeatedly said Ruby will not have indent significant blocks.
So can we pudder back to the original example?

10.times: |x|
x
;;

But now someone has said ';;' is a just a joke feature by matz? Is that
true?

T.
 
G

Gyoung-Yoon Noh

Matz has repeatedly said Ruby will not have indent significant blocks.
So can we pudder back to the original example?

10.times: |x|
x
;;

But now someone has said ';;' is a just a joke feature by matz? Is that
true?

T.

IIRC, ';;' was stolen from Qu language[1], which Matz also mentioned
with homonym 'qoo', the famous beverage/character.
I don't know why Matz mentioned those simultaneously, but
I can guess as it's just funny, aren't you? ;-)


[1]: http://centrin.net.id/~marc/example.html
 
A

Austin Ziegler

Well, the idea was to give everyone the choice of what they wanted to
use, delimited blocks, or indentation blocks.

IMO, this is not a good idea. Choose one and stick with it. Also IMO,
Ruby came down on the right side of the debate -- indentation blocks
are excessively fragile.

-austin
 
A

Austin Ziegler

I didn't mean a indentation-block as in Python, but just to use a colon
with one-statement blocks. Multi-statements blocks would look the same.

class Foo
def foo
a =3D "foo"
a
end
def bar: "bar"
end

The indentation of the statement following the colon would be ignored.
It looks prettier than the double semicolon to me.
With multilines blocks I can't see any reason to change the do .. end
syntax.

Ruby permits multiple statements on a single line. Your proposal:

def bar: "bar"

looks unbalanced (because, in fact, it is). It gets worse if you do:

def bar: foo; "bar"

Sorry, but I think that this -- and ;; -- are both bad ideas that
should be dropped.

-austin
 
N

Nikolai Weibull

Austin said:
On 11/4/05, Nikolai Weibull
IMO, this is not a good idea. Choose one and stick with it. Also IMO,
Ruby came down on the right side of the debate -- indentation blocks
are excessively fragile.

Thanks for repeating what I said in the rest of my response, which you
have elided here.

nikolai
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top