Shop OBEX P1 Docs P2 Docs Learn Events
Spin and Implied Scope Blocks — Parallax Forums

Spin and Implied Scope Blocks

TinkersALotTinkersALot Posts: 535
edited 2010-06-05 14:41 in Propeller 1
While still new to Spin, I'll admit that I am prone to rookie errors.

However, the "implied logical scope" that is defined by indent levels is, well, interesting.

Soft Rant·= On

Innocent Coder: "Simply reformatting code can lead to logic changes. Really?"
Seasoned Coder: "Um, Yep"
Innocent Coder: "Ah, well that is an interesting feature of the language. Wonder why they did it like that? Seems like an easy way to make all kinds of hard to detect bugs."
Seasoned Coder: "Um, Yep"

Soft Rant = Off





·

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-06-04 18:04
    Weclome to Spin, Grasshopper. You're at stage 2 now:

    1. What the ... ?

    2. Why?

    3. Oh, Okay.

    4. I love it!

    Maybe this will help you get to state 3: Think of all the vertical screen space that's saved by not requiring block terminators and how much more of your program you can see at one time.

    -Phil
  • TinkersALotTinkersALot Posts: 535
    edited 2010-06-04 18:06
    chuckle
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-06-04 19:48
    It took me a while to get used to the Spin syntax.· Make sure you turn on the block indicator in the Spin tool and it's not so bad.· I still get caught by statements like "if x <= y" when I should have used "if x =< y".· The first version actually means "if (x := x < y)", which is a perfectly acceptable Spin statement, and it usually takes me several hours to find the logical error.
  • John R.John R. Posts: 1,376
    edited 2010-06-04 20:29
    It still beats LISP (i.e. Lost In Stupid Parenthisis).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.
    Click here to see my Nomad Build Log
  • TinkersALotTinkersALot Posts: 535
    edited 2010-06-04 20:47
    Dave Hein,

    Your statements remind me of the topic of the abuse of operator overloading from the C++ world.

    As has been said by someone wiser than me. All languages are arcane to the un-initiated -- that's why its called code.

    Don't get me wrong, I think it is fun to learn new stuff; Thus my username on this forum. I was just feeling a bit pesky after fighting with a logic bug that snuck in when I was just trying to improve the 'readability' of what I working on.

    Completely my bad....
  • w8anw8an Posts: 176
    edited 2010-06-04 22:12
    Ooh... Please be nice to Lisp. Waltz Lisp was a Great And Powerful tool in CP/M.
  • John R.John R. Posts: 1,376
    edited 2010-06-04 23:23
    You mistake my comments for bashing the language. In the past I have worked with Common LISP and AutoLISP, and actually enjoyed working with them. I was just saying that the indentation of Spin is a piece of cake as opposed to the freaking parens. This was also back in the days of less than friendly editors in terms of finding matching (or not so matching) parens...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.
    Click here to see my Nomad Build Log
  • heaterheater Posts: 3,370
    edited 2010-06-05 00:05
    TinkersALot: Don't let them fool you with all this "grasshopper" stuff.

    <rant>
    There is no stage "3. Oh, Okay." unless they buy you a lot of beer first. Stage "4. I love it!" is of course loony tunes.

    Yes, the absence of block delimiter saves vertical screen space. So what? Who has such small screens now a days? Would you want to read a novel with no paragraphs and chapter boundaries, everything squashed into one blob of continuous text? No, of course not.

    Those who argue for white space block delimiting always fall back on "let the editor highlight the blocks for you" when you get confused. BINGO admission that they too need block delimiting help. Why not just put it in the code to start with for god sake?

    Now, it has been said that languages like Lisp have an intolerable amount of parentheses, can't argue with that. I would go further and say that languages like C and Pascal also have too many braces, brackets, "begin", "end" and semi-colon junk.

    Jack Crenshaw showed with his TINY and KISS example languages that it is possible to have all the block structure of C and Pascal like languages without most of that baggage. Yes, the brackets around expressions in C "if", "while" etc can be done away with. The semi-colons are redundant. The { and } or "begin" and "end" are not all required.

    It is possible to have all the compactness of white space delimited languages without actually having to use the madness that is white space delimiters.
    </rant>

    Rant over, sorry everyone.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-06-05 01:41
    heater said...
    Yes, the absence of block delimiter saves vertical screen space. So what? Who has such small screens now a days?
    What difference does screen size make? More visible code is more visible code, whether it's 25 lines or 60.
    heater said...
    Would you want to read a novel with no paragraphs and chapter boundaries, everything squashed into one blob of continuous text? No, of course not.
    Of course not, indeed. Total red herring, heater! That's what the indents are for. Besides, if you wan't to add blank lines or comment-style delimiters to pretty up your Spin code, no one is stopping you.

    I'm not quite sure how TINY is an example of lightweight syntactical baggage. It has ENDIF, ENDFOR, and ... well ... just END (to terminate a BEGIN, of course), which are not only as cluttery a braces but take longer to type.

    TinkersALot, don't let this little rant exchange sour you on Spin. Being a dyed-in-the-wool Perl programmer (i.e. Python-hater), I at first thought the white-space delimiters were nuts, too. But, as you can tell, they've grown on me. smile.gif

    -Phil
  • ScopeScope Posts: 417
    edited 2010-06-05 01:45
    I know I'm new to this stuff . . . but is someone talking about me in this thread . . . ? . . .
  • TinkersALotTinkersALot Posts: 535
    edited 2010-06-05 01:57
    No worries, Phil.

    I'm not discouraged. These exchanges can be useful as long as they remain respectful (and I hope my pesky post did not accidently rip a bandaid off a recovering wound) -- though I also recognize it is quite unlikely that spin will change because of it.

    Plus, believe me, this site is nothing like other forums I've seen. The sense of community spirit here is rare and astoundingly helpful.

    TinkersALot
  • w8anw8an Posts: 176
    edited 2010-06-05 03:06
    I personally used indentation to keep tract of all the parens in Lisp. Old dumb terminals didn't have much of an editor let alone software to track the parenthesis levels and matches. So being used to and preferring this layout for so many years makes me feel that Spin's indentation is practically a God send.

    Now I'm curious how Phi-Pi, the Python-hater, feels about Ruby? Ruby makes programming a computer almost as much fun as programming a Prop! yeah.gif

    ..Steve
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-06-05 06:43
    TinkersAlot said...
    I hope my pesky post did not accidently rip a bandaid off a recovering wound
    Not at all! We love ... um ... debating stuff like this -- not that we really solve anything by doing so. smile.gif
    w8an said...
    Now I'm curious how Phi-Pi, the Python-hater, feels about Ruby?
    I've never tried Ruby, but I really should. It would be hard to beat Perl's huge CPAN library, though. Like the Spin OBEX, it makes fast work out of apps that might otherwise be really messy to program from scratch.

    -Phil
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-06-05 07:49
    I do like the 'soft rant':
    Soft Rant = On
     
    Innocent Coder: "Simply reformatting code can lead to logic changes. Really?"
    Seasoned Coder: "Um, Yep"
    Innocent Coder: "Ah, well that is an interesting feature of the language. Wonder why they did it like that? Seems like an easy way to make all kinds of hard to detect bugs."
    Seasoned Coder: "Um, Yep"
    
    Soft Rant = Off
    
    



    Though perhaps in keeping with the topic you might write it:
    Soft Rant = On
    
        Innocent Coder: "Simply reformatting code can lead to logic changes. Really?"
        Seasoned Coder: "Um, Yep"
        Innocent Coder: "Ah, well that is an interesting feature of the language. Wonder why they did it like that? 
        Seasoned Coder: "Um, Yep"
    
    



    Depending on one's coding background, does that still leave rant mode on? [noparse];)[/noparse]

    I haven't completed PhiPi's 4 step program to recovery yet. Still stuck on step 2. Though there are other solutions, Catalina C, Propbasic and the wonderful language of PASM.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
  • heaterheater Posts: 3,370
    edited 2010-06-05 08:09
    No worries TinkersAlot. It's a recurring scuffle that has happened here and on other forums a million times. There is no resolution to these aesthetic differences. It will happen again.

    Phil, you are right about TINY. If I remember correctly Jack explores many syntactic choices in language design and then the final TINY spec included IF..BEGIN..END..ENDIF..ENDFOR etc.

    However a long the way he shows how to use { and }, or whatever you like, instead. He shows how to make semicolons redundant and so on.

    What I was alluding to was the extreme case where you could write something like:

    if a < b
        c = d
    else
        c = e
    end
    
    



    No semicolons here, no "begin" or "then" after the "if". The "if" statement looks like it relies on the end of line to delimit it from the conditional block but it does not. The parser knows when the "if" expression is complete and the first block expression starts. You could write this program all on one line.

    I once put together a version of the Jacks KISS language generating asm code for x86. Unless it's still sitting on an old hard drive some where I seem to have lost it. Always wanted to adapt it for the Prop.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • heaterheater Posts: 3,370
    edited 2010-06-05 08:34
    Phil: I've been thinking...

    There are a couple of things that could get me to your step "3. Oh, Okay." and possibly even to the step 4 "la la" land[noparse]:)[/noparse]

    If one is going to promote white space to the status of normal printable characters then one should impose some rules on white space like one does for the others. That is the compiler should impose some rules.

    For example:

    1) Thou shalt not mix spaces and tabs when indenting code blocks.
    or better still
    1) Thou shalt only uses spaces for indenting.
    2) Thou shalt be consistent with thine indenting. Eg a program will use n spaces per indent level everywhere.
    n could be a compiler option. If n is set to 4 and a line starts after 3 spaces it's an error.

    I would like to have the compiler complain, if only warn, about breaking these rules.

    BradC..where are you...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-06-05 08:47
    heater,

    Your #1, at least, is already covered by Spin, since all tabs are converted to spaces on the fly. Does that get to to stage 3? smile.gif

    I'm pretty much in agreement with your #2 as well. I might also preclude indents where they don't do anything, viz:

    a := 1
      b := c
    x := y
    
    
    


    -Phil
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-06-05 09:42
    I like heater's suggestion of trying to standardise things.

    In an ideal world the IDE could take a program with no indents at all and put in the indents correctly and automatically, and fix indents that have not been put in correctly. I don't think Spin can do that, as there are ambiguities in the syntax. vb.net (and other .net languages) can do this (so it is not impossible) and it has been one of the big things compared with old qbasic that make programming so much easier. There is now a vb.net indent standard because the IDE automatically does the standardising.

    And auto insertion of endif when you type 'if' is another bonus that speeds up writing code. The IDE starts to do the scope blocks for you.

    How could/would you do that for Spin? Probably not possible. But I started pondering this when looking at Femtobasic which can be written and interpreted on the propeller itself and maybe this lends itself to 'FemtoSpin'. Many of the keywords in femtobasic do translate one to one into spin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
  • heaterheater Posts: 3,370
    edited 2010-06-05 10:11
    Dr_A: "In an ideal world the IDE could take a program with no indents at all and put in the indents correctly..."

    That ideal world has existed for a long time for C, C++ and other language programmers. Even without and IDE there are "pretty printer" programs that will reformat your C etc code to conform to some desired layout style. Don't like the indenting and brace positioning in my C++ code, just run it through bcpp and reformat it how you like.

    You are right, this "pretty printing" is impossible for languages like Spin. Auto indenting could be done to some extent, automatically insert spaces and position the cursor for indented blocks after "if", "repeat" etc.

    But this ambiguity that you mention is at the heart of why I may get to (or be at) Phils level "3. Oh, Okay." but am unlikely to get to the step 4 la-la land.

    Phil: "...might also preclude indents where they don't do anything..."

    Yes that's exactly what rule 2) is for.

    With an enforced indenting rule spacing screw ups like the following are less likely to occur and so you don't have to wrack your brain again to figure out what you meant to write so often.

      if pa == 0
        ser.str(string("Bla bla bla.."))
       ser.hex(va,8)
      ser.str(string("Bla Bla Bla"))
        return
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.

    Post Edited (heater) : 6/5/2010 10:21:09 AM GMT
  • KyeKye Posts: 2,200
    edited 2010-06-05 13:33
    I don't understand how you guys screw up the indenting. I've never had propblems with that. Maybe its because I'm still young. =)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-06-05 13:57
    I've been thinking about that - maybe it is because we are using BST and it doesn't show those little indent arrows. So you are guessing about the structure most of the time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.smarthome.viviti.com/propeller
  • heaterheater Posts: 3,370
    edited 2010-06-05 14:30
    Kye: "Maybe its because I'm still young."

    Cheeky blighter[noparse]:)[/noparse]

    But you have a point. Not so much just age but after years of not having to worry so much about spaces in traditional languages it's a new habit that has to be acquired.

    Fortunately I've always been a bit compulsive about indentation, lining up columns in tables and general formatting in source code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • jazzedjazzed Posts: 11,803
    edited 2010-06-05 14:36
    @Dr A when will you turn off your rant?
    @heater I loathe tabs except in makefiles where I have no choice.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Pages: Propeller JVM
  • heaterheater Posts: 3,370
    edited 2010-06-05 14:41
    Yeah. Anyone know why it has to be tabs in makefiles?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
Sign In or Register to comment.