- 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
I have no problem in condemning all of the languages used for web-development, particularly given the average level of competence from web-developers is roughly zero. That's why they don't have real jobs.
Admin
I don't think there's any confusion about why this is worse than failure. These heathens are using a massive include full of functions instead of a God Object. Everything runs better with objects! Overhead be praised!
Admin
But then you need to recompile every time someone new joins the team. I prefer.
boolean fix(String person, float beatings)
It returns if he was fixed. Beatings is a float so you can give people less brutal reprimands. But also so you can do
while(!fix(Brian, 0.001)){
}
so you dont unnecesarily beat him too much.
Admin
Why assume that the boss or lead programmer or whoever is so wedded to something he wrote a long time ago. If I came across something like fixString, I'd assume the programmer wrote it when he was a neophyte, and would like to see it improved.
Admin
Nothing. You missed a closing ).
Admin
Admin
Admin
Addendum to TRWTF - Why the hell is he using an array for a single charcter, you get the same thing without array('$')
Admin
So you use C#, and you think all languages used for web development suck? Hmmmm. Sounds to me like you're just another inflexible fanboy, looking for ways to put down things you don't "like".
Languages are tools. You should be able to see the value in even crap tools like Scheme and ASP.net, and not just dismiss them all out of hand.
Admin
Must have been the electricity in his "Great!"
Admin
ok, comic book guy.
Admin
Please Matt, inform us as to what a 'real' job is. I am curious.
Admin
Actually, have a bunch of developers each implement and handle their own input cleaning code seems silly and an invitation for bugs.
The guy added a fix to remove the '$' - great. But what happens when someone enters '$1,000' or '$1,000.00'? Well, now it's more code that needs to be added, and it needs to be added for each developer.
The better solution would be to have a single function that takes a string and return a dollar amount. It would correctly parse all user input that is intended to be used as $$$. All of the developers should use that single function instead of trying to parse the input themselves. If there is a bug in the code, it can be fixed in one place and not for everyone.
Admin
Matt has provided excellent flame-bait, albeit a bit too obvious on his part. Where are the good trolls today?
looks for topcod3r
Admin
When will people learn?
Sure it should be suffixed with g but but christ sake. you DON'T need to escape any (.) when it's in a range of characters ([]). Also don't use ''. Never use '' unless you want \n or something.
'/[^0-9.]/g' will do finely.
I swear there are 50 wtfs here in comments alone.
Admin
And yes I agree why the hell is he using an array? I assume it's a joke aimed at the original function.
Admin
"culture of the computer should be assumed"? the server or the client? assuming is dangerous. perhaps it should enforce your code is culturally aware by requiring a locale to be passed in / set so programmers are more aware of the implications of their choices.
Admin
[quote user="Matt"]PHP sucks because:
I think PHP's biggest downfall is that it's too easy to get something simple working. It invites amateur coders in the professional programming world, and before long it's totally out of hand.
Admin
[quote][quote user="Matt"][/quote]
How embarasing...
Admin
i agree. strong typing, and const correctness, are extremely important. dynamic typing was a shameful feature to have replicated in more than one language. it's more of a cute experimental feature, than it is useful for real production code.
Admin
In my younger and much more foolish days, I had an everything.inc. It was for Perl though and was everything.pm (or something). It had a ton of functions that were useful for various things: trim(), a perl version of the PHP strtotime(), etc.
At least I thought it was useful at the time. Hey, I was young and uneducated and we all make WTFs when we were younger.
Admin
$price='$100.5.4'; $cleanedPrice = preg_replace('/[^0-9.]/g', "", $price);
cleanedPrice is 100.5.4? WTF! 51!
Admin
Admin
Ok, sure, but Ruby and Python are the same way. Beyond that, what are your web development options? JSP and ASP? I personally don't have a problem with ===, but I agree that it's counterintuitive for a newbie.
If you're still using PHP4, you deserve what you get. Haven't they stopped releasing even security updates for it?
Agreed, but that's not something that can't be fixed in the future.
PHP 5.3+ will have namespaces.
PHP is an ugly bitch, but it's a well-documented ugly bitch, and the actual language (i.e. not the function library) is not that bad.
Admin
It seems to me that you should only strip leading dollar signs. If the user types
when they meant to type then arguably that's an error which should be trapped.Admin
Their 4.4.9 release back in August of this year was the last, and it addressed several issues, including some security aspects.
Admin
Brian's str_replace does a lot more than the ordinary one, which you can gauge by the O(n²m) worst case complexity (where n is the string length and m the length of the character array). Never mind that it could easily be O(n) or at least O(n log m) even if the full Unicode spectrum has to be supported.
Admin
trwtf is that the array function is not necessary in his 'better way' :P
Admin
Yup. The whole thing.
Admin
and what would be an example for that worst-case complexity? at first glance I would say the inner loop is executed at most n times IN TOTAL since the length decreases every time. Yields an O(n²) if all characters get removed, plus the obvious O(nm) from strpos executed for every character to be removed.
Admin
just being anal retentive here.. i hate inaccurate/misleading information being referenced as fact in a humor so you can try to get away with it
just for reference the overhead in C++ of a call to a class method is exactly the cost of having exactly 1 more argument in it's argument list for non-virtual functions, and for virtual functions it is that plus two pointer traverses.. not very great performance hit on most systems
(yes on extremely limited resources like embedded platforms it may become noticable but that's why you code specifically for those platforms in mind)
Admin
Yeah, but not always. Take Java's StringBuilder and StringBuffer. StringBuffer exists because people kept "Reimplementing an existing API" making the original StringBuilder run faster.
Admin
that's mostly because the function library developed by extension instead of by a plan too
for all the idiot programmers we hear about dealing with PHP i've seen a equal number of genuine wizards (would be wizard in any language they worked on) writing some very nice PHP
not that anyone i know, including myself, enjoys writing PHP - but that is because we all hate writing webpages and would be rather writing INTERESTING things :P
Admin
I'd rather have beatings be an integer ( you can't only beat them half a time) bool fix('Brian', 10);
Admin
I worked in a web dev/design sweatshop about a year ago, and the lack of function argument typing was certainly aggravating. We had a double deuce, though -- a hulking, monolithic God object (for our home-brew CMS, which was essentially a PHP3 app crammed into a singe 12,000 line class -- I wish I were exaggerating) AND an "everything.inc" file, except the lead developer, the owner's son, didn't know about the .inc extension when he started writing it. The guy also didn't believe in source control, testing on a development server rather than live, and wow, I'm de-railing myself here.
In re: argument types... Most good PHP IDEs (all three or four of them?) support integration with phpDocumentor, and therefore can do type-hinting within the editor, so you can somewhat alleviate this problem, at least in the initial coding stage. Of course, if your lead dev also doesn't believe in IDEs or source code documentation... God, I'm glad I quit that place.
...Although it was pretty awesome watching Eclipse PDT, PHPEd, and Zend Studio all choke on the aforementioned monolith of doom. The only thing that could handle it was Visual Studio with the VS.PHP plugin -- go figure. Too bad the guy didn't take this as a sign that there was something wrong with his approach to so-called "OOP." Rather, all this did was net me a response of, "hurrr, that's why Notepad is the GREATEST!" facepalm
Admin
the $64k question..
Did he fix the function in everything.inc ?
... and what did it break?
:D
Admin
Instead of arguing how a developer should try to correct a completely f--ked input such as "$3$45.4.11,0B" on the back end, how about some front end validation here? Let the user fix their mistake; don't try to read minds. If the input doesn't conform to what you are expecting, throw an error. Chances are if you're having to strip out chars left and right, it's going to be a bad value anyway.
Admin
^$?(\d{1,3}(,?\d{3})*(.\d{2})?)$
I don't use php, but this works in java regexp. Get the value of capture group 1, strip out the commas if your number parser happens to be retarded, and you're good to go.
One could argue that this would be better:
^$?(\d{1,3}(\d*|(,\d{3})*)(.\d{2})?)$
Since it doesn't let you mix commas with non-commas. Of course, it won't work for those crazy Europeans who reverse the thousand-separator and decimal characters, but it at least it doesn't allow 54$$$2.
There may be an easier way, and I'm sure my solutions aren't perfect. I was surprised, though, that regex was mentioned and then the solution used was so...crude.
Admin
I have to disagree. True, it has tons of documentation. But a lot of it is outdated or simply completely incorrect. There are even functions in there of which the number of arguments is incorrect in the documentation. Go figure.
Admin
Obviously ==false means you want it to be false. ===false means you REALLY want it to be false. Scale of economy here.
Admin
Remember that someone went and registered topcod3r.
I think that he has re-invented himself as cod3_complete, whose subtle trolling started the whole language war.
Excellently done, and so entertaining!
Admin
I see there is still someone out there with actual experience. :D
Admin
Admin
Not all languages are C++, nor do they implement their classes in the same fashion. C++ is designed for speed so its objects damn well better be fast.
Admin
No, actually there is no relation between me and topcod3r. He just happens to use a little 1337 speak like I do. I've commented on thedailywtf before (but its been a while)and possibly before topcod3r even started. The posts should still be found with a little searching. And yes PHP really does suck and it matters. :-) http://www.codinghorror.com/blog/archives/001119.html
Admin
The real WTF here is you, if you continue to use PHP4 instead of migrating to version 5.
And no, not everyone uses PHP 4.
Admin
And you worked with PHP last time in 2001? That explains everything, kiddo.
Admin
I'm curious as well, if web developers don't have real jobs then tell me why I develop web applications under the title of "Web Developer". If we are as incompitent as you say we are then why are we being paid oh so much money to support major online corporations such as Google, ETrade, Scottrade, Yahoo, etc. and are increasing in demand as we speak.
I also don't understand how a web developer's position is different from a database developer or java developer... same concept different environments. It's all programming, maintenance and standards.
I'm sorry that you can't get a real job, but you don't have to take it out on us. Keep trying, you'll get that QA position you want.
Admin
For the record, NoScript (a Firefox addon) freaked out over the URL for this story. I understood why it was not a malicious link but NoScript just saw the code and threw an error.
Admin