Pythonic indentation (or: beating a dead horse)

J

J Haas

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

Juan Zanos

Because it confuses. And having confusion about significance of
the whitespace in a programming language is a VERY bad thing
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?
 
J

J Haas

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

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

Rimantas Liubertas

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
 
R

Rimantas Liubertas

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
 
R

Rimantas Liubertas

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
 
J

J Haas

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

I could. But frankly, there are more good features of Ruby missing
from Python than there are good features of Python missing from Ruby.
And implementing the biggest feature missing from Ruby would not be
terribly difficult, and would be fully optional and backward
compatible. I'm not sure that any of these things are true about
Python's deficiencies with respect to Ruby.
Imperfection is in the eye of the beholder.

Do you disagree that Ruby is imperfect? If so, which version is
perfect, 1.8 or 1.9?
 
J

Joel VanderWerf

Juan said:
On May 28, 2009, at 3:51 PM, James Britt wrote: ...
You're splitting some fine hairs. Apparently you have your own
dictionary. http://www.thefreedictionary.com/terse

That link undermines your point:

terse
Adjective
1. neatly brief and concise
2. curt or abrupt [Latin tersus precise]

No one would say "I apologize for being concise with you"!
 
J

J Haas

Do you know many other ways to break the text into paragraph?

Yes. You could be required to type 'end' at the end of every
paragraph. But that'd just be silly and redundant, considering that
whitespace does a perfectly good job as a delimiter.
 
J

Juan Zanos

Juan said:
On May 28, 2009, at 3:51 PM, James Britt wrote: ...
You're splitting some fine hairs. Apparently you have your own
dictionary. http://www.thefreedictionary.com/terse

That link undermines your point:

terse
Adjective
1. neatly brief and concise
2. curt or abrupt [Latin tersus precise]

No one would say "I apologize for being concise with you"!


It undermines nothing. Concise is used as the definition as you've
just shown. Also you seem to have omitted the part about "easy to
understand". Why would you do that? Or is your concern that the
computer will be offended?

From that same page:

Adj. 1. terse - brief and to the point; effectively cut short; "a
crisp retort"; "a response so curt as to be almost rude"; "the laconic
reply; `yes'"; "short and terse and easy to understand
 
C

Caleb Clausen

def foo big,
list,
of,
args

some.stuff
some.stuff
some.stuff


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


more.stuff = boring


end

This (and your other, similar example) actually works in endless.rb
right now. Leave off the end and it inserts one for you, just where
you'd expect. You can always indent things more than necessary, and
that's fine. If you'd wanted to indent less than the surrounding code,
then I'd be in trouble. This won't work:

def foo big,
list,
of,
args

some.stuff
some.stuff
some.stuff


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


more.stuff = boring


Gregory said:
def foo("bar", :a => 1, :b => 2,
:c => 3, :d => 4)


end

But that's not legal. Presumably you meant either this:

def foo(bar, a = 1, b = 2,
c = 3, d = 4)


end

or this:

foo("bar", :a => 1, :b => 2,
:c => 3, :d => 4) do


end

Both break endless.rb. I sort of expected that the second one would
fail as soon as I saw it (do is the only thing that requires an end
but doesn't begin the expressions which it belongs to; I neglected to
consider the case of a do on a line after the one where it's method
call begins). But the first is a surprise.... that should have worked.
Well, they both should work, but now I have 2 bugs to fix. Thanks for
the test cases!
 
G

Gregory Brown

foo("bar", :a =3D> 1, :b =3D> 2,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 :c =3D> 3, :d =3D> 4) do


end

Yeah, just this:

foo("bar", :a =3D>1, :b =3D> 2,
:c =3D> 3, :d =3D> 4)

with or without a block.


This is what I get for staring at the weird macruby method definition
syntax. I'm not even sure if what I wrote was legal there, though :)
 
G

Gregory Brown

def foo big,
=A0 =A0 =A0 =A0 list,
=A0 =A0 =A0 =A0 of,
=A0 =A0 =A0 =A0 args

=A0 some.stuff
=A0 some.stuff
=A0 some.stuff


So then that means the common indentataion of:

def foo
bar
rescue
0

would also break? Just how many examples of problems do people need here?=
:)
 
E

Eleanor McHugh

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.

Occam's law applies to theory formation, not to literate exposition.
When writing code I'd rather err on the side of verbosity if that
expresses my model well to those who lack my implicit knowledge, than
terse and incomprehensible to anyone except myself.
Exactly. So there should be a choice. Right?

There is. It's called Python, and as its proponents frequently inform
me it's every bit as powerful as Ruby.
It's possible to do this too. Is it not?

And how do you embody syntactic rules for coping with such custom
indenting when the whole point is that they're both exceptional and
aesthetic in nature?


Ellie

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

Juan Zanos

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

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

Eleanor McHugh

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.

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
 
T

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

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

Juan Zanos

Occam's law applies to theory formation, not to literate exposition.
When writing code I'd rather err on the side of verbosity if that
expresses my model well to those who lack my implicit knowledge,
than terse and incomprehensible to anyone except myself.

I'd be careful about making such a narrow definition of the "law of
succinctness." I'd also be careful about trying to twist the
definition of
terse towards meaning incomprehensible. A part of the definition of
terse is
"easy to read."

You can choose whatever word you want to describe conciseness, but
most of them
imply or directly state clearness or an ease of understanding not
compromised
by beating around the bush or cluttering things up. You can choose a
near
synonym for concise that sometimes has a sense of impoliteness to make
concise
look negative, but the fact is the computer doesn't care.

Trying to argue that longer is somehow inherently better doesn't make
any
sense. If you really feel that way then Ruby is a poor choice
considering how
many wonderfully tedious languages there are just filled with
redundancy and
unnecessary syntax. How about Java's long winded forced naming
conventions?
Or better yet how about C++ templates for readability? There's just a
ton of
information about every last detail concerning types and all kinds of
stuff and
lots of redundancy. Certainly that is wonderfully readable compared
to Ruby.

Seriously, if you want to argue some other point about implementation
details
or some implication of a particular solution well then that's fair
game. But
you're not going to get anywhere arguing that longer is better or
telling
people to go away and use some other language.
 
G

Gregory Brown

Seriously, if you want to argue some other point about implementation
details
or some implication of a particular solution well then that's fair game.
But
you're not going to get anywhere arguing that longer is better or telling
people to go away and use some other language.

And you're not going to get anywhere being a giant douche. Or maybe
you think that (almost) everyone else in this thread is to blame.
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top