Robert Dober
7/14/2007 12:17:00 PM
On 7/13/07, Robert Klemme <shortcutter@googlemail.com> wrote:
> 2007/7/13, Chad Perrin <perrin@apotheon.com>:
> > On Fri, Jul 13, 2007 at 03:24:30PM +0900, Robert Klemme wrote:
> > > 2007/7/13, Jeffrey Bowen <ja_bowen@yahoo.com>:
> > > >Of course the code below will not work because gets is
> > > >adding /n to the entry. I know that chomp will remove
> > > >the /n but is there away to cut the /n without
> > > >reassigning test1 to another variable IE test2 =
> > > >test1.comp
> > >
> > > Use chomp!
> > >
> > > >print "test1 "
> > > >test1 = gets
> > > >puts test1.class
> > > >if test1 == "1"
> > > > puts "step 1"
> > > >else
> > > > puts "step 2"
> > > >end
> >
> > That was the first thing that occurred to me, too, but I think that Chris
> > Carter's solution is (usually) the better option. In-place modification
> > can lead to some difficult-to-track bugs when working with complex code,
> > and can also be problematic for concurrency -- so I try to stay in the
> > habit of avoiding in-place modifications.
>
> You're over cautious here. Your concerns do not apply because test1 is
> a local variable and this bit of code is far from complex. Also,
> chomp! is more efficient. If you need to make sure that an object does
> not change you can use #freeze and be sure to immediately detect bugs
> (i.e. unwanted modifications).
Robert I am a big fan of in place modification and you have already
explained the thread safety of local variables very well to me on this
list.
Furthermore all you say here is technically very sound...
... am I about to back you up on this?
Actually no, well your post is relevant and technical interesting but
I feel that Chad's approach is quite elegant.
Maybe his motivation is wrong, I do not want to make a statement about
it, but I feel that his code is cleaner, more functional oriented,
more modern in some way...
What you have said will be worth gold when we have to optimize the
code but maybe it is premature optimization right now.
Just some thoughts, after all both solution seem very reasonable to me :)
>
> Apart from that, every Array append operation is an inplace
> modification. Changing an object's state is at the core of OO
> programming - so avoiding it is not realistic.
Hmm not sure it might not be possible to strive for some common goals
of pure functional and OO, but not an expert at all, just a thinker ;)
>
> If you follow your thought consequently to the end you should switch
> to a pure functional language because that is free of side effects.
Voilà, but I do not like too strict categorization.
>
> Kind regards
>
> robert
>
>
Robert
--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck