[MacRuby-devel] Weird behaviour for a weird line of code

Jeff Cohen cohen.jeff at gmail.com
Tue Nov 16 14:55:22 PST 2010


On Tue, Nov 16, 2010 at 4:14 PM, Eric Christopherson <
echristopherson at gmail.com> wrote:

> On Mon, Nov 15, 2010 at 3:50 PM, Ryan Davis <ryand-ruby at zenspider.com>
> wrote:
> > First off, I hate this style of coding. If you didn't assign in a
> conditional you'd avoid all of this crap to begin with. Assigning in
> conditionals is just a sloppy and error prone way of coding and you should
> avoid it. This has been a known anti-pattern in any algol-esque language
> since at least the 80s.
>
> I'm not sure I understand what you mean. Are you saying it's bad to do
> the *first* assignment to a variable inside a conditional? Or it's bad
> to assign inside a conditional in any case?


It's bad to assign inside a condition in any case.


> I can understand the
> first, but I'm not sure how you would work around the second, unless
> you used a more functional style like
>
> x = (n > 2 ? true : false)
>
> or
>
> x = (if n > 2; true; else false; end)
>

Um... just do:

x = n > 2


Jeff

purpleworkshops.com

_______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20101116/ea1afce2/attachment.html>


More information about the MacRuby-devel mailing list