Spin and Implied Scope Blocks
TinkersALot
Posts: 535
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
·
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
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
Click here to see my Nomad Build Log
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....
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
Click here to see my Nomad Build Log
<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.
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.
-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
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!
..Steve
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
Though perhaps in keeping with the topic you might write it:
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
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:
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.
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.
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?
I'm pretty much in agreement with your #2 as well. I might also preclude indents where they don't do anything, viz:
-Phil
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
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Post Edited (heater) : 6/5/2010 10:21:09 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
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.
@heater I loathe tabs except in makefiles where I have no choice.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Pages: Propeller JVM
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.