[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

What style should I chose? if (this_variable) { do.this();

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 49
Thread images: 3

What style should I chose?

if (this_variable) {
do.this();
}


or

if (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?
>>
>>56061982
if ( 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 than

if (hasExpired == true) {
doStuff();
}
>>
>>56061982
if ( ((char)this_variable != 0) == true )
>>
>>56061996
Won't true always be true though?
>>
File: 2016-07-24 10.15.30.png (202KB, 1079x584px) Image search: [Google]
2016-07-24 10.15.30.png
202KB, 1079x584px
>>56062063
Not if you code in PHP
>>
>>56061982
this_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();
}
>>
>>56061982
for(; this_variable; ) 
{
// ...
break;
}
>>
switch(this_variable) {
true:
do_stuff();
}
>>
Default state should be false.
Here is some examples
while ( !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
>>
>>56061982
if (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')


vs

if 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.
>>
>>56062656
if(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();
}
>>
>>56061982
lw    $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
}
>>
File: image005.jpg (11KB, 238x215px) Image search: [Google]
image005.jpg
11KB, 238x215px
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!();
Thread posts: 49
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.