Pythonic indentation (or: beating a dead horse)

On 5/28/09, Eleanor McHugh [email protected] wrote:

Until I have time to study your code I’ll take your word for that.
Have you tried framing endless.rb as a patch for MRI’s lexer? and if
so how significant are the changes?

urk. I’m not familiar with the mri lexer code. In case I wasn’t clear
before, when I said that it was relatively easy to add to the lexer, I
meant my lexer. Of course everything is much less fun in c than it is
in ruby; 150 lines of rubylexer hacks might be equivalent to 600 lines
or more of c. On the other hand, since 1.9 is already warning about
misaligned ends, half of the code needed may be done already.

Then put out an [ANN] and if the community finds pythonic indentation
valuable, it’ll catch on.

Perhaps I should, but I did it more as a lark and to prove that it
could be done.

On May 28, 12:33 pm, Caleb C. [email protected] wrote:

I think the best way to assuage their
doubts would be for any change to have absolutely no impact on
existing code, with a clear distinction between old-style syntax and
new-style indentation-aware syntax.

You’re making an argument based on other people’s opinions, for which
you have no evidence. I rather doubt that the naysayers on this thread
will be much convinced by such a fine point.

Okay then, remove “assuage their doubts” and replace it with “pull the
teeth of their arguments.” It’s hard to argue against something that’s
completely optional. You can say that syntactic indentation is worse
than ‘end’ until you’re blue in the face, but how do you say that
having choices is worse than not having them?

Besides, I kind of like the look of the colon as a block-start
delimiter. It emphasizes the separation between the loop or
conditional or method call and the block it controls.

Ah, now we get down to it. It’s really all just a matter of taste.

No, seriously, this was an aside. I do prefer the look of having the
colon, but far more important than aesthetics is the fact that using a
colon (or other delimiter) would preserve compatibility with blocks
that have random indentation.

Would a semicolon make you just as happy? :wink: It looks almost the same
and can be used where you want a colon already:

while foo;
bar

I wouldn’t say it’d make me “just as happy”… I suppose I’d prefer it
to having no delimiter at all (and therefore not supporting blocks
that do not have canonical indentation) but the colon makes more sense
to me. Usually punctuation marks in programming languages at least try
to have some relation to their plain human-language meaning (foo?
foo!) and the colon means ‘here comes a bunch of stuff related to the
thing before the colon’.

Can you give an example of when you would want indentation to be
ignored that’s not overly weird looking to you?

I suppose I could but it seems tangential. Grep the Ruby standard
library and you’ll find hundreds of places which would break if
indentation were enforced, there are your examples. And besides, I’m
all in favor of choice. Even if freeform indentation is “overly weird
looking” to me, it may not be for someone else, who should have the
option of using it should he wish.

Okay then, remove “assuage their doubts” and replace it with “pull the
teeth of their arguments.” It’s hard to argue against something that’s
completely optional. You can say that syntactic indentation is worse
than ‘end’ until you’re blue in the face, but how do you say that
having choices is worse than not having them?

Because it confuses. And having confusion about significance of
the whitespace in a programming language is a VERY bad thing
to have.

Regards,
Rimantas

Would you be in favor of forcing the use of parentheses for functions and
semicolons at the end of lines instead of significant white space?

No. And I am even less in favour of having to count spaces at the
beginning of
the line.
Maybe I chose the wrong word. Well I want optional significant spaces
even less.

Regards,
Rimantas

On May 28, 2009, at 4:09 PM, Rimantas L. wrote:

to have.
Would you be in favor of forcing the use of parentheses for functions
and semicolons at the end of lines instead of significant white space?

On 28 May 2009, at 20:13, Caleb C. wrote:

misaligned ends, half of the code needed may be done already.
I’d say 150 lines of ruby more often ends up 1500 lines of C lol

Then put out an [ANN] and if the community finds pythonic indentation
valuable, it’ll catch on.

Perhaps I should, but I did it more as a lark and to prove that it
could be done.

Well the real proof of the pudding is in figuring out how to patch it
into the MRI and JRuby lexers as those are the majority of installed
ruby runtimes. If it proves easy to do and doesn’t muck up existing
functionality it would then be worth discussing over on [ruby-core]
and seeing what opposition it receives there.

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net

raise ArgumentError unless @reality.responds_to? :reason

On May 28, 2009, at 4:32 PM, Rimantas L. wrote:

Regards,
Rimantas

http://rimantas.com/

You’ll have to start shopping for a new language. White space is
already significant in Ruby.

Reid T. wrote:

I find this code less readable than the above original code with the
'end’s included

Same here.

Maybe, after enough exposure, I would get used to it, but I don’t see
anything intrinsic to that format that would make it more readable, and
currently (for whatever reasons) the endian version is more readable for
me.

FWIW, daring people to dispute what is ultimately a matter of opinion is
not terribly productive. I’ve had enough discussions with Haml lovers
to know that rounds of “But look how beautiful it is” vs “I find it
grating” go nowhere.

Maybe some verifiable proof that compulsory indentation makes for faster
apps or less buggy code or simpler IDE tool development or whatever
would make for a better case.

“I like it” lacks an element of persuasion.


James B.

www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff
www.neurogami.com - Smart application development

On Thu, May 28, 2009 at 1:33 PM, Caleb C. [email protected]
wrote:

You’re making an argument based on other people’s opinions, for which
you have no evidence. I rather doubt that the naysayers on this thread
will be much convinced by such a fine point.

For what it’s worth, when I got rid of indentation sensitivity in Reia
(by
adding “end” keywords) I got a lot of positive feedback from
indentation-haters, and no unsolicited cries to preserve it. I had to
encourage people to give feedback in defense of indentation sensitivity.

On May 28, 2009, at 12:21 AM, James B. wrote:

FWIW, daring people to dispute what is ultimately a matter of
opinion is not terribly productive. I’ve had enough discussions
with Haml lovers to know that rounds of “But look how beautiful it
is” vs “I find it grating” go nowhere.

Exactly. I prefer chocolate ice cream to python, and thai cuisine to
both.

Cheers–

Charles

Charles J.
Advanced Computing Center for Research and Education
Vanderbilt University

Tony A. wrote:

For what it’s worth, when I got rid of indentation sensitivity in Reia (by
adding “end” keywords) I got a lot of positive feedback from
indentation-haters, and no unsolicited cries to preserve it. I had to
encourage people to give feedback in defense of indentation sensitivity.

What was the reason for remove indentation sensitivity?

James

On May 27, 10:21 pm, James B. [email protected] wrote:

FWIW, daring people to dispute what is ultimately a matter of opinion is
not terribly productive.

Yeah, I realized that as soon as I posted. Sorry 'bout that. But look
at it this way.

In the example from AuthLogic I posted, which is real-world code and
not at all atypical, just under one-fourth of the non-blank, non-
comment lines consist of the bare word ‘end’. The ‘end’ keyword
doesn’t do anything. It’s just a signal to the parser that here is
the end of the block… and with canonical indentation, this is
something the parser is quite capable of inferring on its own. ‘end’
is redundant.

Code speaks louder, right? The whole point of writing code is to tell
the interpreter what you want it to do, and the whole concept of
‘expressiveness’ is based on being able to tell the interpreter what
you want it to do with a minimum of overhead. Let’s tell the
interpreter to do something:

1.upto 10 do |x|
p x

Stop! Don’t write another word. At this point, you’ve told the
interpreter exactly what you want. Using the bare minimum of code,
you’ve expressed with perfect clarity your intent. Anything you write
beyond that is superfluous. And if the language requires you to
write this extraneous code, it’s not as expressive as it could be.

I know it looks funny to a lot of people. It looked funny to me the
first time, too. As I said, my reaction when I first learned of
significant indentation was the same reaction I’ve seen from lots of
developers I’ve told about it: “what, are you kidding?” But it makes
sense. After a day or two of playing around with it, you’ll find that
it becomes second nature.

On Thu, May 28, 2009 at 6:52 PM, James B. [email protected]
wrote:

What was the reason for remove indentation sensitivity?

I was using a Python-style lexer in conjunction with a Ruby-like
(almost)
pure expression grammar, and running into the issues I’ve outlined in
this
thread regarding indent blocks in expressions.

I detailed many of the problems in this blog post:

I’m surprised by how well the solutions others are coming up for this
are
working. The script J Haas found just throws regexes at the problem
(and
removes any degree of formal decidability), however the RubyLexer
approach
sounds interesting.

That said, I have no regrets with ditching indentation sensitivity. If
anything it seemed to alienate people who would otherwise be interested,
and
now Reia has the advantage of looking nearly identical to Ruby. Porting
Ruby programs to Reia programs is now substantially easier.

Tony A. wrote:

Unlimited Novelty

I’m surprised by how well the solutions others are coming up for this are
working. The script J Haas found just throws regexes at the problem (and
removes any degree of formal decidability), however the RubyLexer approach
sounds interesting.

It seems that without formal decidability you’ll end up coding yourself
into a corner, where you can’t change or add anything because of the
side-effects.

That said, I have no regrets with ditching indentation sensitivity. If
anything it seemed to alienate people who would otherwise be interested, and
now Reia has the advantage of looking nearly identical to Ruby. Porting
Ruby programs to Reia programs is now substantially easier.

Very cool!


James B.

www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff
www.neurogami.com - Smart application development

“J Haas” [email protected] schrieb im Newsbeitrag
news:[email protected]

This was my point. It would be good to still have the option of
freeform indentation. Much Ruby code isn’t presently canonically
formatted, and it’d break if put through your preprocessor. One
solution to this would be to only activate the preprocessor on a per-
file basis, but I think a better solution would be for the
preprocessor not to damage existing code. The ultimate goal in the
long term should be to make this style part of core Ruby syntax rather
than the result of a preprocessor, and the best way to do that would
be for the parser to be able to distinguish between indentation-aware
blocks and “old-style” blocks.

If it would be strictly optional it would be fine.
Should be need to be explicitely allowed for not breaking existent code.
Maybe as gem possible.

However, Ruby is about 10 years old now, Python and its insertion is
even
older.
If it would be so superior, didn’t you think it would have been widely
accepted in the mean time?
And would have been spread over to other scripting languages already?

“Roger P.” [email protected] schrieb im Newsbeitrag
news:[email protected]

@Michael:
I don’t think having “either or” syntax would be such a terrible thing
in terms of team re-use or resources–you should be able to convert the
code back and forth at will (a la ruby2ruby, parsetree [rubylexer has a
parsetree compatibility mode] etc.)

Uuups, that’s me.
(BTW: What a discussion, about 2 vs. 20 … that’s really asymmetric
warfare…)

Yes, for sure it would be possible to convert sources back and forth and
up
and down.
Maybe someone would create the perfect converter.
Given there are people prefer PyI or not, maybe others loving brackets
the C
way or the Lisp way, or hating them, some would prefer do…end some
would
like curly brackets…
Going to the end: Convert Ruby code to P-Code which could be converted
to
F77… :wink:
(If some scripts are not located on read-only media…)

But, put joking aside, for much more sure, it would definitely increase
(IMHO) the probability of errors much more effective than other
variations
which are already possible.

My work since some year is to decrease probability of errors - I’m
creating
testing tools, environments and scripts, performing integrations tests
and
so on.

People tend to make mistakes. So, extending possibilities for doing so
is
baaaad.
Scripts are always changed, and nearly nobody really cares about
indendation
or formatting when scripts look like:

# Increase train speed to v_mode1
 @train.increaseSpeed 30

 # Pass signal 'sig1'
@train.expectPosition 'sig1',5


Did you really notice the different spaces? Try a proportional font.

or are created by some foreign language test case generation tools.

I don’t like unnecessary syntax elements for scripting languages,
because
they spoil the view for the real problems. So I like Ruby’s ability to
avoid
brackets, semicolons and so on.
Some people like brackets.
I like using “unless” instead of “if !” because it’s more readable, you
don’t need shift-key.
These possibility of variations did never brought problems into work.
It allows concentrate the attention of people to the real scenarios and
problems.

But, “end” brings much more safety, it is also a “social” thing - its
like
finally writing “done.”
I think, avoid scrolling is a very minor argument. Who needs to scroll
so
much?
Would “J” encourage people to avoid comments and empty lines to avoid
50% of
scrolling?
(Would “Monk” like “end”?)

I would not like to waste resources of highly specialized people by
teaching
them the last corners of Ruby - it’s a scripting language at last. And
it’s
wonderful as such.
So I would never try to force them to distinguish between spaces, tabs
and
other whitespaces.
(They would try - these are tolerant people too…)

(Ohh … sorry … I wasted my resources. Only 3 hours to sleep. Going
to
sleep now…)

Hope you got my point…

Regards,
Michael B.

“Juan Z.” [email protected] schrieb im Newsbeitrag
news:[email protected]

Maybe I chose the wrong word. Well I want optional significant

Did somebody tried Brainf*ck language?

On May 28, 2009, at 10:00 PM, Michael Bruschkewitz wrote:

No. And I am even less in favour of having to count spaces at the

You’ll have to start shopping for a new language. White space is
already significant in Ruby.

Did somebody tried Brainf*ck language?
Now there’s a readable language!

However, Ruby is about 10 years old now, Python and its insertion is
even older.
If it would be so superior, didn’t you think it would have been
widely accepted in the mean time?
And would have been spread over to other scripting languages already?

You might. And you’d be right. Python is widely accepted. Python,
by every indication I’m aware of, is more popular than Ruby. TIOBE
lists Python is slightly more than twice as popular as Ruby
(Home - TIOBE
). And arguably, excluding any discussion of indentation, Ruby is a
better language. I’m told that at Google they won’t even let you
code in Ruby. They only allow a limited number of popular languages,
which includes Python but not Ruby.

On 28 May 2009, at 17:30, J Haas wrote:

I know it looks funny to a lot of people. It looked funny to me the
first time, too. As I said, my reaction when I first learned of
significant indentation was the same reaction I’ve seen from lots of
developers I’ve told about it: “what, are you kidding?” But it makes
sense. After a day or two of playing around with it, you’ll find that
it becomes second nature.

You might just as well tell the Lisp community that all those brackets
they use are redundant. You might well find some converts, but I
suspect most people would look at you with a mix of incomprehension
and revulsion. In a certain sense Lisp is the brackets.

So contrary to how you feel about this, one size doesn’t fit all -
especially not in matters of aesthetics. Indeed I suspect that much of
the resistance that you’ve experienced in this thread is a reflection
of the fact that your original post and this one both show an equal
lack of awareness of that fact.

Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net

raise ArgumentError unless @reality.responds_to? :reason