4 ms·
>Any thoughts? Yes. Model your language on Python except each level of indent must be exactly one space. Really?? Let's check... if am == serious: pri
by logicallee 8y ago
>Any thoughts?
Yes. Model your language on Python except each level of indent must be exactly one space.
Really?? Let's check...
if am == serious:
print "Really."
elif but == srs:
print "Haha. But really"
else:
print "This line actually a syntax error because wrong indent level."
Just my humble suggestion :)
EDIT: no fair downvoting, he said "any thoughts" and I gave some thoughts, with example.
- userbinator 8y agoI played around with various indentation styles and also eventually came to a preference of one space --- all the space savings(!) of tabs, with none of their odd behaviour. As an additional bonus, the column counter of the text editor doubles as a display of the indentation level. That said, when working with shared code I believe what's more important is "micro-consistency" : the exact style doesn't really matter, as long as it's not so inconsistent that it confuses someone inspecting a function or file. One or ten spaces, or tabs, all applied consistently are far better than things like misleading indentation or mixed tabs and spaces in the same block of code. http://www.richardrodger.com/2012/11/03/why-i-have-given-up-on-coding-standards/ http://www.richardrodger.com/2012/11/03/why-i-have-given-up-...
- logicallee 8y agoThanks for that feedback :) I suggested it because OP asked for suggestions and thoughts for their new language. I'm kind of peeved at the downvotes because at a minimum it's a reasonable idea to look into - as you've just confirmed, saying you've picked it as the best solution. I thought it's worth considering as the syntax solution for a new language! It's fully orthogonal and removes all style decisions. The compiler never has to guess. That actually means the IDE could be fully sure of it in every case and could let you adjust the tabs, as in this example I put together (using excel and a C program): https://imgur.com/a/s7zQMpw https://imgur.com/a/s7zQMpw ---- I chose my suggestion based on orthogonality. Originally I started suggesting 2-space tabs for OP's new languages (as a syntax feature), since they're a pretty common style convention used by many in the C world, so not totally absurd. But that is not fully orthogonal and hard to automate: if the compiler encounters 3 spaces, what is that supposed to be? Automatically a syntax error? How many indents is 6 spaces again? -- when you use 2-space tabs the answer is 3 //Guess below line's indent level (2-space indents) x With two-space tabs, the answer is 3: //This is indented how many? x a b c x but when you use 1-space tabs the same is: //Guess below line's indent level? (1-space indents) x //Answer: x a b c x You can just count, and it is visually also very clear. As mentioned your IDE can treat leading spaces as indents. (Visually indent them.) It's a 1:1 correspondence. Anyway just my humble suggestion for tomcam's new language, who solicited ideas with "Any ideas?". I gave actual code snippets in my original comment. :)
- tristanj 8y agoOne space indenting makes nested if statements and nested for loops a pain to read. Especially in long functions.
- deleted 8y ago[deleted]
- logicallee 8y agoHave you tried it? For how long? (Or on how much code, if you just tried a small snippet.)