Forum: Ruby 10 things to be aware of in 1.8 -> 1.9 transition

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-14 19:42
(Received via mailing list)
Hi --

I know it's not usual to announce blog posts here, but I'm going to
indulge the impulse as the content of this one is something I might
have posted here anyway:

http://dablog.rubypal.com/2009/1/14/10-things-to-b...

I'm finishing up "The Well-Grounded Rubyist" and am thinking of
writing an appendix with more or less this content, so I thought I'd
run it up the flagpole first.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2009-01-14 20:15
(Received via mailing list)
David A. Black wrote:
> writing an appendix with more or less this content, so I thought I'd
> run it up the flagpole first.
>
>
> David
>

I do appreciate it, having been slow to test on 1.9.

There is a small bug in the text though:

x = 1
{|x|  }

Maybe there should be an "x=3" in the block?
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2009-01-14 20:16
(Received via mailing list)
On Jan 14, 2009, at 12:40 PM, David A. Black wrote:

> run it up the flagpole first.
Double-check your examples in "Block variables scope."  It looks like
they may be cut off.

I also think you need to add a section on this error, which seems very
likely to be the first thing programmers encounter in the new m17n code:

   $ echo "Résumé" > utf8.rb
   $ ruby_dev utf8.rb
   utf8.rb:1: invalid multibyte char (US-ASCII)

I love the idea overall though.  Thanks for sharing!

James Edward Gray II
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-14 20:24
(Received via mailing list)
Hi --

Sigh -- I forgot to wrap some of them in <pre>.

Everyone please look at it again for those block examples :-)


David


On Thu, 15 Jan 2009, Joel VanderWerf wrote:

>> writing an appendix with more or less this content, so I thought I'd
> x = 1
> {|x|  }
>
> Maybe there should be an "x=3" in the block?
>
> --
>      vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
>

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
B57c5af36f5c1f33243dd8b2dd9043b1?d=identicon&s=25 F. Senault (Guest)
on 2009-01-14 20:35
(Received via mailing list)
Le 14 janvier 2009 à 20:14, James Gray a écrit :

> I also think you need to add a section on this error, which seems very
> likely to be the first thing programmers encounter in the new m17n code:

Oh yeah.

And this :

>> require "yaml"
=> true
>> a = "héhé"
=> "héhé"
>> b = a.to_yaml
=> "--- !binary |\naMOpaMOp\n\n"
>> c = YAML.load(b)
=> "h\xC3\xA9h\xC3\xA9"
>> c << "héhé"
Encoding::CompatibilityError: incompatible character encodings:
ASCII-8BIT and UTF-8
        from (irb):8
        from /usr/local/bin/irb:12:in `<main>'

Fred
Who is still having trouble with utf-8 in one of his rails models...
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2009-01-14 21:03
(Received via mailing list)
On Wed, Jan 14, 2009 at 7:40 PM, David A. Black <dblack@rubypal.com>
wrote:
> Hi --
>
> I know it's not usual to announce blog posts here, but I'm going to
> indulge the impulse as the content of this one is something I might
> have posted here anyway:
>
I believe this is something lots of folks want desperately, YHS
included.
So please keep the good work up.
A small comment on hash key ordering:
As you said it is insertion order, not update order, thus in the
(unlikely) case that one wants to change that, one
has to delete the key.
   h = { a: 42, b: 42 }
   h.update a: 42
   h --> { a: 42, b: 42 }
   vs.
   h.delete a:
   h.update a: 42
   h --> { b: 42, a: 42 }

It seems to be true too that the hash literal is insertion order
preserving, thus the read syntax and write
syntax for hashes seem identical :).
Can anybody confirm this please?
Cheers
R
C215c6ac79d6bc891dd6a2f4f74aff71?d=identicon&s=25 Ollivier Robert (Guest)
on 2009-01-15 11:05
(Received via mailing list)
In article <1s9tj58uadsr2.dlg@tamnavulin.lacave.local>,
F. Senault <fred@lacave.net> wrote:
>> I also think you need to add a section on this error, which seems very
>> likely to be the first thing programmers encounter in the new m17n code:
>
>Oh yeah.

I agree, everything encoding-related will bite people. This is
complicated in
1.9.
F889bf17449ffbf62345d2b2d316a937?d=identicon&s=25 Michal Suchanek (Guest)
on 2009-01-15 12:21
(Received via mailing list)
2009/1/14 James Gray <james@grayproductions.net>:
>>
>  $ echo "Résumé" > utf8.rb
>  $ ruby_dev utf8.rb
>  utf8.rb:1: invalid multibyte char (US-ASCII)
>

As a quick fix you can do

$ ruby -KU utf8.rb

but a guide summarizing the encoding features and possible problems
would be very helpful.

Thanks

Michal
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2009-01-15 14:32
Joel VanderWerf wrote:
> There is a small bug in the text though:
>
> x = 1
> {|x|  }
>
> Maybe there should be an "x=3" in the block?

No, it's correct as it is. The point is that in ruby 1.8, |x| is
assigned to each time the block is called, and if x existed before the
block, it remains after the block as the last value. This is regardless
of whether you actually use or assign to x inside the block.

$ irb
irb(main):001:0> x = 1
=> 1
irb(main):002:0> [2,3].each{|x| }
=> [2, 3]
irb(main):003:0> x
=> 3

But in ruby1.9, |x| is a local block argument, independent of any local
variable x outside the block.

$ irb19
irb(main):001:0> x = 1
=> 1
irb(main):002:0> [2,3].each{|x| }
=> [2, 3]
irb(main):003:0> x
=> 1
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2009-01-15 14:44
(Received via mailing list)
On Jan 15, 2009, at 5:18 AM, Michal Suchanek wrote:

>>> http://dablog.rubypal.com/2009/1/14/10-things-to-b...
>> very
> $ ruby -KU utf8.rb
>
> but a guide summarizing the encoding features and possible problems
> would be very helpful.

Yeah, I've been working on such a guide:

http://blog.grayproductions.net/articles/understanding_m17n

I just haven't got to the 1.9 sections yet.  I will eventually though…

James Edward Gray II
86e33dee4a89a8879a26487051c216a8?d=identicon&s=25 Michael Fellinger (Guest)
on 2009-01-15 16:43
(Received via mailing list)
On Thu, Jan 15, 2009 at 3:40 AM, David A. Black <dblack@rubypal.com>
wrote:
> run it up the flagpole first.
You might also want to mention (around the point of block-parameters
have def syntax) that procs can take a block now.
The Enumerator stuff is in 1.8.7 already, not sure if it's that
notable. Maybe some things instead about String (#each, Enumerable,
[0], ?a, ...) would be more helpful.

^ manveru
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-15 16:54
(Received via mailing list)
Hi --

On Fri, 16 Jan 2009, Michael Fellinger wrote:

>> writing an appendix with more or less this content, so I thought I'd
>> run it up the flagpole first.
>
> You might also want to mention (around the point of block-parameters
> have def syntax) that procs can take a block now.
> The Enumerator stuff is in 1.8.7 already, not sure if it's that
> notable. Maybe some things instead about String (#each, Enumerable,
> [0], ?a, ...) would be more helpful.

I'm not really dealing with 1.8.7 in my book (nor much in general).
[0] is a good idea. I do mention in my list that strings aren't
enumerable any more.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-01-15 17:30
(Received via mailing list)
> I'm not really dealing with 1.8.7 in my book (nor much in general).

The problem with that theory that certain Rails sites (I'm not naming
any
names!) run 1.8.7 on their servers, for the latest patches, but their
developers
still use 1.8.6 on their workstations, for all the mature tools...
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-01-15 17:45
(Received via mailing list)
>    h = { a: 42, b: 42 }

I thought the new label: syntax was worth a top-level citation.

That syntax sugar, together with stringy symbols and hashes in hashed
order,
produce an emergent "named argument" system that makes DSLs much easier
to
invent on the end of your method arguments.
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2009-01-15 18:06
Phlip wrote:
>>    h = { a: 42, b: 42 }
>
> I thought the new label: syntax was worth a top-level citation.

But that isn't going to break any existing code, and I believe the main
thrust of this article is changes to be wary of - although some aren't
in that category, like def foo(a,*b,c).
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 Joel VanderWerf (Guest)
on 2009-01-15 19:47
(Received via mailing list)
Brian Candler wrote:
> Joel VanderWerf wrote:
>> There is a small bug in the text though:
>>
>> x = 1
>> {|x|  }
>>
>> Maybe there should be an "x=3" in the block?
>
> No, it's correct as it is.

Well, it's correct *now*:

   x = 1
   [2,3].each {|x|  }

(it wasn't even parsing before)
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-15 20:21
(Received via mailing list)
Hi --

On Fri, 16 Jan 2009, Phlip wrote:

>>    h = { a: 42, b: 42 }
>
> I thought the new label: syntax was worth a top-level citation.

It's cool but it doesn't belong on the original list, because it's not
something that might make your existing code fail to work, which is
(mostly :-) what the list is. The mention of ordered hashes is
questionable on those grounds too in fact.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-15 20:24
(Received via mailing list)
Hi --

On Fri, 16 Jan 2009, Brian Candler wrote:

> Phlip wrote:
>>>    h = { a: 42, b: 42 }
>>
>> I thought the new label: syntax was worth a top-level citation.
>
> But that isn't going to break any existing code, and I believe the main
> thrust of this article is changes to be wary of - although some aren't
> in that category, like def foo(a,*b,c).

Yes -- that one and the ordered hash one are a bit out of step with
the overall idea of the post. I guess I just include them among the
new stuff in almost any context out of habit.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (candlerb)
on 2009-01-15 22:17
David A. Black wrote:
>> But that isn't going to break any existing code, and I believe the main
>> thrust of this article is changes to be wary of - although some aren't
>> in that category, like def foo(a,*b,c).
>
> Yes -- that one and the ordered hash one are a bit out of step with
> the overall idea of the post. I guess I just include them among the
> new stuff in almost any context out of habit.

BTW, I think the blog post should link to the presentation by David
Thomas and yourself:
http://rubyconf2008.confreaks.com/ruby-19-what-to-...

I watched this a while back and enjoyed it, but had to search hard to
find it again.
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2009-01-16 01:30
(Received via mailing list)
David A. Black wrote:

> It's cool but it doesn't belong on the original list, because it's not
> something that might make your existing code fail to work, which is
> (mostly :-) what the list is. The mention of ordered hashes is
> questionable on those grounds too in fact.

Maybe we need two lists:

  - warnings, gotchas, and incompatibilities
  - new conveniences and benefits
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-16 01:48
(Received via mailing list)
On Fri, 16 Jan 2009, Phlip wrote:

> - new conveniences and benefits
Well, my whole book is about 1.9 :-)


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2009-01-16 02:42
(Received via mailing list)
On Thu, Jan 15, 2009 at 8:19 PM, David A. Black <dblack@rubypal.com>
wrote:
> Hi --
>
> On Fri, 16 Jan 2009, Phlip wrote:
>
>>>   h = { a: 42, b: 42 }
>>
>> I thought the new label: syntax was worth a top-level citation.
>
> It's cool but it doesn't belong on the original list, because it's not
> something that might make your existing code fail to work, which is
Ah there is one tiny little thing which bite me quite hard, maybe you
wanna mention it

580/206 > ruby186 -v -e 'p [?*, ?\ ]  '
ruby 1.8.6 (2009-01-06 patchlevel 291) [i686-linux]
[42, 32]
robert@siena:~/tmp 02:40:59
581/207 > ruby187 -v -e 'p [?*, ?\ ]  '
ruby 1.8.7 (2009-01-06 patchlevel 78) [i686-linux]
[42, 32]
robert@siena:~/tmp 02:41:04
582/208 > ruby191 -v -e 'p [?*, ?\ ]  '
ruby 1.9.1 (2009-01-06 patchlevel-5000 trunk 21356) [i686-linux]
["*", " "]

R.
F53b05cdbdf561cfe141f69b421244f3?d=identicon&s=25 David A. Black (Guest)
on 2009-01-16 14:47
(Received via mailing list)
Hi --

On Fri, 16 Jan 2009, Phlip wrote:

>> I'm not really dealing with 1.8.7 in my book (nor much in general).
>
> The problem with that theory that certain Rails sites (I'm not naming any
> names!) run 1.8.7 on their servers, for the latest patches, but their
> developers still use 1.8.6 on their workstations, for all the mature tools...

I'm not directly concerned with Rails in the book (The Well-Grounded
Rubyist is descended from, but not the same as, Ruby for Rails), and I
think most people are focused on the 1.8.6-to-1.9.1 transition.


David

--
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!
This topic is locked and can not be replied to.