r/ProgrammerHumor • • Jan 05 '19

You know it's true

Post image
60.6k Upvotes

1.1k comments sorted by

View all comments

84

u/SSUPII Jan 05 '19

How can I know if I'm good or bad?

104

u/mrbmi513 Jan 05 '19

What is the value of x? int x = 5/2.0;

13

u/theXpanther Jan 05 '19

Also, what is the value of x ? x = 5/2.0 : ';'

70

u/adenosine-5 Jan 05 '19

what monstrosity of a language allows that syntax?

43

u/Thalanator Jan 05 '19

my bet is on some spawn of javascript

36

u/Cobaltjedi117 Jan 05 '19

Or maybe just JavaScript

2

u/mypetocean Jan 05 '19

No, you can't check the value of x if it hasn't been declared (either lexically earlier or by hoisting), and you can't perform an assignment like that within a ternary without wrapping the assignment in parentheses.

The only place that line as a whole would not throw a runtime error in JavaScript would be in a try block — and of course even then it wouldn't do anything but pass the error to catch.

2

u/_Lady_Deadpool_ Jan 06 '19

Python would let you, albeit with its backwards format

x = 5/2.0 if x else pass