Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Strong Sauce
Jul 2, 2003

You know I am not really your father.





Skuto posted:

Only in strict mode. In ES6 it's back with different prefixes, one of which I'm going to mention because it's appropriate here: 0O. (Admittedly I can't think of a case in which that would cause bugs, no matter how silly it looks)

Maybe you're thinking of parseInt enforcing base10 in ES5?

The problem is the ES6 spec claims the code in the previous post is illegal. On the internet, this means the spec is wrong, because for sure nobody is going to fix their website. What makes it so grating is that the uses are mostly the date example given, so they're are not just wrong, they're downright stupid, misguided, and in some cases likely subtle bugs of their own.

As I said, JavaScript is an easy punching bag, but this one is another level of "extra-special".

Which javascript environment are you using that says 08 as an octal?

Separately, the ES6 spec at least as of July says numbers beginning with 0 should be a decimal number..

Edit: It seems in node/firefox/chrome any invalid octal number returns the decimal equivalent... which sounds worse than throwing an error.

Strong Sauce fucked around with this message at 23:40 on Aug 6, 2014

Adbot
ADBOT LOVES YOU

xtal
Jan 9, 2011

by Fluffdaddy
== true does have a legitimate use case in any language with truthy values other boolean true, am I misunderstanding something or why is this discussion happening?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

xtal posted:

== true does have a legitimate use case in any language with truthy values other boolean true, am I misunderstanding something or why is this discussion happening?

Wanting to specifically distinguish true from other truthy values nearly always means you've doing something very stupid.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
code:
    outStr  = strReplace( tradingPartnerId, ',', ' ' );
//  2 Direction
    outStr += ',' + strReplace(enum2str( EBmDocDirection::Outbound ), ',', ' ');
//  3 Type
    outStr += ',' + strReplace(enum2str( EBmDocType::Rebate ), ',', ' ');
//  4 Claim Number
    outStr += ',' + strReplace( claimSeqNumber, ',', ' ' );
//  5 Submission Date
    outStr += ',' + date2str( systemDateGet(), mmddyyyy, dayChars, slash, monthChars, slash, yearChars );
//  6 Report Period Start Date
    outStr += ',' + date2str( startDate,       mmddyyyy, dayChars, slash, monthChars, slash, yearChars );
//  7 Report Period End Date
    outStr += ',' + date2str( endDate,         mmddyyyy, dayChars, slash, monthChars, slash, yearChars );
//  8 Distributor number
    outStr += ',' + strReplace( DCRebateDistributorXref::find( vendor, warehouse ).DistributorNumber, ',', ' ' );
//  9 Distributor name
    outStr += ',' + strReplace( companyinfo::find().Name, ',', ' ' );
// 10 item nbr
    outStr += ',' + strReplace( DCRebateReportTable.ItemId, ',', ' ');
// 11 upc nbr
    outStr += ',' + strReplace( ProductReferenceTable::findItemLabel( RebateReportTable.ItemId, 'UPC' ).RefItemId, ',', ' ' );
// 12 mfg nbr
    outStr += ',' + strReplace( ProductReferenceTable::findItemLabel( RebateReportTable.ItemId, 'MFG' ).RefItemId, ',', ' ' );
// 13 InToStock Cost
    //!<COMMENT>
    //!    <AUTHOR>Redacted</AUTHOR>
    //!    <DATE>Nov 16 2012</DATE>
    //!    <DESCRIPTION>Need to Take the POCost from the DB, no need to recaculate</DESCRIPTION>
    if ( DCRebateReportTable.POCost )
    {
        outStr += ',' + strReplace(strltrim(num2str( DCRebateReportTable.POCost, numChars, numDecimals, decimalSep, thousandSep )), ',', '');
    }
    /*
    intoStockCost = ContractPricing::getPurchCostDate( DCRebateReportTable.ItemId, DCRebateReportTable.SalesUnit, '', endDate );
    if (!intoStockCost)
    {
        intoStockCost = ContractPricing::getPurchCostDate( DCRebateReportTable.ItemId, DCRebateReportTable.SalesUnit );
    }
    if ( intoStockCost )
    {
       outStr += ',' + strReplace(strltrim(num2str( intoStockCost, numChars, numDecimals, decimalSep, thousandSep )), ',', '');
    }
    */
    else
    {
       outStr += ',0.00';
    }
// 14 Contract Cost
X++ if anyone is wondering.

This goes on all the way up to // 42.

Knyteguy fucked around with this message at 03:51 on Aug 7, 2014

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Jesus, the part of my brain devoted to JS type semantics must finally be being reclaimed. :downs:

Vanadium
Jan 8, 2005

Strong Sauce posted:

Which javascript environment are you using that says 08 as an octal?

Separately, the ES6 spec at least as of July says numbers beginning with 0 should be a decimal number..

Edit: It seems in node/firefox/chrome any invalid octal number returns the decimal equivalent... which sounds worse than throwing an error.

https://mail.mozilla.org/pipermail/es-discuss/2014-August/038596.html

Can't ~break the web~, man.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨


Sort of pointless to do so, too, in this case.

xtal
Jan 9, 2011

by Fluffdaddy

Plorkyeran posted:

Wanting to specifically distinguish true from other truthy values nearly always means you've doing something very stupid.

Or a library is, but yeah.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Okay so I guess Skuto used a nightly version that threw an error for him about 08?

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

Strong Sauce posted:

Okay so I guess Skuto used a nightly version that threw an error for him about 08?

I saw some tweets about the issue on my stream, and thought it was hilarious after seeing the date example, in the saddest sense of that word.

Soricidus
Oct 21, 2010
freedom-hating statist shill
Picture, if you will, a codebase in which the .h files are all symlinks to the corresponding .c files, most of which then #include themselves recursively.

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.
I tried, but I can't. How do you not get duplicate symbols?

Soricidus
Oct 21, 2010
freedom-hating statist shill
Different bits of the files are used each time they're included, depending on which symbols are already defined.

I wish I was joking.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Soricidus posted:

Picture, if you will, a codebase in which the .h files are all symlinks to the corresponding .c files, most of which then #include themselves recursively.

This is an awesome way to say "I hate you and myself"

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Soricidus posted:

Picture, if you will, a codebase in which the .h files are all symlinks to the corresponding .c files, most of which then #include themselves recursively.

All I get is that scene in π where he takes a drill to his own head except I'm the guy

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Soricidus posted:

Picture, if you will, a codebase in which the .h files are all symlinks to the corresponding .c files, most of which then #include themselves recursively.

Time works the same way.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
There was a discussion last page on "if (x == true)" being bad form because generally "if (x)" is the better alternative.

What about "if (!x)" versus "if (x == false)"?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Soricidus posted:

Different bits of the files are used each time they're included, depending on which symbols are already defined.

I wish I was joking.

Purify your code base and coworkers with cleansing fire.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Knyteguy posted:

There was a discussion last page on "if (x == true)" being bad form because generally "if (x)" is the better alternative.

What about "if (!x)" versus "if (x == false)"?

I'd say it's the same. It's also more readable if you use descriptive names.

code:
while (!ready) {
    sleep(1000);
}

Soricidus
Oct 21, 2010
freedom-hating statist shill

Volmarias posted:

Purify your code base and coworkers with cleansing fire.
We were thinking of sticking the code on a spike above the front door as a warning to others. We'd do the same to the perpetrator, but curiously enough he doesn't seem to work for us any more.

Knyteguy posted:

There was a discussion last page on "if (x == true)" being bad form because generally "if (x)" is the better alternative.

What about "if (!x)" versus "if (x == false)"?
The same arguments mostly apply. The explicit comparison is safer with false values than it is with true values, but it still has no real advantages, and there are still plenty of cases in many languages where its semantics may not be immediately obvious. So the shorter form is usually more idiomatic.

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀

eithedog posted:

If anybody's interested, in JS, for example:

code:
if ({}) { console.log('hi'); }
outputs hi.

code:
if ({} == true) { console.log('hi'); }
doesn't

That's not fair. Using js is cheating.

Knyteguy posted:

There was a discussion last page on "if (x == true)" being bad form because generally "if (x)" is the better alternative.

What about "if (!x)" versus "if (x == false)"?

I don't think either form is actually any less clear than the other. Just write whichever feels natural.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Knyteguy posted:

There was a discussion last page on "if (x == true)" being bad form because generally "if (x)" is the better alternative.

What about "if (!x)" versus "if (x == false)"?

Once upon a time the related if (p == NULL) might've made sense (in C at least), if you couldn't count on NULL being falsy. But I think it's been standardized as 0 for quite some time now.

In other languages you've got various definitions of "falsy" and various behaviours of the == operator, so whether or not the expressions are equivalent depends on the language.

hobbesmaster
Jan 28, 2008

The reason to do ==false is because it's easier to skim than a single !

Also in C you should do false== because defensive programming.

JawnV6
Jul 4, 2004

So hot ...

hobbesmaster posted:

Also in C you should do false== because defensive programming.

Pretty sure our new hire will have to be trained out of doing this.

hobbesmaster
Jan 28, 2008

Eh so long as you actually have a standard.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
In C, you should be compiling with warnings on, including -Wparentheses, preferably as errors (at least in your local build), which will catch silly things like accidentally using assignment instead of equality far more effectively than internalizing dumb rules like always writing false==. There are so very, very many gotchas in C; you might as well let the tools handle the easy ones.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Strong Sauce posted:

Edit: It seems in node/firefox/chrome any invalid octal number returns the decimal equivalent... which sounds worse than throwing an error.

Jesus, it's the worst of both worlds.

code:
x=077;
y=078;
alert(x); //63
alert(y); //78
Use strict mode

Edit: Even more simple:
code:
alert(078-077); //15

HappyHippo fucked around with this message at 02:57 on Aug 8, 2014

shrughes
Oct 11, 2008

(call/cc call/cc)

pokeyman posted:

Once upon a time the related if (p == NULL) might've made sense (in C at least), if you couldn't count on NULL being falsy. But I think it's been standardized as 0 for quite some time now.

It still makes sense because it makes the code more readable. At least I had to make that a rule because a coworker was doing all sorts of implicit pointer-to-boolean conversions in a way that must have felt so clever but didn't do anything good for readability.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Soricidus posted:

We were thinking of sticking the code on a spike above the front door as a warning to others. We'd do the same to the perpetrator, but curiously enough he doesn't seem to work for us any more.

So what you're saying is that there's no one to be upset if your codebase was mysteriously refactored to sanity.

NFX
Jun 2, 2008

Fun Shoe

Dr. Stab posted:

That's not fair. Using js is cheating.


code:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> if object():
...   print "hi"
...
hi
>>> if object() == True:
...   print "hi"
...
>>> import datetime
>>> datetime.datetime(2013, 08, 19)
  File "<stdin>", line 1
    datetime.datetime(2013, 08, 19)
                             ^
SyntaxError: invalid token

Axel Rhodes Scholar
May 12, 2001

Courage Reactor

pokeyman posted:

It is possible, depending on language, that some boolean-ish value needs to be coerced to an actual boolean. For example, in Objective-C (and this anecdote belongs in this thread for one reason or another), the boolean type used to be a typedef'd char, with the values YES and NO defined as 1 and 0. So you could return something like 17 as a boolean, and since it's just C it works when you do if (myBoolValuedSeventeen), but as soon as some joker tried if (myBoolValuedSeventeen == YES) they hosed themselves. The competent library writer would thus make sure they returned YES or NO.

I found another fun way to screw up with this in our codebase the other day.

code:
int someBitMaskOption1 = (1 << 0);
int someBitMaskOption2 = (1 << 1);
int someBitMaskOption3 = (1 << 2);
...
int someBitMaskOption9 = (1 << 8);
...
BOOL isOption9Enabled = (BOOL)(flagsToCheck & someBitMaskOption9);

Look Around You
Jan 19, 2009

NFX posted:

code:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> if object():
...   print "hi"
...
hi
>>> if object() == True:
...   print "hi"
...
>>> import datetime
>>> datetime.datetime(2013, 08, 19)
  File "<stdin>", line 1
    datetime.datetime(2013, 08, 19)
                             ^
SyntaxError: invalid token

Maybe I'm the wrong one but I've always thought that in languages with nullable object types it really makes sense to let you write if (object) and have it coerce to boolean true if it exists and boolean false if it's null. It makes testing for object existence a lot cleaner. The semantic difference between that and if (object == true) also makes sense to me because an (non-null) object reference is a truthy value, but it's not necessarily the literal value true (and it probably actually isn't),, so directly comparing it to true and expecting it to return true for the comparison doesn't make any sense.

I guess I just find
code:
o = some_function_that_returns_an_object_or_null()
if (o) {
  // do stuff with o
} else {
  // handle not having object
}
a lot cleaner than if (o != NULL). It's also idiomatic in most languages that allow it, so you really should be able to see what's going on if it's the only thing in the conditional part of the if statement (like above)

Look Around You fucked around with this message at 09:21 on Aug 8, 2014

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

NFX posted:

code:
>>> import datetime
>>> datetime.datetime(2013, 08, 19)
  File "<stdin>", line 1
    datetime.datetime(2013, 08, 19)
                             ^
SyntaxError: invalid token

That's the sane behavior...which JS can never ever get.

QuarkJets
Sep 8, 2008

hobbesmaster posted:

Also in C you should do false== because defensive programming.

What does this mean?

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

QuarkJets posted:

What does this mean?

If you write if (false = variable), instead of if (false == variable) you'll get an error.

QuarkJets
Sep 8, 2008

Skuto posted:

If you write if (false = variable), instead of if (false == variable) you'll get an error.

Oh so it's to generate an error in case you leave off the second =, since 'variable = false' would be valid whereas the reverse is not. Good to know

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

Skuto posted:

That's the sane behavior...which JS can never ever get.

Is there any real reason to support octal literals (as opposed to math functions that handle arbitrary bases) anymore?

I know they look neat for some bit twiddling, but hex is always there for that as well.

hobbesmaster
Jan 28, 2008

Compilers these days will have a warning like "Did you really want an assignment in an if statement?" But I got in that habit when writing embedded code with a terrible compiler...

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

ulmont posted:

Is there any real reason to support octal literals (as opposed to math functions that handle arbitrary bases) anymore?

I know they look neat for some bit twiddling, but hex is always there for that as well.

That's what I'd like to know too. Outside of Unix style file permissions, when would you realistically use octal?

Adbot
ADBOT LOVES YOU

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Volmarias posted:

Outside of Unix style file permissions, when would you realistically use octal?

Typically, accidentally.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply