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

Spin2 Operator Syntax

1121314151618»

Comments

  • cgracey wrote:
    The ternary ? is much more efficient: ...

    I agree.

    -Phil
  • jmgjmg Posts: 15,140
    cgracey wrote: »
    The ternary ? is much more efficient:

    a =: flag ? b : c

    This efficiency scales with compound ternaries.

    The code generated by both forms should be identical, and it is proposed as a sytnax-alternative of the same decision, so I'm not follow the "much more efficient" claim ?
  • Not sure, but Chip may just mean the ease of typing, as well as being able to pack more into available screen columns.
  • Heater.Heater. Posts: 21,230
    edited 2018-01-20 01:06
    Personally I think ternary operators should be be removed altogether. From all programming languages everywhere.

    As jmg says the code generated by a human readable "if ... then ...else..." should be the same.

    Ternary operators are just a twist in the syntax, an extra complexity, that is not really needed.

    Yeah I know, it's less characters to type in the source. So what? The time saved in typing is passed on as extra time for the reader to figure out what is going on.









  • Roy ElthamRoy Eltham Posts: 2,996
    edited 2018-01-20 01:42
    Chip,
    I really like the ternary ? operator as you show here. It's really concise and easy to read. Please stick with it.

    Heater,
    We all know you hate it, please stand down. It's not going away. As I said above, I think x := e ? a : b is what easier to read/parse, maybe because I've been using it for the better part of 4 decades?

    jmg,
    Sure the spin compile result should be the same, but the compiler code to parse it and handle it will be more work, for sure. Probably not a super lot, but more. It also becomes more cumbersome with nesting.
  • jmgjmg Posts: 15,140
    Roy Eltham wrote: »
    jmg,
    Sure the spin compile result should be the same, but the compiler code to parse it and handle it will be more work, for sure. Probably not a super lot, but more. It also becomes more cumbersome with nesting.

    I agree, not a super lot, but remember this was in the context of suggestions the parser infer which ? applies, from context, which sounds like even more work to me.. ? can mean many things....
    Catching an if following an assignment operator, is rather less context work.
  • Roy ElthamRoy Eltham Posts: 2,996
    edited 2018-01-20 03:52
    jmg,
    I hope Chip leaves it so that ? for ternary, and ?? is the random. makes it much more clear at a glance and easier to parse.

    Phil always wants more "inferring" things from context Smile. He should write his own compiler and see how hard that is to actually do in the real world.
  • now
    Roy Eltham wrote: »
    Chip,
    I really like the ternary ? operator as you show here. It's really concise and easy to read. Please stick with it.

    Heater,
    We all know you hate it, please stand down. It's not going away. As I said above, I think x := e ? a : b is what easier to read/parse, maybe because I've been using it for the better part of 4 decades?

    jmg,
    Sure the spin compile result should be the same, but the compiler code to parse it and handle it will be more work, for sure. Probably not a super lot, but more. It also becomes more cumbersome with nesting.

    I do too. The concise, and permissive nature of SPIN is what I appreciate most.

    Guys, SPIN has a character, ways of working that present a strong set of tradeoffs.

    I know it looks like a cleanup opportunity to some of you. Understandable, but please also understand it's breaking something valuable, flexible, efficient and potent to people who use it a lot.

    Had SPIN+PASM been what is often suggested, I would have never looked at a P1. Lots of us out there who want it that way for P2. :D

    Needs to exist.

    Once Chip does it the way he does it, which does impact the language in ways those of us want it for P2 really get benefit from, Roy will do OpenSpin.

    At that point?

    Show us your best! Who knows? Could be golden.

    And, C will get done too.

    At that point, game on!

    There is no need to bend SPIN away from it's roots now. Lots of us want it to exist.





  • cgraceycgracey Posts: 14,131
    Roy Eltham wrote: »
    jmg,
    I hope Chip leaves it so that ? for ternary, and ?? is the random. makes it much more clear at a glance and easier to parse...

    That is how I want it to be, too.
  • Heater.Heater. Posts: 21,230
    Oh Roy. I'm fully aware that nothing I say will make the cryptic ugliness of ternary operators go away. In Spin or any other language.

    I can match your four decades. Such things still cause my mind to stall when reading them.

    Experience tells me that good programmers love to save a few characters of typing with their obscure hieroglyphs. At the expense of legibility.

    Ah well.
  • Heater,
    It's interesting because I rarely try to save characters. I use long variable, function , and class names. I include extra white space (space between things and blank lines between chunks).
    I just find the ternary ? setup easy to read at a glance, and especially so for more complex constructs where the equivalent if/else//etc. setup just gets silly.

  • cgraceycgracey Posts: 14,131
    Imagine what a mess this would be without ?/:
    `regscan (slow_m, 3'b0,
    !ena || cmd && ~&ix[1:0] || slow_rw,				// rdbyte/rdword/rdlong/wrbyte/wrword/wrlong/wmlong
    	!ena				?	3'b000
    :	cmd	?	slow_spreadx	?	3'b101		// init, spread		-> 101
    		:	|nx		?	3'b110		// init, more		-> 110
    					:	3'b111		// init, last		-> 111
    
    :	slow_m[1:0] == 2'b11		?	3'b000		// busy, x11		-> 000, done
    :	|{n[17:1], n[0] && slow_spread}	?	3'b010		// busy, x01/x10	-> 010, more
    					:	3'b011)		// busy, x01/x10	-> 011, last
    
Sign In or Register to comment.