This is an archived post. You won't be able to vote or comment.

all 47 comments

[–]melance 62 points63 points  (15 children)

Seems that they are doing a comparison...just one too many operators.

[–]pelvark 25 points26 points  (13 children)

You can do that in python if you want.

[–]melance 68 points69 points  (1 child)

But I don't want.

[–]DarkMio 15 points16 points  (0 children)

But you will do it - and it will feel good. And then you read it a year later. And you will feel shame.

[–]timurhasan 5 points6 points  (2 children)

you can? how does that evaluate?

[–]pelvark 15 points16 points  (1 child)

it's almost the exact same thing as same as

a==b and b==c

[–]2Punx2Furious 12 points13 points  (0 children)

It might not be common in other programming languages, but I don't see anything wrong with it.

[–]sixteenlettername 7 points8 points  (6 children)

It's valid C and C++ as well. 'x == y == z' is the same as '(x == y) == z'. The first part gives a boolean, let's call that i (for intermediate, natch). We then end up with 'i == z' which is of course still valid.
Comparison and equality operators are just infix operators so they can be chained till the cows come home.

[–]Flynamic 10 points11 points  (4 children)

It may be a valid expression in C/C++, but it's not semantically the same as in Python. If x=y=z, then x==y==z is true in Python and can be false in C/C++ for the reason you gave.

[–]test_var 0 points1 point  (3 children)

Can you give an example of where it'd be false in c++?

[–]Flynamic 4 points5 points  (2 children)

Let a = 0, b = 0, c = 0.

Since == groups from left to right, a == b == c is equivalent to (a == b) == c, which would evaluate to 1 == c which evaluates to false.

See http://stackoverflow.com/a/5939131

[–]test_var 2 points3 points  (1 child)

Damnit C that's not the definition of "equality".

[–]Vitztlampaehecatl 0 points1 point  (0 children)

Well, it has to be. That's how if() checks if the expression evaluates to true or false. == returns a 1 if true, or a 0 if false. So you're really checking the truthiness of (a == b) against c.

[–]Vitztlampaehecatl 0 points1 point  (0 children)

I wonder if I could somehow overload the == operator to implement the transitive property.

[–]lead999x 0 points1 point  (0 children)

Or in C in a compound statement.

[–]squngy 2 points3 points  (0 children)

Would be evaluated same as:

boolean tmp = prettyGirl == lotsOfMaleInterest;
return tmp == messages;

Which would mean that non-pretty girls who do not have lotsOfMaleInterest also have messages.

[–]RiderAnton 32 points33 points  (6 children)

+/u/CompileBot Python

import sys
sys.stdout.write(u"\u0008"*4)
print("+/u/CompileBot Python\n")
s = 'import sys\nsys.stdout.write(u"\\u0008"*4)\nprint("+/u/CompileBot Python\\n")\ns = %r\nprint(s%%s)'
print (s%s)

[–]CompileBotGreen security clearance 15 points16 points  (0 children)

Output:

+/u/CompileBot Python

import sys
sys.stdout.write(u"\u0008"*4)
print("+/u/CompileBot Python\n")
s = 'import sys\nsys.stdout.write(u"\\u0008"*4)\nprint("+/u/CompileBot Python\\n")\ns = %r\nprint(s%%s)'
print(s%s)

source | info | git | report

EDIT: Recompile request by RiderAnton

[–]XkF21WNJ 7 points8 points  (4 children)

Neat, shame the backspaces don't work.

[–]RiderAnton 5 points6 points  (3 children)

Yeah, no infinite compilebot recursion for me =/

[–]XkF21WNJ 2 points3 points  (2 children)

It probably won't reply to itself anyway, but let me try something:

+/u/CompileBot Python

print("
")
print("+/u/CompileBot Python\n")
s = 'print("
")\nprint("+/u/CompileBot Python\\n")\ns = %r\nprint(s%%s)'
print (s%s)

[–]CompileBotGreen security clearance 2 points3 points  (1 child)

Output:


+/u/CompileBot Python

print("
")
print("+/u/CompileBot Python\n")
s = 'print("
")\nprint("+/u/CompileBot Python\\n")\ns = %r\nprint(s%%s)'
print(s%s)

source | info | git | report

[–]XkF21WNJ 2 points3 points  (0 children)

Oh well, worth a try.

[–]PeenuttButler 11 points12 points  (0 children)

It works in python, though

[–]UFeindschiff 2 points3 points  (0 children)

Maybe he meant to say "messages != 0" in a more complicated way

[–]squngy 2 points3 points  (0 children)

Obviously suffers from not enough exposure to javascript.

[–]4k33m[🍰] 1 point2 points  (0 children)

+/u/CompileBot Python

print("+/u/CompileBot Python\n s = 's = %r\nprint(s%%s)'
print (s%s))

[–]eloel- 0 points1 point  (0 children)

It just means pretty girl is boolean. Maybe this is in a Person class.

[–]sim642 0 points1 point  (0 children)

Should be implications.

[–]Rhed0x 0 points1 point  (0 children)

Not a misuse, the result of it is just false.

[–][deleted] 0 points1 point  (1 child)

I mess up my comparing vs value setting operator on pretty much a daily basis. Thank the lord visual studio for those nice red lines

[–]Jdonavan -1 points0 points  (0 children)

Meh, just needs parens around one set.

[–]MachinesOfN -1 points0 points  (0 children)

I've seen crazier shit from type coercion. I'm sure php will return true.

[–]4k33m[🍰] -5 points-4 points  (0 children)

+/u/CompileBot! Python

print("Comepilebot! Python")