Pythonic indentation (or: beating a dead horse)

On 5/28/09, J Haas [email protected] wrote:

any problems in a proper implementation of syntactic indentation, any
more than:

Indeed. rescue, when, else, elsif, and ensure are special-cased. If
they occur on the beginning of a line with the same indentation level
as the last line with a beginword, an extra end is not inserted.

Caleb C. wrote:


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.

Interesting. Thanks!

James

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

I don’t know if it works in Caleb’s script, but this need not cause
any problems in a proper implementation of syntactic indentation, any
more than:

Indeed. rescue, when, else, elsif, and ensure are special-cased. If
they occur on the beginning of a line with the same indentation level
as the last line with a beginword, an extra end is not inserted.

Caleb, have you thought about toying around with forking Ruby and
invoking your pre-processor automatically in some way? I think
that’d turn this conversation into something much more productive.

Even if it’s not a realistic implementation at first, it could lead to
productive discussion on how it could be integrated, and what
syntactic changes it would need to make Matz happy.

-greg

On May 28, 2009, at 9:26 PM, James B. wrote:

Juan Z. wrote:

Trying to argue that longer is somehow inherently better doesn’t
make any
sense.

Same holds for the inverse. But no one has been arguing that longer
is inherently better.

Well, maybe we’ll just have to agree to disagree on that one. Shorter
is better to the degree that nothing is harmed by doing so. If
significant indentation sufficiently harms something else then I agree
that is important too.

My point is that zero entropy and maximal information is a poor
goal when targeting people, that some amount of redundancy reduces
errors and improves communication (again, for people).
There is a well known and written about principle of economy that
applies universally to human languages. If we’re talking about
shortening everything then I’d agree with you completely. But when
something is really common we alter the language to make it shorter.
An entire line occupied only by the word ‘end’ is one of if not the
most common line in Ruby. That makes it a great candidate for
applying a principle of economy.

I do not have any objective way to say what, exactly, that is for a
programming language. My own experience from working with
indentation sensitive languages is that the trade-offs do not always
sit well with me. Nor does the verbosity of Java
The commonness of the occurrence is one key factor. All those
needless semicolons in Java, for example.

The information provided by significant indentation, while usable
(and possibly more efficient for some cases of human parsing),
introduces restrictions on how it may be used elsewhere, effectively
limiting how a writer expresses non-syntactical information in a
program.
Well that could be a good argument against. I’m not familiar enough
with such counter examples to say. So far I’ve
been pretty impressed with what Caleb’s tool can do.
for other humans that is also machine readable. That is, the goal
was highly-readable computer expressions, not machine-readable
people expressions.
I agree with you. Java advocates I know will claim that static typing
is worth the added redundancy and verbosity because it reduces the
chance of type errors and provides structure. They don’t believe that
you can have industrial strength applications without it. Sound
familiar?

My own guess is that static typing currently provides an efficiency
advantage that isn’t yet available in most dynamic languages.
Actually, I’ve heard that Sun’s JVM now throws away static type
information anyway. It would be interesting to know more about that.

I write way too much Java. I’ve been pretty disappointed that it
seems to be getting more verbose and less expressive for reason that
at this point still don’t make much sense to me. JRuby is a breath of
fresh air.

Juan Z. wrote:

Trying to argue that longer is somehow inherently better doesn’t make any
sense.

Same holds for the inverse. But no one has been arguing that longer is
inherently better.

My point is that zero entropy and maximal information is a poor goal
when targeting people, that some amount of redundancy reduces errors and
improves communication (again, for people).

I do not have any objective way to say what, exactly, that is for a
programming language. My own experience from working with indentation
sensitive languages is that the trade-offs do not always sit well with
me. Nor does the verbosity of Java

My experience with Haskell has been much different than my attempts at
Python. Maybe it’s Haskell’s emphasis on mathematical functions, on
using a format that employs (so it seems) a whole lot of equal signs.
The use of white space there feels much more natural than it did for me
with Python. (I also think Haskell induces different expectations about
what things should look like. It would probably feel wrong to use do/end
for something that is essentially mathematics.)

The information provided by significant indentation, while usable (and
possibly more efficient for some cases of human parsing), introduces
restrictions on how it may be used elsewhere, effectively limiting how a
writer expresses non-syntactical information in a program.

What puts me off so many discussions about code formatting is the idea
that code is first meant to provide instructions to a machine, and ideas
for people second.

The “machines first” attitude may be the reason for so much cruft in
Java. I’m sure GvR had “people first” in mind when opting for
significant indentation, but perhaps he viewed writing software as
primarily an exercise in generating code, less as writing a document for
other humans that is also machine readable. That is, the goal was
highly-readable computer expressions, not machine-readable people
expressions.


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 6:06 PM, Juan Z. [email protected]
wrote:

On May 28, 2009, at 5:20 PM, Eleanor McHugh wrote:

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

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.

On May 28, 2009, at 6:11 PM, Gregory B. wrote:

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.

Is there a way to block users on this group who use vulgar language
with intent to offend?

On Fri, 2009-05-29 at 17:56 +0900, Michael Bruschkewitz wrote:

I dont really understand this sentence (too much indirection - I’m german
and I’m tired…) Did you mean “It must be strictly optional” ?
What I mean is…
if endless ruby code is allowed, it cannot be strictly optional. If a
core class or any other class/project that you utilize is coded without
ends, then you get endless ruby whether you want it or not.

On Thu, May 28, 2009 at 8:14 PM, Juan Z. [email protected]
wrote:

Is there a way to block users on this group who use vulgar language with
intent to offend?

The same way you block users with intent to offend (or not) who do not
use vulgar language, with a kill-file in your mail client. Another
way to avoid such discourse is to not act like a troll with no respect
for the other members of this list.

-greg

“Gregory B.” [email protected] schrieb im Newsbeitrag
news:[email protected]

-greg

Offender may have some problems staying kind and friendly.
People feeling offended have problems beeing tolerant.
(They should just skip the post when tolerance limit is reached.)
It is the same sort of social disability.

Some offendings may come from in-familiarity to english language or
cultural
differences.
Never offer left hand to muslims, for example. I had absolutely no idea
about this problem until I read/heard about real reason.

In this NG we should concentrae on language issues.

Best Regards,
Michael B.

On May 29, 2009, at 5:00 AM, Michael Bruschkewitz wrote:

The same way you block users with intent to offend (or not) who do
People feeling offended have problems beeing tolerant.
(They should just skip the post when tolerance limit is reached.)
It is the same sort of social disability.

Some offendings may come from in-familiarity to english language or
cultural differences.
Never offer left hand to muslims, for example. I had absolutely no
idea about this problem until I read/heard about real reason.

In this NG we should concentrae on language issues.

It’s impossible to never offend. You can’t please everybody all the
time as they say. But in this case
there was no language misunderstanding. The poster’s intent was
specifically to be vulgar and offensive. It’s perfectly reasonable to
reject abusive behavior.

On Fri, May 29, 2009 at 9:34 AM, Juan Z. [email protected]
wrote:

It’s impossible to never offend. You can’t please everybody all the time as
they say. But in this case
there was no language misunderstanding. The poster’s intent was
specifically to be vulgar and offensive. It’s perfectly reasonable to
reject abusive behavior.

In all seriousness, I’ve found your behavior on this list abusive, and
I was venting my frustration. I should have done that in a private
mail, but please do not push this issue and make it sound like I’m the
source of great pain and suffering here.

People only need to search the archives to see what my contributions
to this list have been like.

-greg

“Juan Z.” [email protected] schrieb im Newsbeitrag
news:[email protected]
It’s impossible to never offend. You can’t please everybody all the
time as they say. But in this case
there was no language misunderstanding. The poster’s intent was
specifically to be vulgar and offensive. It’s perfectly reasonable to
reject abusive behavior.

Maybe it was just a very special try of being funny?

If somebody is really vulgar and offensive, he dis-qualifies himself.
IMHO, more than a shrug and ignore offensive wording would not be
appropriate.
There is no need for guards of morale in NG if everybody (who is
possible to
do that) tries to remain calm.

I, personally, prefer people calling me asshole to friendly stupids.

Let’s stop wasting our resources.

On Fri, May 29, 2009 at 1:24 PM, Caleb C. [email protected]
wrote:

I made it to prove a point, and I feel what I’ve done now is a
sufficient proof that it can be done, without buggy regex hackery, or
particular difficulty (given you have an already working lexer) and
the result can have very clean syntax.

Yeah, that was very surprising. Good work on that man, hopefully
it’ll be put to good use, but anyway, it’s nice to see the idea tried
out.

-greg

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

Caleb, have you thought about toying around with forking Ruby and
invoking your pre-processor automatically in some way? I think
that’d turn this conversation into something much more productive.

It wouldn’t be very hard, but that’s more effort than I want to put
into it right now.

Even if it’s not a realistic implementation at first, it could lead to
productive discussion on how it could be integrated, and what
syntactic changes it would need to make Matz happy.

I made it to prove a point, and I feel what I’ve done now is a
sufficient proof that it can be done, without buggy regex hackery, or
particular difficulty (given you have an already working lexer) and
the result can have very clean syntax.

On 28 May 2009, at 22:22, Juan Z. wrote:

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

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

INTERCAL’s where the action’s really at lol

Ellie

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

raise ArgumentError unless @reality.responds_to? :reason

Maybe it was just a very special try of being funny?

Whoever wrote it can clear this up easily by stating what his intention
was.

Personally, my experience was that sarcasm or irony often does not bode
well in written text. Additionally, often people assume that something
is insulting or otherwise harmful against them - written text is often
limited in expressing human intentions. Or, some people have a hard
time expressing their thoughts.

But anyway, let’s jump to the proposal again (and we can see that this
generated quite a stir… huge huge huge here hehe.)

I dont want to write too much, so I try to be short and concise:

  • Personally, i think it would be nice to omit “end” and have my code
    still work. I do indent my code already with two spaces all the time for
    every meaningful code block anyway. Those “end’s” aren’t really helpful
    for my eyes.

  • I do however not have a serious problem with that. It would be nice,
    but it is nothing where I would say “ruby sucks” because I cant omit
    ends. To me, it is not really important.

  • As far as language design is concerned, I personally think it is not
    elegant if a parser bothers too much about meaningful indent. Instead, I
    think a parser should try to capture the INTENT of the programmer, and
    it is stupid if a parser stops working because the INDENT was wrong. It
    just strikes me as inelegant - and keep in mind that I said, I wouldn’t
    mind to omit end at all.
    I found it silly to not be able to just paste code into the interactive
    python shell, and have it work. It complained about whitespace crap, and
    I found this insulting. I think the best way would be for a parser who
    could allow for both, with “end” being the default, but a switch which
    could allow for a shorter ruby-like syntax where one can omit “end”.

  • I think python has one solid argument going for it (and please also
    keep in mind that I hate other python choices, especially the foo():
    part. That includes the ‘:’ in there as well) - whitespace and
    homogeneous structure would be something I would appreciate. I love
    ruby’s flexibility, but I would also love to have something
    super-concise AND homogeneous. And more readable, IMHO, too.

  • As written above, I have one problem with the python whitespace. And
    this is the ‘:’ part. I hate that.

‘if foo:’

I do NOT want to get rid of “end” in ruby, if that means introducing
something like ‘:’. The ‘:’ is not beautiful at all, and thus it would
not be a real improvement for me, if I have to clutter my code with ‘:’.

  • I do not think that you applied the DRY statement correctly, because
    DRY applies for code logic primarily, not for satisfying a parser. And
    the “end” is there because of the parser.

Programmers shouldn’t be using freakin’ tabs anyway,
and if they are, they definitely shouldn’t be mixing them with spaces.

Personally I used to like tabs, and reasoned that people could set their
tabs width to whatever they like. But then I realized that i do comment
my own code a lot, and suddenly I was mixing tabs with spaces.

I stopped at that very day, and used 2 spaces (2, because I usually like
to have 80 chars per line, and not more. I am that old, really. I like
80 chars per line, even though i sometimes use more than that - i think
it is a good general rule of thumb to cut down below 80 chars / line,
and with 4 spaces i just hit that threshold sooner)

Anyway, I think this is all mostly just happy discussing here. Ruby is
the way it is, and to change something as fundamental as indent is way
too difficult and probably has no huge gain whatsoever. Didn’t Guido
once say that, if he could switch one thing in python, he would no
longer use significant whitespace?

On 28 May 2009, at 22:47, Reid T. wrote:

This would kill me. I utilize temporary code all the time starting
in column 0 so that it will be easy to find and pull back out

It’s an old and well-established practice that I’m also guilty of most
days of the week :slight_smile:

Ellie

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

raise ArgumentError unless @reality.responds_to? :reason

“Reid T.” [email protected] schrieb im Newsbeitrag
news:[email protected]

What I mean is…
if endless ruby code is allowed, it cannot be strictly optional. If a
core class or any other class/project that you utilize is coded without
ends, then you get endless ruby whether you want it or not.

For this reason, wouldn’t it be possible to add an “option”-parameter to
“require”?

On 28 May 2009, at 20:41, Juan Z. wrote:

Terse may mean "smoothly elegant, neat, clean, easy to understand,
or even brusque. But it doesn’t mean hard to read.

We may well be separated by a common language. It’s unusual here in
the UK for anyone to use the word ‘terse’ without meaning brusque with
a tendency to rudeness, and when applied to code it’s common currency
for “reads like obfuscated C”.

about the possibility of shortening it.
True. But removing it altogether isn’t the same as abbreviating it
(even txtspk leaves some of the characters in words to convey
meaning).

Ellie

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

raise ArgumentError unless @reality.responds_to? :reason