Do something like this?
kill_some_people unless moral_code == good
If so, then do ______.
instead of this:
kill_some_people unless moral_code == good
if moral_code == good....
That may not seem like much, but when the line goes ACROSS THE PAGE, it gets a bit ambiguous, repetitive, and also confusing as hell. I'm just looking for a way to go
DO A unless B, and if B, then do this instead.
without restating B. Ternary operators seem like they MIGHT work, but, for some reason, I don't seem to think they work for anything except assignment. Meh.
is the same as
So this:
is the same as:
Wow blizz that makes more sense...I even had troubles with the unless command. lol thnx
Let me restate,
$data_weapons[53].build_encryption_ray(743, ham, nine) + $data_weapons[oaphfoiwenbrkjbwmtgf] unless i_give_a_f***
if $data_weapons[53].build_encryption_ray(743, ham, nine) + $data_weapons[oaphfoiwenbrkjbwmtgf]
That's a bit long. It's not about if or unless, it's about, is there a way to avoid using up a WHOLE nother line, and making it look UBER confusing, just to restate the conditional?
Oh yeah. Unless/else. Der >.>. I'm just thinking about within the context of the statement modifiers.
if you make it clear the lin is unfinished like leafing an && or || or , or ( or { ect. at the end of the line then press enter and indent it will continue the lin on the next line.
i didn't really explain that will so I hope someone one else dose better or did i even answer your question?
Because indentation is used to mark where blocks start and end so the code gets readable.
@Seox: Why checking 2 times for the same condition? Use if-else/unless-else blocks.
And what you want is probably this.
if a then b
b if a
unless a then b
b unless a
I never tried the third one, BTW.
Quote
kill_some_people unless moral_code == good
If so, then do ______.
instead of this:
kill_some_people unless moral_code == good
if moral_code == good....
I'd do it this way, it's least confusing:
if moral_code == good
#blah
else
kill_some_people
end
Thank you, everyone. I guess I'm just a lazy bastard who was looking to use statement modifiers like that, when I shoulda just stopped and thought.
^_^
Not really. One fine day, you could realize s shortcut did exist and you haven't been using it.
I think you know this already, but large conditions can stored in local variables for convelience:
$data_weapons[53].build_encryption_ray(743, ham, nine) + $data_weapons[oaphfoiwenbrkjbwmtgf] unless i_give_a_f***
if $data_weapons[53].build_encryption_ray(743, ham, nine) + $data_weapons[oaphfoiwenbrkjbwmtgf]
can be:
condition = $data_weapons[53].build_encryption_ray(743, ham, nine) +
$data_weapons[oaphfoiwenbrkjbwmtgf] unless i_give_a_f***
if condition
And don't forget the ternary operator ?: It's a handy replacement for small if-else statements, and it's my personal favorite.
Syntax:
condition ? statement_if_true : statement_if_false
For example, this:
moral_code == good ? donate : kill_someone
is the same as this:
if moral_code == good
donate
else
kill_someone
end
If you really feel like using one line, you can encapsulate all the <evil> stuff and all the <good> stuff in their own methods, and have them return true or false depending on morals (in other words, the method "evil" would do evil things and return true if you are evil, and return false if not, and simiilar with the method "good"). Then you could just use
Of course, that's rather hard to read/impractical. But if you absolutely
have to have one line...
O_O
Thank you, all of you.
Yeah, I LOVE ternary operators. They also sound cool as hell.
Thank you, LongFellow ^_^
Ternary operators just mean they operate on 3 operands (binary 2, unary 1).
Quote from: Longfellow on July 06, 2009, 08:22:38 pm
If you really feel like using one line, you can encapsulate all the <evil> stuff and all the <good> stuff in their own methods, and have them return true or false depending on morals (in other words, the method "evil" would do evil things and return true if you are evil, and return false if not, and simiilar with the method "good"). Then you could just use
Of course, that's rather hard to read/impractical. But if you absolutely have to have one line...
VERY impractical. "evil" would be executed every time.
Quote from: Seox on July 06, 2009, 09:05:47 pm
Yeah, I LOVE ternary operators. They also sound cool as hell.
I prefer "C ? A : B" in short statements only.
I meant evil would be like
def evil
if @morals == :wrong
kill_people
return true
end
end
"evil" would then return nil (which acts like false when you use "if <var>") unless you are evil. It would execute, but it wouldn't do anything evil.
And lol, why didn't I think of ternary? I use it all the freaking time :P
That's a very inconsistent concept. -_- The cohersion of your methods is very bad.
Quote from: Blizzard on July 07, 2009, 09:26:37 am
That's a very inconsistent concept. -_- The cohersion of your methods is very bad.
That's why I called it impractical, lol. :P
And that's why I don't understand you going on with that idea. When I come to the conclusion that something is impractical, I stop thinking about it.
Quote from: Blizzard on July 07, 2009, 04:25:09 pm
And that's why I don't understand you going on with that idea. When I come to the conclusion that something is impractical, I stop thinking about it.
Hey Blizz. Breathing is impractical.
XD
Seriously though, at first, I really didn't think about "good coding" and "bad coding." You guys've really helped me to learn to NOT be a lazy-ass, both in and out of this thread. Thank you ^_^