Slashdot Mirror


Symbolic vs. Mnemonic Relational Operators: Is "GT" Greater Than ">"?

theodp writes: "Mnemonic operators," writes SAS's Rick Wicklin as he weighs the pros-and-cons of Symbolic Versus Mnemonic Logical Operators, "tend to appear in older languages like FORTRAN, whereas symbolic operators are common in more recent languages like C/C++, although some relatively recent scripting languages like Perl, PHP, and Windows PowerShell also support mnemonic operators. SAS software has supported both operators in the DATA step since the very earliest days, but the SAS/IML language, which is more mathematically oriented, supports only the symbolic operators. Functionally, the operators are equivalent, so which ones you use is largely a matter of personal preference. Since consistency and standards are essential when writing computer programming, which operators should you choose?"

47 of 304 comments (clear)

  1. Of course! by i.r.id10t · · Score: 2

    Of course a Gin & Tonic is greater than some symbol

    --
    Don't blame me, I voted for Kodos
    1. Re:Of course! by cellocgw · · Score: 3, Funny

      Of course a Gin & Tonic is greater than some symbol

      Yes! Cue the blonde joke: "I'll have a Fifteen." bartender: "What?" blonde 'You never heard of a Seven and Seven?"

      thanks; try the veal.

      --
      https://app.box.com/WitthoftResume Code: https://github.com/cellocgw
  2. Typing versus Reading by szczys · · Score: 2

    I think he's right about the mnemonics being easier to type. They're generally on dominant fingers and you use letters constantly (not so much with pipe, ampersand, great and less than). That being said, I do think the capitalization should be saved for constants, and scanning code with your eyes proves the symbology easier to pick out. Symbols are better.

    1. Re:Typing versus Reading by szczys · · Score: 2

      Just submitted this comment, but not that I think about it. If you want these to be easier to type you should set up your IDE to auto-replace the mnemonics. Type GT(space) and it gets replaces with '>'.

    2. Re:Typing versus Reading by phantomfive · · Score: 2

      The way I look at it, typing speed doesn't really matter (for programming). The bottleneck for my typing speed isn't how fast I type, it's how fast I think. In bad cases, it can take a couple weeks to write ten lines of code.

      I had a professor who couldn't touch type, he used hunt and peck. That is obviously suboptimal, but he was able to program fast even with that handicap.

      --
      "First they came for the slanderers and i said nothing."
    3. Re:Typing versus Reading by Archangel+Michael · · Score: 2

      > and 1 (X is bigger / greater than 1 )

      Almost everyone could figure it out ... in 3rd grade. If you had a teacher that understood math, they can make anything easy to understand. The problem is, most grade school teachers are VERY poor at basic math. And it shows.

      I'm in education, I see this first hand. Teachers who need calculators to do basic math. And we wonder why our kids can't do simple math anymore.

      --
      Agent K: A *person* is smart. People are dumb, stupid, panicky animals, and you know it.
    4. Re:Typing versus Reading by Xolotl · · Score: 4, Insightful

      The comparison operators > and < have been in use for four hundred years and are (or should have been) learned in primary school. They also work in any (human) language, not just in English, and map directly to what is used in mathematics. No one should be confused by them.

    5. Re:Typing versus Reading by pla · · Score: 2

      On the other hand, students and people in-general have gotten > and < confused for a long time.

      Call me crazy, but I expect a teensy bit more from a graduate of a 4-year university in a math-heavy major, than I do from 4th graders or the general public.

    6. Re:Typing versus Reading by grimmjeeper · · Score: 2

      That's the reason early C had trigraphs. So that you could get the job done on old mainframes that didn't have all of the symbols used by the language.

    7. Re:Typing versus Reading by Waffle+Iron · · Score: 5, Interesting

      On the other hand, students and people in-general have gotten > and < confused for a long time.

      Many decades ago, my first grade teacher explained that these symbols are like alligators: They choose to chomp on the bigger meal. I've never been confused on these symbols since that day.

  3. mnemonic assumes everyone speaks English by Anonymous Coward · · Score: 3, Insightful

    Stick to simple mathematical symbols for the basic comparators we've use since elementary school. Shame about the fucking mess with = and ==.

    1. Re:mnemonic assumes everyone speaks English by Alain+Williams · · Score: 4, Insightful

      I sometimes wonder how many zillions hours of programmer debugging time would have been saved if K&R had used ':=' for assignment (like Pascal) rather than '=' ? The number of times people have assigned rather than compared is huge.

    2. Re:mnemonic assumes everyone speaks English by alvinrod · · Score: 2

      It's less of an issue for the newer high level languages that are either strongly typed or don't implicitly treat numbers like a boolean. for example:

      int x = 5;
      if(x = 7)
      {
      foo();
      }

      This gets caught at compile time because x = 7 evaluates to an int which can't be used as a condition by itself.

      The only problem you get is if you have a case where x is a boolean type and you're doing assignment instead of comparison, but you shouldn't need to check (x == true) or (x == false) anyhow as you can just use (x) or (!x) respectively.

      Besides, if we had to use := instead of just =, we'd be complaining about the zillions of hours lost typing that extra keystroke when an '=' would be a perfectly serviceable operator choice because of course we're such good programmers and would never mistake the two for each other.

      Also, is there a way to get white-space in a /. post? It seems as though the non-breaking space is stripped out.

  4. Are there any non-English languages? by xxxJonBoyxxx · · Score: 4, Insightful

    Are there any non-English languages or anyone using the language for whom English is a challenge? If there are, the use of symbols would seem to be preferred over remembering what the first letters of "plus que" are in English. (FTW.)

    1. Re:Are there any non-English languages? by Anonymous Coward · · Score: 2, Interesting

      A bare minimum of English is needed for programming. If, else, switch, case, import and so on are hard to avoid.

      I would still argue that > is better than GT though. The reason is that reading the meaning from a symbol comes more natural to the brain than reading letters, which is then turned into a sound/word, which then is turned into a meaning. This mean a symbol like > takes less energy for the brain to read and it becomes easier and faster to read the code. Also using letters for variables and symbols for operators is also a way to make it easier to identify what is what.

      if ((varA > varB) && (varC > varD))
      if varA GT varB and varC gt varD

      It's not like readability is precisely the same for those two lines even though they are identical from a mathematical point of view.

      One more thing about reading symbol vs letters. Japan uses both symbols (kanji aka Chinese letters) and phonic (hiragana, which is sounds like in English) and since they are able to write the very same text with both systems, they study the effect of symbols vs sounds in writing. It turns out that symbols are faster to read. Even more interesting is it that they activate different parts of the brain, which mean it is possible to be dyslexic for sounds only, while symbol reading is unaffected. Clearly using symbols vs words is more than just "like to look at GT or >".

  5. Knowledge of English by ledow · · Score: 4, Insightful

    ">" is universally understood in mathematics
    "GT" relies on a knowledge of English, and what it stands for, and thus what it means.

    But the bigger question - WHY does any language created nowadays have hard-coded operator names? If you prefer >, why not just use that and make it equivalent to GT in whatever default settings you provide? Why are you constrained to the choice of operators given to you and the mnemonics they choose to use?

    However, arguing over it is pointless. Change if it you can, otherwise it doesn't matter. If you can change it, or overload it, or rename it, or macro-ise it as you like, than it doesn't matter either.

    1. Re:Knowledge of English by cfalcon · · Score: 3, Insightful

      Because code review

    2. Re:Knowledge of English by countach · · Score: 4, Insightful

      I don't know if the world needs even more unreadable code where people are overriding the basic operator names.

  6. Re:Wow, a paper about GT by prunus.avium · · Score: 4, Interesting

    We're on /.. By definition we're all wasting time....usually instead of working.

    That being said, this raises some interesting questions about how our brains parse the languages. Would a mnemonic like GT be simpler to parse than >.

    Of course, I think this brings up the question of first language. Someone with English and the Latin alphabet may find the mnemonics easier but someone for whom the Latin alphabet is not their primary alphabet might handle the operators better.

  7. Ignored after the first sentence by OverlordQ · · Score: 4, Interesting

    They unfortunately used perl as an example. While yes Perl does have both gt and > one is a string comparison and the other is a numerical comparison.

    --
    Your hair look like poop, Bob! - Wanker.
    1. Re:Ignored after the first sentence by Tablizer · · Score: 2

      Dynamically typed languages should somehow allow explicit type comparing. Perl has the right idea, but it's too easy to forget to use the right one, especially if you work with other languages.

      I'm starting to lean toward functions like str_gt(), num_gt(), etc. (or str_greaterthan();).

      Another option is something like: "str_cmp(a, '>', b)" and "num_cmp(a, '>', b)". I often make my own utility functions for such because the built in ones don't fit my needs. For example, I often compare strings first by trimming and then ignoring case. Rarely do I need to do case-sensitive comparison.

      One downside of rolling your own comparison functions is loss of efficiency, but app CPU is rarely the bottleneck in most apps I deal with.

    2. Re:Ignored after the first sentence by truckaxle · · Score: 3, Informative

      Perl has the right idea, but it's too easy to forget to use the right one, especially if you work with other languages.

      Actually it is quite easy to remember Perl's usage... The operator 'gt' uses strings and is used for a string comparison. The ">" is a math symbol and used for numeric comparison.

  8. Re:Do anything other than what Perl did by Anonymous Coward · · Score: 4, Informative

    In Perl, where there are both operators (e.g. gt and >), the textual one (gt) does a string comparison, while the mathematical one (>) does a numeric comparison, fairly consistently.

  9. Re:Do anything other than what Perl did by Anonymous Coward · · Score: 2

    ^ This. They are NOT doing the same thing. You are used to operators being overloaded to do very different things depending on context. Now, Perl does awful things with overloading in lots of other places but in this one place I think it gets it right. (I also think having a dedicated string concatenation operator is the way to do, not overloading + for that purpose.)

  10. It's all squiggles by OrangeTide · · Score: 3, Interesting

    It's all squiggles on the screen that I have to learn to interpret in the correct context.

    --
    “Common sense is not so common.” — Voltaire
    1. Re:It's all squiggles by azcoyote · · Score: 2

      It's all squiggles on the screen that I have to learn to interpret in the correct context.

      This is true. All letters are symbols, and all symbols require a context in order to interpret. Somebody above pointed out that > is universally understood in mathematics, and thus its universality seems to make it preferable to GT, which is based on English. But this can be misleading. In the long run, > is just as arbitrary as GT, and although the symbol is widely used in mathematics, that is no guarantee that it will retain a clear meaning forever. A context will always be necessary, and although mathematics provides a kind of easily-accessible and widely-dispersed context, the specific system of mathematics that we utilize today is still a culturally-developed system of symbolization, and hence it is neither truly universal nor immortal.

      At the same time, even the mathematical context may not adequately guarantee that the meaning of > is understood. In fact, it is questionable whether the strictly mathematical meaning of > is strictly at play in computer programming. The Perl gt operator already shows that the sphere of the meaning of "greater than" within programming can be wider than that which belongs to ordinary mathematics. In other words, the symbol > is borrowed from the context of mathematics, but this originary context is not the only context that determines the usage of this symbol within programming. It is always possible for this symbol to carry additional meanings not strictly intended by mathematical logic.

      The strength of C++, for example, is that you can define your own operators and how they operate upon particular data structures, such that > can mean anything you want it to mean. Of course it would be silly to use > to mean "less than," but one might use it to mean "greater than" in a way that is only analogous to the scalar numerical calculation; hence for example one could conceive of a "greater than" with regard to GPS coordinates that does not measure which coordinates are greater in sheer magnitude, but rather determines which are farther north.

      In short, no symbol is guaranteed in its meaning by an external relationship to another, distinct usage of the same symbol. It does not matter whether the symbol comes from written or spoken language, academic usage or common dialect, science or superstition; all symbols are determined in their meaning by context.

      --
      Incipiamus, fratres, servire Domino Deo, quia hucusque vix vel parum in nullo profecimus.
    2. Re:It's all squiggles by petermgreen · · Score: 2

      The strength of C++, for example, is that you can define your own operators and how they operate upon particular data structures

      IMO the weakness of C++ is that you can define how the provided operators work on custom types but you can't create new ones.

      The result is that the set of provided operators gets overloaded to have very different meanings.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
  11. Re:Do anything other than what Perl did by nogginthenog · · Score: 5, Funny

    ^ This

    Not This?

  12. Re:The problem is using operators for other things by johnw · · Score: 5, Insightful

    It's one thing to use ">" for "less than".

    That would be almost bound to cause confusion.

  13. Re:mnemonic assumes everyone speaks English+ by Ungrounded+Lightning · · Score: 2

    Shame about the fucking mess with = and ==.

    When I did a "desk language" (a notation for writing code on paper notes, which might have had a compiler written for it later), about the time C was being developed (but before I had access to it), one of the things I did was carefully avoid items like that. One thing I did was ban the bare equal sign.

    ":=" Replacement (also: like C, unary ops had before and after replacement forms - by adding : the same way C adds =, i.e. ":+" and "+:"
    "==" Equality
    "===" Equivalence (Two variables are aliases for the same storage. Think "union" but as a separate "put these two things in the same storage / use this symbol (perhaps as a different type) for the same bits as that one" declaration.)

    I also had the logical and bitwise operators swapped from the way C did it - because "||", "&&", etc. are mnemonic for a string of bits. (This proved to be the biggest stumbling block when I started coding in C.)

    --
    Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
  14. Agreed. Except the shell, editor by raymorris · · Score: 2

    > In bad cases, it can take a couple weeks to write ten lines of code

    Absolutely agreed. And my ten (or 100) lines do the same task that someone else's 3,500 lines did, and do it more elegantly, because I'm using meta-programming.

    On the other hand, at the shell, it's helpful if the typing is fast enough that it doesn't effect my train of thought, which can be fast for tasks I know. You mentioned hunt and peck. That ends up being think, stop, hunt, peck, stop, think, stop, hunt, peck, think, stop - breaking one's train of thought. There's a qualitative difference when you're just thinking and the typing takes place automatically, in another mental "thread".

  15. Re:Better as symbols for add and subtract by Dog-Cow · · Score: 2

    A symbology that requires one to read in a different direction based on the symbol would be extremely retarded and infinitely stupid.

  16. Not even correct. by whoever57 · · Score: 4, Informative

    He includes Perl as a language that has both symbolic and mnemonic operators, and says that functionally they are equivalent, but this isn't really correct. In Perl, for example, "==" is not the same as "eq": one is a numeric comparison, the other is a string comparison and for consistent results the correct operator must be used.

    --
    The real "Libtards" are the Libertarians!
    1. Re:Not even correct. by azcoyote · · Score: 4, Informative

      I can understand why one might dislike this distinction between string and numeric operators in Perl, but I personally like it a lot.

      Perl is an odd hybrid. On the one hand, it for the most part does not distinguish between different scalar data types syntactically (no strict declarations as in C++). This makes it a more casual language that is good for quick scripting within a limited environment (similar to JavaScript), but of course it could lead to confusion later on if a programmer reassigns variables to different data types on the fly. On the other hand, Perl solves potential confusions by using distinct operators for string and numeric operations. This means that (A) it is clear what is being done at any given point, and (B) it simplifies converting between numeric and string data types for on-the-fly operations. This is why Perl is amazing: you can do so much in a single, miniscule line of code, and yet everything you do is very clear and straight-forward in the syntax, however brief it is. Perl is thus capable to some extent of emulating one's flow of consciousness rather than requiring a strict, logical process according to clearly-defined data types. After all, my brain only seems to distinguish between string and numeric data types when I operate upon them (e.g. when I think about the number 2, I can freely flow between adding 3 to it and writing the number out as a word).

      --
      Incipiamus, fratres, servire Domino Deo, quia hucusque vix vel parum in nullo profecimus.
    2. Re:Not even correct. by Cederic · · Score: 3, Informative

      So you've averaged writing over a hundred lines of perl every day since Larry Wall first shared it?

      There's clearly something wrong with the language and/or you, but I'll be polite and avoid suggesting which.

    3. Re:Not even correct. by guestapoo · · Score: 2

      I'm not Perl expert, but I find more comfortable with Perl in text processing than others equivalent language. IMHO, it's faster and more flexible than Python.
      But sometimes, I need to re-read some of my Perl scripts to know how they work again.

  17. Re:Gamer here by jfdavis668 · · Score: 2

    I did too, but I was thinking the car, not the video game.

  18. Re:Do anything other than what Perl did by kjhambrick · · Score: 2

    What Perl did was definitely an improvement over /bin/sh where the nmemonic ( ex: -gt ) works on integers while the symbolic ( > ) works on strings ...

  19. Re:Wow, a paper about GT by grimmjeeper · · Score: 4, Informative

    I would agree with you except for the horrendous number of hours wasted tracking down places where a single equal was used in place of a double. While lexical analysis tools can catch it, and coding standards (like putting the constant/literal value on the LHS) will help, it's still an unnecessarily wide trap that catches too many people.

    There is little real benefit to allowing an assignment to be used as a member of an encompassing expression. In fact, that "feature" only promotes overly complex statements that are harder to read and debug. And with optimizing compilers being so good these days, there's no reason not to break a statement into smaller, more readable pieces.

  20. It's not a matter of preference by jdavidb · · Score: 3, Informative

    relatively recent scripting languages like Perl ... Functionally, the operators are equivalent, so which ones you use is largely a matter of personal preference

    That is not the case in Perl at all! In Perl, operators like gt and lt are for string comparisons, and operators like are for numeric comparisons. Since in Perl you can conveniently transmute numbers intro strings and vice versa, which operator you use can make a whole lot of difference!

  21. Re:Is it really a waste of time? by nmb3000 · · Score: 5, Insightful

    We could say ">", "GT" or "gt", or perhaps even "greater than."

    I disagree. I believe > is easier to parse while reading code since it separates it from identifiers, control statements, constants, numbers, and other keywords. It's the same reason && is better than "AND" in C syntax derivatives.

    I'd be quite pleased with a language that understood all three to be the same thing, with similar broad expression capabilities for everything else as well.

    Please, no. Syntactic sugar is one thing but creating multiple equivalent ways to express the same thing is just a readability, support, and maintenance nightmare.

    explicit and English-like for the newcomer.

    Which is how we got COBOL. It turned out that just making source code use lots (and lots) of English words isn't enough to allow laymen to understand it or make changes, so all you end up with is a language that programmers find exhausting to read and annoying to write.

    --
    "What do you despise? By this are you truly known." --Princess Irulan, Manual of Muad'Dib
    /)
  22. Re:Wow, a paper about GT by Darinbob · · Score: 2

    Why do those languages that use GT also use "+" instead of PLUS? a lot of times the reasons aren't about having words instead of symbols, but other pragmatic reasons. There were limitations on early punch card formats, the relevant symbols just may not have existed. IBM Model 026 keypunch did not support . And once you've got "EQ" to distinguish from "=" then it's much easier to use "GT" or "LT".

  23. Re:Wow, a paper about GT by Cederic · · Score: 2

    Just because they allow you to do this doesn't make it sensible, good programming or acceptable in any sane code base.

  24. Re:Do anything other than what Perl did by Daniel_Staal · · Score: 2

    I'd argue that the 'punctuation gone awry' view of Perl is largely because it was one of the first languages to fully embed regular expressions. While it has a fair number of different punctuation operators on it's own, nearly all are shared by other languages, and most of the rest are because the syntax has to differentiate between different types of variable operations, where more statically typed languages can let the types determine that.

    --
    'Sensible' is a curse word.
  25. Re:Wow, a paper about GT by grimmjeeper · · Score: 2

    That may have been true 20 years ago but modern optimizing compilers will generate the same output whether you embed your assignment in the conditional or do it separately.

  26. Blocking and non-blocking substitutions. by Ungrounded+Lightning · · Score: 2

    For completeness sake := is a blocking assignment. Meaning that the next instruction is not executed until the assignment is completed.

    You also want a non-blocking assignment. The actual assignment is delayed (and may be overridden in following non-blocking assignments).

    Had that: "=:", as with "+:" vs. ":+", etc. Like C's equal-sign-concatinated-with-unary-op semantics, the side the colon is on tells you whether the store occurs before or after the whatever.

    Equal sign in my language COULD have been considered a unary do-nothing/"make a local copy" operator (i.e. "foo", "= foo", "= = foo" etc. are all the same thing - except that all but the first might not be acceptable as the target of an assignment, or might result in the store being discarded) - except that, as a special case, a single equal sign was explicitly forbidden to stand alone in an expression.

    --
    Bantam Dominique roosters crow a four-note song. Once you've heard it as "Happy BIRTHday" you can't NOT hear it that way
  27. Re:Is it really a waste of time? by pauljlucas · · Score: 2

    It's the same reason && is better than "AND" in C syntax derivatives.

    Given that C has shorthands like ++, I've always wondered why K&R chose && for logical-and and & for bitwise-and. If it were the other way around, you'd save having to write the second & most of the time since one tends to write far more logical-and expressions than bitwise-and expressions.

    --
    If you reply, do so only to what I explicitly wrote. If I didn't write it, don't assume or infer it.