Pythonic indentation (or: beating a dead horse)

J Haas wrote:

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

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”. :slight_smile:

My experience says otherwise


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 May 28, 2009, at 2:15 PM, Eleanor McHugh wrote:

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?

Juan Z. wrote:

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?

:slight_smile:


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

Michael Bruschkewitz wrote:

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.

There’s no way it could be strictly optional. Unless you provide some
way for
persons that want code block ends to automatically convert code without
ends to
code with ends.

On May 28, 2009, at 2:33 PM, James B. wrote:

doesn’t do anything. It’s just a signal to the parser that here is

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

Some times I really do
want to do this.

This is a powerful option.

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

On May 28, 2009, at 2:46 PM, James B. wrote:

Juan Z. wrote:

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.

Ah. So you agree. :slight_smile:

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?

On 28 May 2009, at 19:31, Juan Z. wrote:

show an equal lack of awareness of that fact.

When was there ever great innovation in art that didn’t cause anger
and revulsion?

Anger and revulsion alone are not the proof of great innovation. Nor
for that matter does aesthetic innovation invalidate the tastes of
those who choose not to follow it.

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?

I probably wouldn’t have taken to the language, just as I didn’t take
to Python.

And would the fact that Python works the way it does justify my
arguing for inclusion of ‘end’? It’s hard to see how the language
could retain its character that way and it would be rather rude of me
to push the point with people who are clearly comfortable with its
current form. The same applies with Lisp, a beautiful language which I
choose not to use because I dislike the extensive use of parentheses.

Ellie

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

raise ArgumentError unless @reality.responds_to? :reason

On 5/28/09, James B. [email protected] wrote:

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?

On May 28, 11:15 am, Eleanor McHugh [email protected]
wrote:

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.

On May 28, 2009, at 2:33 PM, James B. wrote:

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

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

On 5/28/09, James B. [email protected] wrote:

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?

Maybe multi-line structures and expressions?

def foo(“bar”, :a => 1, :b => 2,
:c => 3, :d => 4)

end

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”. :slight_smile:

Regards,
Rimantas

Caleb C. wrote:

On 5/28/09, James B. [email protected] wrote:

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?

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

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?

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

On May 28, 2009, at 3:51 PM, James B. wrote:

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

Readability for humans.

terse != concise.
You’re splitting some fine hairs. Apparently you have your own
dictionary. Terse - definition of terse by The Free Dictionary

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.

Juan Z. wrote:

On May 28, 2009, at 2:33 PM, James B. wrote:

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.

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.

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?

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

On May 28, 11:33 am, James B. [email protected] wrote:

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

Have you noticed that your post is broken into paragraphs, and those
paragraphs are delimited solely by whitespace, and this does not
impair readability?

Have you noticed that this post contains quotes from you, and the
quotes from you contain quotes from me, and these quotes are delimited
from each other solely by indentation, and this does not impair
readability?

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.

Since we’re in the realm of the subjective, I don’t understand why you
and others are fighting so hard against having the option of
syntactic indentation. Why are you so gung-ho on forcing your own
subjective interpretation of the “right balance” of useless redundancy
on everyone else?

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.

Can you cite some real world code, preferably in a widely-used
library, that does this?

On May 28, 12:51 pm, James B. [email protected] wrote:

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?

This puzzles you? This really, really puzzles you? Truly?

Then I’ll try to explain.

Python is not merely Ruby with syntactic indentation. If it were,
you’d be absolutely correct and my complaint would be redundant, and
“switch to Python” would be good advice. But it’s not. There are some
parts of Ruby that are better than Python, and if I switched to
Python, I’d have to give those up. There are also some parts of Python
that are better than Ruby, and switching to Ruby means giving them up.

Ruby is imperfect and could be improved, and before you recoil in
horror, it’s no sacrilege to say so. As an engineer all I care about
is having the best tools for the job, and as such I’d rather work to
improve an imperfect tool than abandon it for another tool which is
just as imperfect (or moreso) but in a different way.

Python is not merely Ruby with syntactic indentation. If it were,
you’d be absolutely correct and my complaint would be redundant, and
“switch to Python” would be good advice. But it’s not. There are some
parts of Ruby that are better than Python, and if I switched to
Python, I’d have to give those up. There are also some parts of Python
that are better than Ruby, and switching to Ruby means giving them up.

Well, you can go to Python list and make a request to implement those
parts that you like in Ruby.

Ruby is imperfect and could be improved, and before you recoil in
horror, it’s no sacrilege to say so. As an engineer all I care about
is having the best tools for the job, and as such I’d rather work to
improve an imperfect tool than abandon it for another tool which is
just as imperfect (or moreso) but in a different way.

Imperfection is in the eye of the beholder.

Regards,
Rimantas

Have you noticed that your post is broken into paragraphs, and those
paragraphs are delimited solely by whitespace, and this does not
impair readability?

Do you know many other ways to break the text into paragraph?
Does the indentation of the first line changes the meaning of the
paragraph?

Have you noticed that this post contains quotes from you, and the
quotes from you contain quotes from me, and these quotes are delimited
from each other solely by indentation, and this does not impair
readability?

Quotes what I see are marked with “>”.

Since we’re in the realm of the subjective, I don’t understand why you
and others are fighting so hard against having the option of
syntactic indentation. Why are you so gung-ho on forcing your own
subjective interpretation of the “right balance” of useless redundancy
on everyone else?

Because seemingly the same code in different modes can mean
completely different things.

Regards,
Rimantas