What style should I chose?if (this_variable) {
do.this();
}
orif (this_variable == true) {
do.this();
}
first doesn't use redundant code but the second one looks easier to read. What style do you chose and why?
>>56061982if ( this_variable && true)
>>56061982
I use "== true" on variables, and the first for functions.
>>56061996
this
>>56061982
>first doesn't use redundant code but the second one looks easier to read. What style do you chose and why?
you answered yourself
>second one looks easier to read
second
>>56061982
The first is the correct way. The second way is just for people who are learning. The suggestion listing both is redundant
>>56061982
>second one looks easier to read
Maybe you're using shitty variable naming?if (hasExpired) {
doStuff();
}
is easier to read thanif (hasExpired == true) {
doStuff();
}
>>56061982if ( ((char)this_variable != 0) == true )
>>56061996
Won't true always be true though?
>>56062063
Not if you code in PHP
>>56061982this_variable ? do.this();
>>56062092
_self_.kill();
>>56061982
People reading the code should be aware of the type of your variable, and since it's a boolean, it doesn't really even make sense to compare it to true.
Also this helps >>56062042
>>56062042
This man knows what's up. Good variable/method naming is 90% of what makes your code readable.
>>56061982
I'd always go with the first option, though any compiler that optimizes at all would treat both the same.
However, if the first style looks unclear you probably have a weird name. Booleans should be stuff like 'allowed' 'enabled' 'possible' anyways and "if (enabled)" shouldn't look weird.
if( this_variable == true && this_variable != false && !this_variable == true && this_variable ) {
do.this();
}
>>56061982for(; this_variable; )
{
// ...
break;
}
switch(this_variable) {
true:
do_stuff();
}
Default state should be false.
Here is some exampleswhile ( !complete )
if( !out_of_range )
if( !no_errors )
>>56061982
second obviously
everyone saying otherwise is a fucking troll
>>56062305
>second
I meant first
fuck up that post really good
>>56061982if (this_variable && this_variable == true)
That way people who write both types of code understand what you meant
>>56061982
I'd do second. I agree that while the part is redundant, the second makes it very apparent what it is and any pajeet will understand it.
A code monkey writes code that works. A good programmer can write code that anybody can understand.
It's why brackets are such a hot topic.
>>56061982
!(this.variable != !false)&&(
do.this();
)
>>56061982
Why stop at the second option?if ((this_variable == true) == true)
if variable:
print('Hello')
vsif variable is not None:
print('Hello')
Code is meant to be human readable, so second one is better
>>56062435
(!(!(if ((this_variable != !!false&&(return !false)) != !true)) ? :'')?return !eval(!true):return false)&&(do.this();)
>>56061982(if this-variable (this do))
>>56061982
It's entirely dependent on how you name this_variable. If you have the name of your variables of the boolean type start with "is", like isOn or isValid, you should go with the first style because code is kept non-redundant with very little impact to readability.
>>56061996
This is the stupidest I have ever seen.
Whats the reason being redundant with your code?
>>56062174
false == true?
>>56062174
You couldn't even get your meme right.
>>56062656if(this_variable.ToString().ToLower().BeginsWith("true"))
{
do.this();
}
else if(this_variable.ToString().ToLower().BeginsWith("false")
{
do.this();
}
>>56062703
》 still performs same method.
>>56061982
If the variable is properly named, first.
IF THIS_VARIABLE
PERFORM DOTHIS
ELSE
IF NOT THIS_VARIABLE
PERFORM DOTHAT
END-IF
END-IF.
Which language pussies?
>>56062450
1st checks boolean value of var so not only None will prevent the printing but also 0, [], (,), etc.
let a = '';
(Math.random() > 0.5)&&(a='!')
if (eval(a + 'this.variable')){
do.this();
}
>>56061982lw $t0, this_variable
beq $t0, 1, do_this
>>56062786
Applescript?
>>56062786
I didn't realize metalheads went and made their own screaming language.
if (variable != 0x0) {
do shit
}
The second one my byutt
>>56062876
>>56062900
No it's COBOL.
This is literally how I program day in day out.
>>56061982
Honestly whichever one you prefer.
If you are more comfortable glancing at the first one and knowing it means it's true, use it. Same goes for the second.
>>56062284
Clean Code tends to disagree with you.
if (var){
do niggerdicks
}
if tab tab
for tab tab
dont forget your shortcuts up
>>56062400
>>56062475!!!(!!!this_variable != !!!(!!!this_variable != ((!!!this_variable || (!!!false != !!!true) && !!!true)))) || do.this.faggot!();