From: Aldric Giacomoni on
Rick Denatale wrote:
> Just so you know I wasn't dissing La langue belle. I try to maintain
> a basic fluency. Not sure if my French or my C is more rusty! <G>
>

Hah! No worries, I wasn't insulted.
So .. Friend++ ?
Warning: incrementing a constant!
--
Posted via http://www.ruby-forum.com/.

From: Rick DeNatale on
On Mon, Nov 9, 2009 at 2:48 PM, Aldric Giacomoni <aldric(a)trevoke.net> wrote:
> Rick Denatale wrote:
>> Just so you know I wasn't dissing La langue belle.  I try to maintain
>> a basic fluency.  Not sure if my French or my C is more rusty! <G>
>>
>
> Hah! No worries, I wasn't insulted.
> So .. Friend++ ?

Bien sur


--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

From: Joshua Ballanco on

On Nov 9, 2009, at 6:35 AM, Seebs wrote:

> On 2009-11-09, Marnen Laibow-Koser <marnen(a)marnen.org> wrote:
>> Would you? Or would you rather see
>> count = blahblahblah.count do |args|
>> lots_of_stuff
>> condition
>> end
>
> Huh! That is prettier. Didn't know it existed.
>
> But in general, basically, any place where we have a += 1, I'd prefer ++.
>
> And I am pretty sure that +=1 is occasionally useful.

...and *this* is where, in the long long history of this thread, where I finally realized the *real* issue here.

Let's take Rails... rails, activerecord, activeresource, actionpack, actionmailer, and activesupport...

106,518 lines of Ruby code

66 instances of foo += 1 (or foo += 100)

That's 0.06% of the lines of code! If you're writing Ruby code and your fraction is higher, chances are you're "doing it wrong".

Cheers,

Josh
From: t3ch.dude on
On Nov 7, 4:39 am, "David A. Black" <dbl...(a)rubypal.com> wrote:
> Hi --
>
>
>
> On Sat, 7 Nov 2009, Marnen Laibow-Koser wrote:
> > Michael W. Ryder wrote:
> > [...]
> >> .  I much prefer the
> >> simplicity of Basic and C with for loops that can go either direction.
>
> > That's because you're trying to write C in Ruby.  There are far more
> > idiomatic ways of doing things -- and they *are* clearer, at least in a
> > Ruby context.
>
> >> As far as going backwards I use it a lot to parse strings of the form
> >> "cityname ST 12345-6789" toCity,State, andZipCode fields.  I look
> >> for the first blank from the end of the string and assume everything
> >> after it is theZipCode, I then find the next two non-blank characters
> >> and assign them toState, and everything else is theCityname.
>
> > That's great in a language like C that doesn't have very good string
> > handling.  The Ruby way to do this would be
> >city,state,zip= string.split(/\s+/)
irb(main):004:0> str = "Washington Court House OH 43160"
=> "Washington Court House OH 43160"
irb(main):005:0> zip, state, city = str.reverse.split(/ /,3).map {|e|
e.reverse}
=> ["43160", "OH", "Washington Court House"]


>
> You'd need to take multi-wordcitynames into account, though. So
> maybe:
>
>    city,state,zip= /\A(.*)\s+(\S+)\s+(\S+)\Z/.match(str).captures
>
> David
>


From: Michael W. Ryder on
Joshua Ballanco wrote:
> On Nov 9, 2009, at 6:35 AM, Seebs wrote:
>
>> On 2009-11-09, Marnen Laibow-Koser <marnen(a)marnen.org> wrote:
>>> Would you? Or would you rather see
>>> count = blahblahblah.count do |args|
>>> lots_of_stuff
>>> condition
>>> end
>> Huh! That is prettier. Didn't know it existed.
>>
>> But in general, basically, any place where we have a += 1, I'd prefer ++.
>>
>> And I am pretty sure that +=1 is occasionally useful.
>
> ..and *this* is where, in the long long history of this thread, where I finally realized the *real* issue here.
>
> Let's take Rails... rails, activerecord, activeresource, actionpack, actionmailer, and activesupport...
>
> 106,518 lines of Ruby code
>
> 66 instances of foo += 1 (or foo += 100)
>
> That's 0.06% of the lines of code! If you're writing Ruby code and your fraction is higher, chances are you're "doing it wrong".
>
Or your style of programming is different than the programmer(s) in the
code you researched. As an example earlier in the thread I showed one
way to separate the city, state, and zip code from a string, at least
two other authors showed totally different methods. They all returned
the same results so which one was right? One used regular expressions
and the other used split and map. x = x + 1 returns the same result as
x += 1 but is probably easier for some people to understand quickly.

> Cheers,
>
> Josh