News for hackers. Stuff that matters.
Re:How to Score a Google Onsite Interview by latch on Saturday April 30, 2011 @11:15PM (#2502211)
I don't know the difference between (“x” == x) vs. (x == “x”), and googling isn't helpful (hah!). Anyone?
Re:How to Score a Google Onsite Interview by Luyt on Sunday May 01, 2011 @03:26AM (#2502599)
"CONST == variable" is called a 'Yoda condition'. More information on this can be found at http://united-coders.com/christian-harms/what-are-yoda-condi... , which describes its uses and advantages. I tried to use them a while, but not anymore, because I find them unnatural; like reading backwards. In my opinion, it's more logical to first introduce what is being compared instead of some value which will be compared against. This is especially true if you revisit the code after a few months.
Re:How to Score a Google Onsite Interview by pfedor on Sunday May 01, 2011 @01:34PM (#2503499)
Furthermore, for many year now the compilers have been able to warn you if you use = instead of ==.
Re:How to Score a Google Onsite Interview by Jach on Sunday May 01, 2011 @02:52AM (#2502553)
I noted that ("x" == x) avoids the problem of (x = "x") that others mentioned, but really, any sane compiler will warn you about the second. (GCC does, mxmlc does, Python flat out disallows the syntax.) The way to shutup the warning is to say ( (x = "x") ) if you really mean it.

I was more worried that the language in question was C++, so you have to worry about conversion constructors, conversion operators, operator==, etc.

Re:How to Score a Google Onsite Interview by allenc on Sunday May 01, 2011 @01:56PM (#2503559)
Agreed, although some laxer languages - say, Javascript - will let you do it all the same. Like I said, it's not necessarily a rule to follow, but whenever I come across people who would do things slightly off (from common coding practices anyway) I notice the difference, and if it's something I recognize I put a little mark there in case they're really, really close. I come from a C++ background, so stuff like i++ and ++i really do make a diff.
Re:How to Score a Google Onsite Interview by epochwolf on Saturday April 30, 2011 @11:58PM (#2502299)
Look at what happens if you miss a =

    (“x” = x) //Throws a compile error
vs

    (x = “x”) //x is set to "x"
Edit: sorry about the quadruple submit, don't know what happened there
Re:How to Score a Google Onsite Interview by latch on Sunday May 01, 2011 @01:18AM (#2502418)
Right..not a problem in Java/C# and no compiler benefit either way in a dynamic language. The "x".equals(x) might be slightly more relevant (no fear of x being null).

Cheers.

Re:How to Score a Google Onsite Interview by elq on Saturday April 30, 2011 @11:16PM (#2502215)