• (cs) in reply to Buddy
    Buddy:
    Look, PHP is okay for simple things. IMHO PHP5 was a bad idea -- it encourages you to write OO, but as soon as try to implement a simple Factory pattern it falls apart.

    Anything more complicated than screen-scraping is a waste of time in PHP.

    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"

  • Dennis (unregistered) in reply to Buddy
    When the 'is equals' operator ceases to be commutative, then you're in for a world of hurt.

    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"

  • Buddy (unregistered) in reply to JDeepBeep
    JDeepBeep:
    Buddy:
    When I talk to him about maintainability, he feigns a language gap and pretends not to understand.

    You do what now?

    There's more than one Buddy. I suppose I should register it.

  • Buddy (unregistered) in reply to Dennis
    Dennis:
    ... Equality is symmetric - "a=b" implies "b=a"

    When the 'is equals' operator ceases to be symmetric, then you're in for a world of hurt.

  • (cs) in reply to Trevel
    Trevel:
    Nevermind that all of these stories that feature a so-called guru in Language X always ends up with the person writing shitty code.

    Uh, dude? Check what site you're on -- ALL the stories here end up with people writing shitty code. (Or some sort of hardware/management failure.) If you heard that some guy was a code guru in Language X and checked his functions and they were awesome, your story would not be told here. You'll have to go to AwesomeCodeStoriesForAwesomeCodeGurus.com to find that sort of story. Or more likely you'll find a DNS error (or if your ISP is evil, a search page -- which ought to be punishable by death)

    I join you in wishing death on Verizon. This annoyance results in me seeing a godaddy search page every time I mistype a URL, and having to retype the URL entirely instead of just correcting the typo and hitting enter again. I'm probably going to just tell my system to use 4.2.2.4 again soon.

    Adam:
    /me wipes tears of laughter from his eyes. Can you not see the "Quote" button? How about the "Preview" button?

    Now, let us go to Wikipedia and learn of this man "Muphry"!

    So, what did you learn about the Quote button and the Preview button again? ;)

  • (cs) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    And this is why anyone who calls themselves a "guru" should be fired immediately. Nevermind that all of these stories that feature a so-called guru in Language X always ends up with the person writing shitty code.

    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."

  • Gary (unregistered) in reply to strictnein

    So you're saying Facebook is not an major site?

  • Buffled (unregistered) in reply to m0ffx
    m0ffx:

    What isn't correct is

    "...their very own, in-house PHP Guru."

    The comma should either be absent or joined by another after 'in-house'.

    What's great about the English language is that people like you can just make up new rules, and most people reading it will believe you.

  • Duke of New York (unregistered)

    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.

  • plaga (unregistered) in reply to Gary
    Gary:
    So you're saying Facebook is not an major site?

    I'll gladly call that facebook site a major fuckup at least.

  • Keybounce (unregistered)

    Alright, this "Try switching the order around" made me actually try it.

    Kleiman-ibook:~ michael$ cat /tmp/test.php
    #!/usr/bin/php
    <?php
    $a = 0; $b = 'Hello';
    
    if ($a == false && $b == true && $b == $a) echo 'Universe broken.';
    ?>
    Kleiman-ibook:~ michael$ /tmp/test.php
    Universe broken.Kleiman-ibook:~ michael$ php --version
    PHP 5.2.6 (cli) (built: Sep 19 2008 11:28:54) 
    Copyright (c) 1997-2008 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
    Kleiman-ibook:~ michael$ 

    In other words: Switching the comparison around did NOT fix the universe.

    Mac 10.5.6

  • ounos (unregistered)
    Dave:
    ounos:
    For as long as he could remember, **one Millan C's clients**
    I hate to break the news, but your grammar skills are well below those of a baby ape. A baby jew ape, to be sure.

    Take your racist asshole stupidity elsewhere, ounos, it's not wanted here.

    You seem to be the only one complaining, lol!

    PS: wow, it works!!! Perhaps I should post more often random nazi/jew jokes!

  • m0ffx (unregistered) in reply to Buffled
    Buffled:
    m0ffx:

    What isn't correct is

    "...their very own, in-house PHP Guru."

    The comma should either be absent or joined by another after 'in-house'.

    What's great about the English language is that people like you can just make up new rules, and most people reading it will believe you.

    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."

  • Trerro (unregistered)

    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.

  • (cs)

    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.

  • BBT (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    And this is why anyone who calls themselves a "guru" should be fired immediately. Nevermind that all of these stories that feature a so-called guru in Language X always ends up with the person writing shitty code.

    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.

  • Procedural (unregistered) in reply to joe
    joe:
    ... I'm always impressed by the fact that people who say that PHP is a bad language, for it promotes odd inconvenient structures, is full of exceptions and incoherent rules, can be so readily abused, and therefore would and should be unpopular if it weren't for the great unwashed masses always choose to state those facts in English. ...

    And if that's how you write English, I'm glad I've never run into your code.

    Stupid Muphry's Law.

    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.

  • Not Telling (unregistered)

    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.

  • NegativeZero (unregistered) in reply to Kazan
    Kazan:
    PS: PHP isn't a bad language, it's however an EASY language - easy languages get a higher proportion of bad programmers.

    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.

  • (cs) in reply to Franz Kafka
    find me a computer that runs programs written in english.
    http://ask.com
  • (cs)

    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 ...

  • dogmatic (unregistered) in reply to strictnein

    wordpress? cmon wordpress is dogdoodoo.

  • dogmatic (unregistered)

    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.

  • OldHand (unregistered) in reply to Americium
    Americium:
    Adam:
    joe:
    ... I'm always impressed by the fact that people who say that PHP is a bad language, for it promotes odd inconvenient structures, is full of exceptions and incoherent rules, can be so readily abused, and therefore would and should be unpopular if it weren't for the great unwashed masses always choose to state those facts in English. ...

    And if that's how you write English, I'm glad I've never run into your code.

    Stupid Muphry's Law.

    /me wipes tears of laughter from his eyes. Can you not see the "Quote" button? How about the "Preview" button?

    Now, let us go to Wikipedia and learn of this man "Muphry"!

    Murphry's Law: Anything you do wrong will get commented on.

    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"...

  • (cs) in reply to OldHand
    OldHand:
    Americium:
    Murphry's Law: Anything you do wrong will get commented on.
    Is this an intentional misquote?
    Take another look at the name of the law. Americium has moved on to the next iteration.
  • ClaudeSuck.de (unregistered) in reply to my name is missing
    my name is missing:
    An expert is anyone 40 miles from home. A guru is anyone you wish was 40 miles away.

    so the gooroo would become an expert. Is this up- or downgrading?

  • (cs) in reply to Satanicpuppy
    Satanicpuppy:
    It's the way PHP handles form data that causes these issues.
    That explains why, when I submitted my form, all the formal parameters in the processing script changed to $a, $b, $c, ....
  • (cs) in reply to Trerro
    Trerro:
    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.
    Only mistake in the whole post. The result would be 19.

    (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.

  • OldHand (unregistered) in reply to Scarlet Manuka
    Scarlet Manuka:
    OldHand:
    Americium:
    Murphry's Law: Anything you do wrong will get commented on.
    Is this an intentional misquote?
    Take another look at the name of the law. Americium has moved on to the next iteration.

    Um. I see. Murfrys law: "Anything you do is wrong"?

  • (cs) in reply to Charles400
    Charles400:
    This comment is brilliant, you know!

    did you just misspell brillant?

  • (cs) in reply to AndyCanfield
    AndyCanfield:
    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 ...

    You forgot...

    NaN = FILE_NOT_FOUND

  • illtiz (unregistered) in reply to Paul
    Paul:
    Jay:
    I think Java is a way cool language. But nevertheless, while new Boolean("true") returns true and new Boolean("false") returns false as anyone would likely guess, new Boolean("really absolutely positively true") is in fact false, or perhaps more subtly, new Boolean("T") and new Boolean("true ") are false. The rules aren't all that difficult to learn, and if they are inconvenient in a particular situation, oh well, too bad.

    Actually, the real wtf with Java Boolean is the public constructor. Why would you ever need to define a new Boolean? I've lost count of the number of times I've had to change new Boolean("TRUE") to Boolean.TRUE when maintaining someone else's code.

    The reason? new Boolean("TRUE") breaks the equality operation.

    System.out.println(new Boolean("tRuE") == Boolean.TRUE); // displays false System.out.println(Boolean.valueOf("tRuE") == Boolean.TRUE); /// displays true System.out.println((new Boolean("tRuE")).booleanValue() == Boolean.TRUE.booleanValue()); // displays true

    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.

  • methinks (unregistered) in reply to anonymous_coder()
    anonymous_coder():
    You know, I've never understood the PHP-bashing. As an experiment, we wrote the same simple web app in Tomcat/Java, Python, and PHP. It took two weeks in Python - mostly fighting with the flash front-end. It took two days in PHP. And it took 5 days in Java.

    Frankly, crying about the language just means you lost your juicy contract to someone who undercut you on a web project proposal. I would never use PHP for anything other than web coding, but it excels at simple web applications.

    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.

  • Rocky (unregistered) in reply to illtiz
    illtiz:
    Paul:
    Jay:
    I think Java is a way cool language. But nevertheless, while new Boolean("true") returns true and new Boolean("false") returns false as anyone would likely guess, new Boolean("really absolutely positively true") is in fact false, or perhaps more subtly, new Boolean("T") and new Boolean("true ") are false. The rules aren't all that difficult to learn, and if they are inconvenient in a particular situation, oh well, too bad.

    Actually, the real wtf with Java Boolean is the public constructor. Why would you ever need to define a new Boolean? I've lost count of the number of times I've had to change new Boolean("TRUE") to Boolean.TRUE when maintaining someone else's code.

    The reason? new Boolean("TRUE") breaks the equality operation.

    System.out.println(new Boolean("tRuE") == Boolean.TRUE); // displays false System.out.println(Boolean.valueOf("tRuE") == Boolean.TRUE); /// displays true System.out.println((new Boolean("tRuE")).booleanValue() == Boolean.TRUE.booleanValue()); // displays true

    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.

    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.

  • methinks (unregistered) in reply to Kiss me I'm Polish
    Kiss me I'm Polish:
    Oh wait, Java sucks, you have no pointers and shit.

    Oh wait, that was an intentional decision and is in fact A Good Thing (R)!

    ;o)

  • methinks (unregistered) in reply to Paul
    Paul:
    Jay:
    I think Java is a way cool language. But nevertheless, while new Boolean("true") returns true and new Boolean("false") returns false as anyone would likely guess, new Boolean("really absolutely positively true") is in fact false, or perhaps more subtly, new Boolean("T") and new Boolean("true ") are false. The rules aren't all that difficult to learn, and if they are inconvenient in a particular situation, oh well, too bad.

    Actually, the real wtf with Java Boolean is the public constructor. Why would you ever need to define a new Boolean? I've lost count of the number of times I've had to change new Boolean("TRUE") to Boolean.TRUE when maintaining someone else's code.

    The reason? new Boolean("TRUE") breaks the equality operation.

    System.out.println(new Boolean("tRuE") == Boolean.TRUE); // displays false System.out.println(Boolean.valueOf("tRuE") == Boolean.TRUE); /// displays true System.out.println((new Boolean("tRuE")).booleanValue() == Boolean.TRUE.booleanValue()); // displays true

    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).

  • Anon (unregistered) in reply to Rocky

    [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.

  • Anon (unregistered) in reply to methinks
    methinks:
    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.

    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.

    So new Boolean("TRUE") does not "break the equality operation", it just simply does not create a Boolean-instance with the value "true".

    It does. new Boolean("TRUE").equals(Boolean.TRUE) does return true.

  • bd (unregistered) in reply to Watson
    Watson:
    Starting with the truism that of any given population of people, half of them have below-average intelligence for that population
    That's not a truism. A truism is "Watson is in the below-average group". (hint: normal distribution is not the only distribution)
  • (cs) in reply to methinks
    methinks:
    Kiss me I'm Polish:
    Oh wait, Java sucks, you have no pointers and shit.

    Oh wait, that was an intentional decision and is in fact A Good Thing (R)!

    ;o)

    i could ALMOST accept that if they allowed explicit memory releases on top of the garbage collection.

  • Patrick (unregistered)

    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.

  • Smurf (unregistered)

    I smurf you're smurfing the smurf with Smurfy's law: anything you smurf will be smurfed on.

  • (cs) in reply to Anon
    Anon:
    methinks:
    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.

    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.

    So new Boolean("TRUE") does not "break the equality operation", it just simply does not create a Boolean-instance with the value "true".

    It does. new Boolean("TRUE").equals(Boolean.TRUE) does return true.

    public static Boolean valueOf(boolean b) {
        return b ? Boolean.TRUE : Boolean.FALSE;
    }
    

    Better. Cheaper.

  • Buddy (unregistered) in reply to Kiss me I'm Polish
    Kiss me I'm Polish:
    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.

    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).

  • (cs) in reply to jonnyq
    jonnyq:
    Kazan:
    Buddy:
    DiverKas:
    Guru and php is pretty much an oxymoron isnt it?
    Pretty much. When a language evaluates (bool)'0', (bool)'' to FALSE but (bool)'false', (bool)'no', (bool)'0.0' to TRUE, you know you're in for a world of hurt.
    PS: PHP isn't a bad language, it's however an EASY language - easy languages get a higher proportion of bad programmers.

    As someone whose main qualification is PHP, I can say that PHP is a bad language. It's a very bad language that can be written well if you try hard enough.

    The truth shall set you free...

  • Anon (unregistered) in reply to JDeepBeep
    JDeepBeep:
    public static Boolean valueOf(boolean b) {
        return b ? Boolean.TRUE : Boolean.FALSE;
    }
    
    Better. Cheaper.

    But that does not really help if you are evaluating/parsing string representations....

  • Todo: register username (unregistered)

    Every programming language has it's own bugs. And no, bugs are not "language features".

    Flaming PHP is so old.

  • Jay (unregistered) in reply to Dennis
    Dennis:
    When the 'is equals' operator ceases to be commutative, then you're in for a world of hurt.

    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"

    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.

  • Jay (unregistered)

    Yes, PHP can lead to really ugly programs. But a sufficiently determined programmer can write a PHP program in any language.

  • (cs) in reply to kastein
    kastein:
    Trevel:
    Or more likely you'll find a DNS error (or if your ISP is evil, a search page -- which ought to be punishable by death)
    I join you in wishing death on Verizon. This annoyance results in me seeing a godaddy search page every time I mistype a URL, and having to retype the URL entirely instead of just correcting the typo and hitting enter again. I'm probably going to just tell my system to use 4.2.2.4 again soon.
    I feel for you and whatever Verizon service you're on, because for my business class FiOS (static IP), they told me to use 4.2.2.1 and 4.2.2.2

Leave a comment on “Can You Say Your $a, $b, $c's?”

Log In or post as a guest

Replying to comment #:

« Return to Article