Shop OBEX P1 Docs P2 Docs Learn Events
Spin2 Operator Syntax - Page 4 — Parallax Forums

Spin2 Operator Syntax

1246718

Comments

  • Heater.Heater. Posts: 21,230
    I vote for just !=
  • cgraceycgracey Posts: 14,206
    Heater. wrote: »
    I vote for just !=

    Done.
  • cgracey wrote: »
    What about supporting both <> and != for inequality? Just go with != ?
    To minimize confusion I would go with just a single operator for each operation. If an operator is different people will think the semantics are different as well. What real advantage do you get by having these synonyms?
  • One advantage to supporting the old operators is the ability to port Spin1 code to the P2 without a lot of changes. On the other hand, it is likely that almost all Spin1 programs will require some changes to run on the P2, so maybe it's not a big deal to convert the operators as well. Someone will just need to write a converter program to automate the process.
  • kwinnkwinn Posts: 8,697
    cgracey wrote: »
    What about supporting both <> and != for inequality? Just go with != ?

    If both symbols are used in other languages then it makes sense to support both. Either one seems clear enough to me.
  • kwinn wrote: »
    cgracey wrote: »
    What about supporting both <> and != for inequality? Just go with != ?

    If both symbols are used in other languages then it makes sense to support both. Either one seems clear enough to me.
    By that logic Spin2 should also support {} and BEGIN / END for block structure in addition to indentation. I think each language makes its own choices about these syntax issues. It doesn't make sense to try to be all things to all people.

  • kwinnkwinn Posts: 8,697
    David Betz wrote: »
    kwinn wrote: »
    cgracey wrote: »
    What about supporting both <> and != for inequality? Just go with != ?

    If both symbols are used in other languages then it makes sense to support both. Either one seems clear enough to me.
    By that logic Spin2 should also support {} and BEGIN / END for block structure in addition to indentation. I think each language makes its own choices about these syntax issues. It doesn't make sense to try to be all things to all people.

    I was referring to this list of operators.
    !       NOT
    &&      AND
    ||      OR
    ^       XOR
    <<      SHL
    %       MOD
    [b]=<   <=
    =>      >=[/b]
    <>      !=
    
    Based on the single character operators != is just as clear if not more so than <> as the not equal operator. The same is true of other logically consistent combinations. How is >= for greater than or equal any less valid or harder to understand than => equal to or greater than. Same is true of other combinations. That does not mean that a lot of illogical or poorly chosen symbols should be added just because they are used in other languages.
  • I vote both for inequality.
  • Heater.Heater. Posts: 21,230
    I thought the idea was to harmonize the operators in line with many other very popular languages, C, C++, C#, Java, Javascript and more. Thus minimizing confusion for the vast majority of people coming to Spin, who will most likely have experience in one of those common languages already.

    To minimize confusion for those new to programming and starting with Spin there should only be one way to write each operator.

    Those operators that are Spin specific, not found in other languages, should have function or keyword syntax. Not cryptic symbols.
  • Looks like only one is supported. I just caught up.

    :D

  • kwinn wrote: »
    David Betz wrote: »
    kwinn wrote: »
    cgracey wrote: »
    What about supporting both <> and != for inequality? Just go with != ?

    If both symbols are used in other languages then it makes sense to support both. Either one seems clear enough to me.
    By that logic Spin2 should also support {} and BEGIN / END for block structure in addition to indentation. I think each language makes its own choices about these syntax issues. It doesn't make sense to try to be all things to all people.

    I was referring to this list of operators.
    !       NOT
    &&      AND
    ||      OR
    ^       XOR
    <<      SHL
    %       MOD
    [b]=<   <=
    =>      >=[/b]
    <>      !=
    
    Based on the single character operators != is just as clear if not more so than <> as the not equal operator. The same is true of other logically consistent combinations. How is >= for greater than or equal any less valid or harder to understand than => equal to or greater than. Same is true of other combinations. That does not mean that a lot of illogical or poorly chosen symbols should be added just because they are used in other languages.
    They are all easy enough to understand. However, having only a single operator per operation will make it easier for one person to read another's code and also make it easier for people coming from languages with similar operators.

    How do you say "=>" in English? Do you really say "equal to or greater than"? I've always said "greater than or equal to".

  • I often say the former, FWIW
  • David BetzDavid Betz Posts: 14,516
    edited 2017-04-11 16:10
    potatohead wrote: »
    I often say the former, FWIW
    That's interesting. In any case, I guess the idea is to use operators that are familiar to C, C++, Java, Javascript, etc programmers.

  • Yeah, I suspect this kind of thing is regional and cultural. How we hear it is how we say it, most often.
  • David Betz wrote: »
    kwinn wrote: »
    cgracey wrote: »
    What about supporting both <> and != for inequality? Just go with != ?

    If both symbols are used in other languages then it makes sense to support both. Either one seems clear enough to me.
    By that logic Spin2 should also support {} and BEGIN / END for block structure in addition to indentation. I think each language makes its own choices about these syntax issues. It doesn't make sense to try to be all things to all people.

    Yes!!! Please add a mode switch so that we can use {} and also use ; at the end of the line so we can pack more multiple statements per line. :)
  • cgraceycgracey Posts: 14,206
    Potatohead pointed out a conflict with % and binary number declarations. I don't want to loose %0101_1111, so % cannot be modulus. What about using // or MOD for modulus?
  • cgracey wrote: »
    Potatohead pointed out a conflict with % and binary number declarations. I don't want to loose %0101_1111, so % cannot be modulus. What about using // or MOD for modulus?
    Since you're already drinking the Kool-Aid I guess you could go to 0bXXXX for binary and 0xXXXX for hex. :-)

  • cgraceycgracey Posts: 14,206
    David Betz wrote: »
    cgracey wrote: »
    Potatohead pointed out a conflict with % and binary number declarations. I don't want to loose %0101_1111, so % cannot be modulus. What about using // or MOD for modulus?
    Since you're already drinking the Kool-Aid I guess you could go to 0bXXXX for binary and 0xXXXX for hex. :-)

    That's just too ugly. I hate seeing hex and binary numbers all cluttered up with that awful syntax.
  • cgracey wrote: »
    David Betz wrote: »
    cgracey wrote: »
    Potatohead pointed out a conflict with % and binary number declarations. I don't want to loose %0101_1111, so % cannot be modulus. What about using // or MOD for modulus?
    Since you're already drinking the Kool-Aid I guess you could go to 0bXXXX for binary and 0xXXXX for hex. :-)

    That's just too ugly. I hate seeing hex and binary numbers all cluttered up with that awful syntax.
    Yeah, it is kind of ugly. I didn't really expect you to go for it. Given that, either of the syntaxes you proposed should be okay.

  • Either is fine. I'm partial to MOD myself.
  • cgraceycgracey Posts: 14,206
    David Betz wrote: »
    cgracey wrote: »
    David Betz wrote: »
    cgracey wrote: »
    Potatohead pointed out a conflict with % and binary number declarations. I don't want to loose %0101_1111, so % cannot be modulus. What about using // or MOD for modulus?
    Since you're already drinking the Kool-Aid I guess you could go to 0bXXXX for binary and 0xXXXX for hex. :-)

    That's just too ugly. I hate seeing hex and binary numbers all cluttered up with that awful syntax.
    Yeah, it is kind of ugly. I didn't really expect you to go for it. Given that, either of the syntaxes you proposed should be okay.

    Thanks. That's quite an admission about C you made there, Dave.
  • cgraceycgracey Posts: 14,206
    potatohead wrote: »
    Either is fine. I'm partial to MOD myself.

    Okay. Thanks.
  • Heater.Heater. Posts: 21,230
    cgracey,
    That's quite an admission about C you made there, Dave.
    Ha! Yes, C is perhaps not the prettiest thing in the world. But it's conventions are everywhere.

    What bugs me is the use of "=" as an assignment.

    In mathematics, where "=" comes from, x = y is does not mean set x to the value of y. It is a statement of fact that x is actually the same as y.

    Which is why other languages use ":=" or such for assignment.

    But that is even more ugly.
  • cgracey wrote: »
    David Betz wrote: »
    cgracey wrote: »
    David Betz wrote: »
    cgracey wrote: »
    Potatohead pointed out a conflict with % and binary number declarations. I don't want to loose %0101_1111, so % cannot be modulus. What about using // or MOD for modulus?
    Since you're already drinking the Kool-Aid I guess you could go to 0bXXXX for binary and 0xXXXX for hex. :-)

    That's just too ugly. I hate seeing hex and binary numbers all cluttered up with that awful syntax.
    Yeah, it is kind of ugly. I didn't really expect you to go for it. Given that, either of the syntaxes you proposed should be okay.

    Thanks. That's quite an admission about C you made there, Dave.
    I never claimed that C was the perfect language. I use it mainly because I can write code and if I'm careful it ports reasonably easily to other platforms. Also, much of the open source code on the web is written in C or C++.

  • jmgjmg Posts: 15,175
    cgracey wrote: »
    What about supporting both <> and != for inequality? Just go with != ?
    Is there a conflict here ?
    Why not support both ?
    A Math teacher will understand <>, whilst a C programmer will understand != (aka not equal)
    Which is your main audience here, people already immersed and skilled in C ? or those in Education, and a broader audience ?
  • jmgjmg Posts: 15,175
    David Betz wrote: »
    cgracey wrote: »
    What about supporting both <> and != for inequality? Just go with != ?
    To minimize confusion I would go with just a single operator for each operation. If an operator is different people will think the semantics are different as well. What real advantage do you get by having these synonyms?
    The advantage is ease of understanding to those not skilled in C.
    I can understand that someone who is skilled in C, sees any other language as clutter, but I believe Parallax have a much wider audience here.
    Some care is needed to not morph Spin into a straight jacket of almost-C, and along the way lose the readability gains that Chip has made on these revised operators.

  • jmg wrote: »
    cgracey wrote: »
    What about supporting both <> and != for inequality? Just go with != ?
    Is there a conflict here ?
    Why not support both ?
    A Math teacher will understand <>, whilst a C programmer will understand != (aka not equal)
    Which is your main audience here, people already immersed and skilled in C ? or those in Education, and a broader audience ?
    A math teach will not use either. He/she will use an equal sign with a slash through it.

  • jmgjmg Posts: 15,175
    cgracey wrote: »
    Potatohead pointed out a conflict with % and binary number declarations. I don't want to loose %0101_1111, so % cannot be modulus. What about using // or MOD for modulus?

    // is already widely used, in many languages, as a comment to end of line.

    I'm not sure % is entirely lost ? - as 12 MOD 4 or 12 % 4 is understood by the parser.
    ie the white space makes it quite clear what use % has ?


  • jmg wrote: »
    David Betz wrote: »
    cgracey wrote: »
    What about supporting both <> and != for inequality? Just go with != ?
    To minimize confusion I would go with just a single operator for each operation. If an operator is different people will think the semantics are different as well. What real advantage do you get by having these synonyms?
    The advantage is ease of understanding to those not skilled in C.
    I can understand that someone who is skilled in C, sees any other language as clutter, but I believe Parallax have a much wider audience here.
    Some care is needed to not morph Spin into a straight jacket of almost-C, and along the way lose the readability gains that Chip has made on these revised operators.
    I would rather see Spin2 use just => and =< than use both the C-style operators and the old Spin-style operators.

  • jmgjmg Posts: 15,175
    potatohead wrote: »
    Either is fine. I'm partial to MOD myself.
    Yes, certainly keep MOD, and that is the one I'd use by default. Where I have to use %, there is usually a comment added to say Modulus anyway :)
Sign In or Register to comment.