- 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
Um...factory is implementable JUST FINE in PHP. I've done it on no fewer than three occasions.
To quote farscape character: "The Imperfection is yours"
Admin
Equality can't be commutative - commutativity means that the order of terms used in an operator don't matter e.g. ab=ba. Note that a notion of equality is required to test commutativity.
Equality is symmetric - "a=b" implies "b=a"
Admin
There's more than one Buddy. I suppose I should register it.
Admin
When the 'is equals' operator ceases to be symmetric, then you're in for a world of hurt.
Admin
Admin
A couple of jobs ago, I had a quasi-client (we worked for the same company, but he was one of the users of the software I wrote/maintained) who kept referring to me as a guru. Eventually I gave up telling him that the term made me uncomfortable and that I preferred "developer."
Admin
So you're saying Facebook is not an major site?
Admin
Admin
Not to defend self-styled "tech gurus", but I'm not convinced that the code was all that bad. The function names were at least meaningful.
Admin
I'll gladly call that facebook site a major fuckup at least.
Admin
Alright, this "Try switching the order around" made me actually try it.
In other words: Switching the comparison around did NOT fix the universe.
Mac 10.5.6
Admin
PS: wow, it works!!! Perhaps I should post more often random nazi/jew jokes!
Admin
Pages 90-93 of the hardback edition of "Eats, Shoots & Leaves", by Lynne Truss.
Whether you consider that book a reliable source is another matter (though unless you have read it, refrain from making statements as to its reliability). The point here is I did not "make up new rules."
Admin
I come mainly from a C++ background, but as most of my work has been web aps lately, I find PHP is the main language I use on a regular basis.
Like every other language that people actually use, PHP has some things it does exceptionally well, some annoyances, and some tradeoffs where it does something awesome, but at the cost of making something else a pain in the ass. All in all, I think it's a great language, but like any language, it has it's share of annoyances.
As many have pointed out, PHP is very easy to learn in the sense that you can probably get it to do something the first day you try to use it, with no programming background. The result is that a lot of people try to learn it without really learning the concepts of good code, and a lot of WTFs result. This isn't a problem with PHP, it's a problem with those people. This is especially bad when you get someone who learns how to use PHP's very easy to use DB features, but doesn't have a clue how to normalize a database, or how to write a decent SQL query. The result may WORK, but some of the code that results is a nightmare.
What I've found is that most people who are fully trained programmers (whether via school or just buying books and actually taking the time to learn) write code just fine in PHP, and the results are great, while those who just want to code something NOW write WTFs. The only difference is that with PHP, the second group is far more likely to get something that runs, and some of that crap gets distributed, while with most other languages, they'll never actually get their code functional, so their crap never leaves their machine. Again, easy to learn language + people who use it without really understanding how to program = WTF code. There's nothing wrong with the language, there's just a higher chance that shitty code will kinda sorta work.
As for loose typing, it IS very much a double-edged sword. PHP supports Perl-style arrays, where an element can be named as a label (x['user'] instead of x[1]), and where you can mix data types within an array. This may sound useless until you realize what it can do with a database. A single function call returns a row of an SQL result set as an array, with each element named exactly what you called it in the database. Loop it and you've got your entire result set in an easy to manipulate form, with all column and variable names automatically consistent. Alternatively, call a row at a time in a while loop to print out a table of data with whatever operations you need performed on it, automatically breaking the loop when there's no data left to read. (Things like user lists, forum thread displays, and high score tables all become really easy to do in very few lines of very readable code.)
On the other hand, the price of this is a language which, like all loosely typed languages, doesn't know the difference between NULL and 0, and has the odd case where '0' is the somewhat paradoxically "null, but nonempty" string. It can also lead to weird cases such as adding 7 to '12 Main St' due to a misplaced line of code executing with no error, and giving '19 Main St' as a result. Result: You have to manually typecast a bit more often than you should, you need some extra error checking code, and when checking if a string is "true", you have to make sure it's not something that can reasonably have '0' as a valid string (if it is, just add an extra check to your if statement, this really isn't the huge issue some make it out to be).
IMO, PHP does a good job of making good use of the advantages of loose typing, while minimizing most of the annoyances.
The bottom line: It's a useful, (mostly) well-designed language for web development, which can be - and often is - abused by those who think ease of use means you don't need to understand coding logic. In the hands of someone who actually knows how to program though, you will see quality code on a regular basis.
Admin
You guys never have worked with a truly fucked up scripting language. Actually I bet you (by "you" I mean php-bashers) never have worked with other less common scripting languages (VB and Javascript apart). The pain of undocumented features, functions, error codes, lack of obvious data access methods, example code that doesn't work, monstrous legacy code left by other (probably insane) developers, and a ridiculous price tag attached to it - this is where your steel balls are forged.
Admin
To be fair, all the stories with guys who don't call themselves gurus also end up with them writing shitty code. It's kind of the point of the site.
Admin
He says, offering dangling conjunction, mixed metaphors, a non-sequitur, and a faulty call to authority. I think you generally prove my point. I also think, by your logic, that you probably used to write expert systems in the 90s.
Admin
I'm ashamed to say I just wrote a code snippet like this, although using String.Format. I'll go back and document it now.
Admin
Real programmers know you're supposed to do anything for the web in perl. Fill it with regular expressions because they're better. And obfuscate it in case someone tries to steal your code. And while you're at it you need to reformat the text so it looks like beautiful ascii art.
Admin
Admin
HyperBoolean:
0 = False 1 = True 2 = False, DAMMIT! 3 = True, True, True, you moron! 4 = I don't know, and I don't give a damn ...
Admin
wordpress? cmon wordpress is dogdoodoo.
Admin
Any language let's you write bad code. php just makes it a bit easier than some. I'm in the middle of customizing (i.e. completely changing) a Magento site. Magento is so full of WTFs it's insane. Some classes are perfectly well written, others a complete nightmare.
Admin
Is this an intentional misquote?
should be "if you write anything criticizing editing or proofreading, there will be a fault of some kind in what you have written"...
Admin
Admin
so the gooroo would become an expert. Is this up- or downgrading?
Admin
Admin
(What follows is not part of the above reply; i.e., not directed at Trerro). No, PHP doesn't offer all the constraints and protections that a statically-typed language would offer. And when a language allows you to compare entities of arbitrary types then some rules have to be laid down to ensure predictable behaviour. And if you find yourself getting bitten by ("0"==false && "a"==true && (int)"a"==(int)"0") then you've only got yourself to blame. The rules are there, they're published, they're consistent, and if you can't be bothered learning about the basics of the language before bashing it then, well, your opinion doesn't count for much. And if you don't want to RTFM ... how big is an unsigned long in C++ again?
Crap code is written by crap programmers. PHP's biggest problem is that it's crap-programmer-friendly. Starting with the truism that of any given population of people, half of them have below-average intelligence for that population, and taking Sturgeon's Law into account, I hypothesise that any competing technology that gains significantly more than half of its potential share is (a) idiot-friendly, (b) crap, and (c) encourages idiots to make more crap.
Admin
Um. I see. Murfrys law: "Anything you do is wrong"?
Admin
did you just misspell brillant?
Admin
NaN = FILE_NOT_FOUND
Admin
I don't get it. The way I see it, this is misuse of the == operator. Sure, you can try and compare object references, and if you happen to compare objects that are statically defined somewhere it even seems to work. But that doesn't make it correct code, and you're not supposed to do it.
Admin
Yes, but this is the point. You do not use Java (or similar strongly typed OO high level languages with complex frameworks) for simple 2-coding-days web apps.
Java begins to shine when you have a big team of developers that writes and later maintaines (!) and changes/extends (!!) a big and complex application (which BTW does not mean that you can not create a complete mess with Java, but it's certainly easier with php when app complexity and size are considerable).
For your project the overhead of Java was simply too much and php is indeed the tool of choice.
Admin
Yes, the == operator should not be used for comparing Boolean objects, but rather only for boolean primitives. But with Java 1.5 automatic boxing and un-boxing, you potentially have Boolean objects automatically being converted into boolean primtives or vice-versa, so that, depending on the operator precedence and the exact expression, the == operator might not actually be comparing objects. That said, any code depending on that would be hard to understand and error-prone.
Furthermore, there is seldom any reason for comparing boolean values in the first place, i.e. you should write "if (booleanvalue) {}" rather than "if (booleanvalue == true) {}".
As an answer to the original posting, as to why Boolean constructors are needed at all, how about parsing values from a properties file, such as "someoption=true", and if the admin or user doing the configuration can't spell "true" correctly, then they just get false, and tough on them.
Admin
Oh wait, that was an intentional decision and is in fact A Good Thing (R)!
;o)
Admin
The rule is actually quite simple: The constructor taking a string parameter only creates Boolean.TRUE if and only if the string is written exactly like Java's boolean literal (i.e. the keyword!) for true, which is, well, "true" without the "" ;o)
Everything else is treated as false.
So new Boolean("TRUE") does not "break the equality operation", it just simply does not create a Boolean-instance with the value "true".
Whether the existence of such a constructor is a WTF is debatable.
But it often helps in avoiding boilerplate code that converts string values to booleans (web apps are all about strings, after all...). Of course you may have to convert an arbitrarily capitalized string to be exactly like "true" first, e.g. by stripping whitespace and always converting it to lower case.
Of course NOT using the pre-fabricated instances Boolean.TRUE/Boolean.FALSE if you need a wrapped boolean and do NOT process arbitrary strings from a web app or similar is plain stupid (and shows that the developer does not know the first thing about Java).
Admin
[quote user="Rocky"][quote user="illtiz"][quote user="Paul"] As an answer to the original posting, as to why Boolean constructors are needed at all, how about parsing values from a properties file, such as "someoption=true", and if the admin or user doing the configuration can't spell "true" correctly, then they just get false, and tough on them.[/quote]
For parsing you should use Boolean.parseBoolean(String s) which returns either Boolean.TRUE or Boolean.FALSE and not a new Boolean object.
Admin
No it doesn't, first it is case insensitive (see the API doc), second it returns a new Boolean object backing the primitive value true or false. It is NOT the same object as Boolean.TRUE.
It does. new Boolean("TRUE").equals(Boolean.TRUE) does return true.
Admin
Admin
i could ALMOST accept that if they allowed explicit memory releases on top of the garbage collection.
Admin
Don't bash PHP. PHP rules the web. Long Live PHP.
More bad code comes from VB and Java, you hardly ever see bad PHP code on this site.
Captcha: validus - yes it is.
Admin
I smurf you're smurfing the smurf with Smurfy's law: anything you smurf will be smurfed on.
Admin
Better. Cheaper.
Admin
I don't think you can beat the scripting reporting language of G---M--- CRM (of some years back) for true WTF-ery. Everything you talk about and more. Spent six months on that navigating the minefield of hard crashes that it was, just to write three very simple reports, then a year maintaining it (and watching it mostly being ignored by our own in-house staff).
Admin
The truth shall set you free...
Admin
But that does not really help if you are evaluating/parsing string representations....
Admin
Every programming language has it's own bugs. And no, bugs are not "language features".
Flaming PHP is so old.
Admin
Just to be joyously contrarian:
Yes, in ALGEBRA, it is meaningless to ask whether equality is commutative because equality is a relation and not an operation. It can be, for example, reflexive, symmetric, and transitive, but not commutative.
But in many computer languages, including Java and C++, equality is an operation. "a==b" is an operation on two values that returns a value, true or false. It is perfectly valid to include it as a part of a larger expression, like in C I could write "((a==b)+1&7)", and that could be evaluated to give some result.
Therefore, in such languages, to say that equality is commutative is a completely valid and meaningful statement. Just as "2+3" gives the same result as "3+2", namely "5", and thus addition can be said to be commutative, so "2==3" gives the same result as "3==2", namely "false", and thus equality can be said to be commutative.
It's rather intellectually amusing, if you're of that frame of mind. Perhaps compiler writers have introduced a fundamental advance to mathematics without really thinking about it: unifying the concepts of "commutivity" and "symmetry".
I can't think of anything similar that could be said about reflexivity. Yes, a==a is true in Java, so equality is reflexive. It's not clear that a+a has any particular meaning or anything more interesting about it than a+b.
Admin
Yes, PHP can lead to really ugly programs. But a sufficiently determined programmer can write a PHP program in any language.
Admin