Interesting boolean technique
-
if (e.Message.StartsWith("Case we don't care about"))
{// easier to read than sticking a ! in the conditional
}
else
{
errorToDisplay += "\n" + e.Message;
}8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
Dan Neely wrote:
8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch.
Well, in Ruby, you could write:
unless (e.Message.StartsWith(.....
which I find even more baffling linguistically. I always have to mentally change that to "if not..." Or worse (because the conditional comes at the end, and in one case I never saw the conditional because it was off-screen on a very long line), but better linguistically:errorToDisplay += "\n" + e.Message unless e.Message.StartsWith("Case we don't care about")
Why do I bring this up? Because idiomitic Ruby frowns on negative conditions, like "if !". Personally, there is a lot of idiomatic Ruby that I refuse to use because it just seems idiotic, not idiomatic. Marc
Latest Article - APOD Scraper
-
Dan Neely wrote:
8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch.
Well, in Ruby, you could write:
unless (e.Message.StartsWith(.....
which I find even more baffling linguistically. I always have to mentally change that to "if not..." Or worse (because the conditional comes at the end, and in one case I never saw the conditional because it was off-screen on a very long line), but better linguistically:errorToDisplay += "\n" + e.Message unless e.Message.StartsWith("Case we don't care about")
Why do I bring this up? Because idiomitic Ruby frowns on negative conditions, like "if !". Personally, there is a lot of idiomatic Ruby that I refuse to use because it just seems idiotic, not idiomatic. Marc
Latest Article - APOD Scraper
I'm glad none of the Ruby on the project I'm working on uses that wtftern... X|
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
-
Dan Neely wrote:
8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch.
Well, in Ruby, you could write:
unless (e.Message.StartsWith(.....
which I find even more baffling linguistically. I always have to mentally change that to "if not..." Or worse (because the conditional comes at the end, and in one case I never saw the conditional because it was off-screen on a very long line), but better linguistically:errorToDisplay += "\n" + e.Message unless e.Message.StartsWith("Case we don't care about")
Why do I bring this up? Because idiomitic Ruby frowns on negative conditions, like "if !". Personally, there is a lot of idiomatic Ruby that I refuse to use because it just seems idiotic, not idiomatic. Marc
Latest Article - APOD Scraper
Jade also supports 'unless'. e.g. (example from my article Feeling Jaded with Jade? Don't Be![^])
- var bob = 'woman'
unless bob == 'man'
p Bob is a not man!would output
<p>Bob is not a man!</p>
Couple of times, I have confused myself trying to unwind what I wrote. -
if (e.Message.StartsWith("Case we don't care about"))
{// easier to read than sticking a ! in the conditional
}
else
{
errorToDisplay += "\n" + e.Message;
}8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
-
if (e.Message.StartsWith("Case we don't care about"))
{// easier to read than sticking a ! in the conditional
}
else
{
errorToDisplay += "\n" + e.Message;
}8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
-
if (e.Message.StartsWith("Case we don't care about"))
{// easier to read than sticking a ! in the conditional
}
else
{
errorToDisplay += "\n" + e.Message;
}8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
I think BASICplus has/had
unless
(and maybeuntil
), but I doubt it was used much. In my opinion, one of the shortcomings of BASIC, and its progeny, is it's plethora of keywords and built-in functions. C et al do very well with far fewer. Better to learn to do more with less.# define unless(x) if(!(x))
:-D Oh, what did I step in...? I pulled out my BASICplus book. Modified IF : <statement> IF <condition> UNLESS : <statement> UNLESS <condition> Implied FOR Loop : <statement> FOR <variable> = <starting value> TO <ending value> [ STEP <increment> ] FOR ... UNTIL and FOR ... WHILE : FOR <variable> = <starting value> TO <ending value> [ STEP <increment> ] WHILE | UNTIL <condition>You'll never get very far if all you do is follow instructions.
-
if (e.Message.StartsWith("Case we don't care about"))
{// easier to read than sticking a ! in the conditional
}
else
{
errorToDisplay += "\n" + e.Message;
}8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
Well, you could re-factor it to
if (CaseWeCareAbout(e.Message))
{
errorToDisplay += "\n" + e.Message;
}
...
private bool CaseWeCareAbout(string input)
{
bool weDontCare = input. StartsWith("Case we don't care about");
bool weCare = !weDontCare;
return weCare;
}Some time later, you'll think: wtf did I need so many lines and an extra function for such a simple task. Every beginner can understand that, but I ought to be capable to understand far more complicated things. What will others think of me writing such code? deflinek's message is quite correct.
-
Dan Neely wrote:
8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch.
Well, in Ruby, you could write:
unless (e.Message.StartsWith(.....
which I find even more baffling linguistically. I always have to mentally change that to "if not..." Or worse (because the conditional comes at the end, and in one case I never saw the conditional because it was off-screen on a very long line), but better linguistically:errorToDisplay += "\n" + e.Message unless e.Message.StartsWith("Case we don't care about")
Why do I bring this up? Because idiomitic Ruby frowns on negative conditions, like "if !". Personally, there is a lot of idiomatic Ruby that I refuse to use because it just seems idiotic, not idiomatic. Marc
Latest Article - APOD Scraper
-
Well, you could re-factor it to
if (CaseWeCareAbout(e.Message))
{
errorToDisplay += "\n" + e.Message;
}
...
private bool CaseWeCareAbout(string input)
{
bool weDontCare = input. StartsWith("Case we don't care about");
bool weCare = !weDontCare;
return weCare;
}Some time later, you'll think: wtf did I need so many lines and an extra function for such a simple task. Every beginner can understand that, but I ought to be capable to understand far more complicated things. What will others think of me writing such code? deflinek's message is quite correct.
Nah, that still uses "!" which is "hard to read". Try this:
private bool CaseWeCareAbout(string input)
{
bool weDontCare = input. StartsWith("Case we don't care about");
bool weCare = weDontCare ? false : true;
return weCare;
}Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
Nah, that still uses "!" which is "hard to read". Try this:
private bool CaseWeCareAbout(string input)
{
bool weDontCare = input. StartsWith("Case we don't care about");
bool weCare = weDontCare ? false : true;
return weCare;
}Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
If ! is hard to read then make it more obvious
private bool CaseWeCareAbout(string input)
{
return !!!!!!!!!!!input.StartsWith("Case we don't care about");
} -
If ! is hard to read then make it more obvious
private bool CaseWeCareAbout(string input)
{
return !!!!!!!!!!!input.StartsWith("Case we don't care about");
}Of course, a normal exclamation mark ought to be "closed" with an inverted exclamation mark, i.e.
return !!!!!!!!!!!input.StartsWith("Case we don't care about")¡¡¡¡¡¡¡¡¡¡¡;
-
if (e.Message.StartsWith("Case we don't care about"))
{// easier to read than sticking a ! in the conditional
}
else
{
errorToDisplay += "\n" + e.Message;
}8 years ago I apparently thought I was being clever by having an empty then block and only having actual code in the else branch. :wtf:
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt
If you find it nice! The compiler understood either way, so do human! ;P
My programming get away... The Blog... DirectX for WinRT/C# since 2013! Taking over the world since 1371!