Pythonic indentation (or: beating a dead horse)

E

Eleanor McHugh

Exactly. The concrete syntax should be purely a question of
presentation and user interface, that should be dealt with by the
editor. Source files could be kept in s-exp form, like it was
intended originally (50 years ago).

I got pulled from a project a couple of years ago for saying the same
thing about DNS records. Some people really do lack a sense of humour ;)


Ellie

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

Juan Zanos

It's interesting that Ruby doesn't force you to use semicolons all
over the
place like C or Java. You only use them were they are actually
necessary
disambiguate something. Ruby also doesn't force you to use
parentheses for
function definitions or function calls. Again, you only need them when
something is ambiguous. Ruby accomplishes these tricks by using
significant
whitespace. Optional 'end' seems very consistent with this philosophy.
 
J

Juan Zanos

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.

When was there ever great innovation in art that didn't cause anger
and revulsion? Currently the one size fits all is that you must use
end. It isn't a choice. Yes, you can be a second class citizen and
use a preprocessor. But how would you feel if the tables were
switched and new ruby forced you to not use end and your only
alternative was to use a preprocessor?
 
J

James Britt

J said:
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.

No, it's a signal to the human reading the code as well.
Code speaks louder, right? The whole point of writing code is to tell
the interpreter what you want it to do,

I'm with Harold Abelson and Gerald Jay Sussman on this point:


"Programs must be written for people to read, and only incidentally for
machines to execute."

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.

But we're back in the realm of subjectivity regarding what is "bare
minimum of code" and "superfluous". Ruby could be made quite terse, but
that's not a proper goal.

There is value in redundancy, and the trick is to find the right
balance, not to eliminate it completely.

Also, having more or less free reign on white space means I can express
non-computational information more easily by using unusual white space
to offset chunks of code or parameters to tell the reader, "Look, this
is important" at a glance.

Programming is a form of technical writing; judicious use of white space
is a critical means of communicating with the reader.


Some times I really do
want to do this.

This is a powerful option.

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.

That's the same argument I hear from Ham'l Qaeda; "Just give it more
time and you'll be enlightened in your ways". :)


My experience says otherwise



--
James Britt

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

James Britt

Juan said:
When was there ever great innovation in art that didn't cause anger and
revulsion?

My Over-the-top-O-meter just went over the top.

Currently the one size fits all is that you must use end.
It isn't a choice. Yes, you can be a second class citizen and use a
preprocessor. But how would you feel if the tables were switched and
new ruby forced you to not use end and your only alternative was to use
a preprocessor?


Drop Ruby and finally move to Haskell?


:)

--
James Britt

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

Juan Zanos

No, it's a signal to the human reading the code as well.


I'm with Harold Abelson and Gerald Jay Sussman on this point:


"Programs must be written for people to read, and only incidentally
for machines to execute."



But we're back in the realm of subjectivity regarding what is "bare
minimum of code" and "superfluous". Ruby could be made quite terse,
but that's not a proper goal.
Terseness is a perfectly reasonable goal. It's a corollary to Occam's
Razer.
No? If you're going to sacrifice conciseness you should have a good
reason
for doing so.
There is value in redundancy, and the trick is to find the right
balance, not to eliminate it completely.

Exactly. So there should be a choice. Right?
Also, having more or less free reign on white space means I can
express non-computational information more easily by using unusual
white space to offset chunks of code or parameters to tell the
reader, "Look, this is important" at a glance.

Programming is a form of technical writing; judicious use of white
space is a critical means of communicating with the reader.


Some times I really do
want to do this.

This is a powerful option.
It's possible to do this too. Is it not?
 
J

Juan Zanos

My Over-the-top-O-meter just went over the top.

Ah. So you agree. :)

Are we just left with aesthetic arguments disguised as readability
arguments?
Are some upset enough by the thought that somebody else might write
their code
differently that they're against even giving them a choice?
 
C

Caleb Clausen

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.
 
J

J Haas

You might just as well tell the Lisp community that all those brackets  
they use are redundant.

Sheesh, talk about strawmen. In Lisp, the parens are anything _but_
redundant. Lisp without brackets is riddled with ambiguity.
Conventionally-indented Ruby is not.
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.

Yes, I was so unaware of this in my original post that I very
specifically made a proposal that would leave existing syntax
unchanged, which would allow people who wanted to use 'end' to
continue to use 'end', and which would break no existing code. My
proposal involved purely optional syntax, reflecting the fact that
many Rubyists are not convinced that syntactic indentation is the way
to go.

While one size certainly doesn't fit all, and while there's no
accounting for taste, some sizes seem to fit most people better than
others. Charles said that he preferred chocolate ice cream to Python.
Well, I don't know about that, but I'm betting he also prefers
chocolate ice cream to, say, mud... at least for eating. And I daresay
most people would prefer chocolate ice cream to mud for mud. But one
size doesn't fit all, and in a world of seven billion you can probably
find a handful of people whose preferences go the other way. So while
it may not be strictly accurate to say that chocolate ice cream is
"better" for eating than mud, it's close enough for most purposes. And
there's nothing wrong with approaching people who are chowing down on
mud because they've never _tried_ chocolate ice cream, handing them a
big ol' bowl of the good stuff, and saying, "Here, try this, you'll
probably like it better." Nor is there anything wrong with thinking
there's something a bit odd about those who, having tried both, prefer
the mud. Nor is there anything wrong with rolling your eyes at people
who say, "I tried half a teaspoon of your 'iced cream', and I like the
mud better."

I think I've just about stretched this analogy to the breaking point,
but I predict that if my proposal is implemented, and people are given
the choice to use syntactic indentation, within a couple of years
it'll be the norm, and most Ruby programmers will think it a bit weird
that anyone fought against it.
 
C

Caleb Clausen

I completely agree with you in principle, and I'm generally in favor
of breaking with the past when such a break is warranted. But
listening to the objections people have raised in this thread, for a
lot of people it boils down to "I don't like it." Well, there's no
accounting for taste, and while I happen to feel that many of these
people would change their tune once they've had a little experience
with syntactic indentation, 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.
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.

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

while foo;
bar
Yep, looks totally weird to me too. Okay, so: no end-delimited blocks
nested inside indentation-delimited blocks. Once you're inside a scope
where the parser is paying attention to your indentation, it will
continue paying attention to your indendation until you leave that
scope.

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

Caleb Clausen

Also, having more or less free reign on white space means I can express
non-computational information more easily by using unusual white space
to offset chunks of code or parameters to tell the reader, "Look, this
is important" at a glance.

Can you give an example?
 
R

Rimantas Liubertas

I think I've just about stretched this analogy to the breaking point,
but I predict that if my proposal is implemented, and people are given
the choice to use syntactic indentation, within a couple of years
it'll be the norm, and most Ruby programmers will think it a bit weird
that anyone fought against it.

I just hope that people who would like to have syntactic indentation
will move on to Python.
Having both options in one languages is just asking for a huge mess.
If there is any voting on this my vote is a thousand times "no". :)


Regards,
Rimantas
 
G

Gary Wright

But we're back in the realm of subjectivity regarding what is "bare
minimum of code" and "superfluous". Ruby could be made quite terse,
but that's not a proper goal.

There is value in redundancy, and the trick is to find the right
balance, not to eliminate it completely.


+1
 
J

James Britt

Juan said:
On May 28, 2009, at 2:33 PM, James Britt wrote:
Terseness is a perfectly reasonable goal. It's a corollary to Occam's
Razer.
Hardly.

No? If you're going to sacrifice conciseness you should have a good
reason
for doing so.

Readability for humans.

terse != concise.

I'm for concise speech, but not so fond of terseness.

Exactly. So there should be a choice. Right?

In what? In how a language is designed? You're free to design whatever
you like.

BTW, one thing about these sort of threads that puzzles me is why, given
the amazing choice of programming languages, do people push, for
example, to have Ruby be like Python, when Python exists? And do these
same people also go on Python lists and argue to make Python more like Ruby?

If you want terseness, use Perl or APL.

It's possible to do this too. Is it not?

In a language such as Python?

If Ruby had magic indentation, could I do this?


def foo x,
y,
z

some code

Some Important Code I want to emphasize

More Important Code I want to emphasize

more code




James
 
J

James Britt

Caleb said:
Can you give an example?

def foo big,
list,
of,
args

some.stuff
some.stuff
some.stuff


something.more.important!
look.at.me!


more.stuff = boring


end




For example.


James
 
R

Rimantas Liubertas

BTW, one thing about these sort of threads that puzzles me is why, given =
the
amazing choice of programming languages, do people push, for example, to
have Ruby be like Python, =C2=A0when Python exists? =C2=A0And do these sa= me people
also go on Python lists and argue to make Python more like Ruby?

Hear, hear! I have seen someone writing Ruby as if it was Lisp, attempts
to turn Ruby into Java (I am not talking about JRuby here), into Python
and a request for RHP. Is that "I like X, but Ruby is cool at the moment,
let's make Ruby into X so it is the same thing I like and also cool"
way of thinking?

Regards,
Rimantas
 
J

J Haas

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?
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? ;) 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.
 
R

Rimantas Liubertas

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
 
J

Juan Zanos

Readability for humans.

terse != concise.
You're splitting some fine hairs. Apparently you have your own
dictionary. http://www.thefreedictionary.com/terse
I'm for concise speech, but not so fond of terseness.



In what? In how a language is designed? You're free to design
whatever you like.
Thank you for granting your permission. I am humbled:)
BTW, one thing about these sort of threads that puzzles me is why,
given the amazing choice of programming languages, do people push,
for example, to have Ruby be like Python, when Python exists? And
do these same people also go on Python lists and argue to make
Python more like Ruby?

If you want terseness, use Perl or APL.


A weak argument. Python is not Ruby with optional ends. Neither is
Perl or APL. So can I respond with an equally weak one? Why not use
a statically typed language where there is far more redundancy, which
is apparently so necessary for human readability?

Yes, why indeed on a list about the Ruby language do people insist on
talking about the Ruby language.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top