- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
would like to know, how parseInt() looks like :)
Admin
This one wins the internets.
Admin
FTFY
Admin
Any problems with the above code are due to ambiguity in your code, not the language. This is what gives PHP a bad name, bad programmers. If you want a negative number you should type
If you want it stored as a string: but there's absolutely no reason to try or half of your examples, for that matterAdmin
Yes, I agree this is bad. But it happens. Far too often. I was working at a project where we had things like:
always @(a) begin b = a; end
always @(c) begin d = c; end
And pages of it....
(This is VERILOG, a hardware description language. As in the current WTF, the second function, this is just a pass through and completely redundant.)
We were not allowed to refactor this mess in case it could break abything - ha - like there was anything to break. And this in the source code for a microprocessor in use today - be afraid.
Admin
If you think that stuff is scary, try:
While I would never advocating executing random code found on the internet unless you understand what it does, in this case, if you copy and paste it to your url bar, it is the equivalent of
See this blog entry for an explanation of how it works, or the original slide which it came from at Ryan Barnett's BlackhatDC presentation " XSS Street-Fight: The Only Rule Is There Are No Rules", slide 40...
(Links to further analysis in the comments of the blog post...)
Admin
Or you could use generics/templates in a strongly typed language.
Admin
As with anything, use the appropriate tool for the job. "If all you have is a hammer, every problem looks like a...".
Admin
PHP: Expects the dot in front of a number to be a decimal point and discovers that the number in front of the decimal point is missing. It suspects you tried something else and tells you to either end the command with a semicolon or use a comma as concatenation operator in this case. While this is an extra WTF - using two different concatenation operators which are not interchangable and only valid in certain situations - it is not the point of my argument. The point is: The dot is not interpreted as concatenation operator in this case because it precedes an operand of a certain type.
Java: Concatenates "1" to the string, and then someVariable's content. We can agree that it depends on the context whether "+" is seen as concatenation operator or not. Therefor it is ambiguous.
In both cases you can put parenthesis around the math expression to get the math done if that is what you intended to do. It is better practice; in most cases, it is even better to use a seperate variable.
Since my initial goal was to show that PHP's concatenation is not disambiguous, I won't get into the argument whether Java's or PHP's concatenation operator is superior. I'd probably cause religious wars with that.
Admin
I bow to the masters.
Admin
Admin
JavaScript supports anonymous functions for this purpose.
Admin
Such functions are actually very common in functional programming.
The latter one is often called IDENTITY or just (lambda (x) x).
So I don't see the wtf.
Admin
Uh, lemme guess - you worked for AA back in the ol pre-Enron days..? :-)
Admin
And (as people have no doubt said, given I'm late on the scene) returns exactly what it was passed...