Block delimiting

From: Pete Yadlowsky pmy@virginia.edu
Hi,

I’m a Perl → Python → Ruby convert and new to this mailing list.

I like Ruby very much except for one thing: all those “end” tokens
scattered
everywhere. For my style of coding, they are superfluous and, in my
opinion,
only serve to clutter the code. I very much like Python’s indent blocking
style and would like to use it with Ruby. Indenting does everything I need
it
to do in terms of establishing structure and enhancing readability. Once
you
get used to this style (I’ve been using it for just about all languages and
for longer than Python has existed), delimiter tokens become unnecessary
and
unwanted.

I suppose that it’s not to your liking to simply do something like:

$ cat test.rb
puts “hello”

def myfunc
puts “in myfunc”
puts “finishing”; end

def iffunc
something = false
something_else = true

if something == true
    puts "in an if"
    elsif something_else == true
         puts "nope, I'm here"; end

puts "ending iffunc"; end

myfunc
iffunc
puts “done”

$ ./test.rb
hello
in myfunc
finishing
nope, I’m here
ending iffunc
done

Visually, it’s the same effect, IMHO…

···

Make your home warm and cozy this winter with tips from MSN House & Home.
http://special.msn.com/home/warmhome.armx

From: Pete Yadlowsky pmy@virginia.edu

I like Ruby very much except for one thing: all those “end” tokens
scattered
everywhere.

I suppose that it’s not to your liking to simply do something like:

[…]

def myfunc
puts “in myfunc”
puts “finishing”; end

Better, but no cigar I’m afraid. One of the things that makes Python so
clean-looking is the total absence of block delimiters. That’s what I’m going
for. I also like not having to remember to add them. If it looks right
block-indent-wise, it is right syntax-wise. I want that immediate visual
connection. Thanks, though.

···

On Thursday 08 January 2004 03:24 pm, Mike Wilson wrote:


Pete Yadlowsky
ITC Unix Systems Support
University of Virginia

Oh, god, that’s hard to follow!

That means if you forget an end, you get a weird broken block structure
that could do anything. The whole point of Python’s delimiting is that
it’s not possible to have a mismatch between what the programmer and the
interpreter think the structure is.

The OP would be better off writing a script to parse his code with
Python-like indentation rules, and add delimiters when appropriate.

Joe

···

In article Law12-F38fDGCl9FopY000082ac@hotmail.com, Mike Wilson wrote:

def iffunc
something = false
something_else = true

if something == true
    puts "in an if"
    elsif something_else == true
         puts "nope, I'm here"; end

puts "ending iffunc"; end

if iusepyhton:

print “A simple Copy/Paste can screw up your code”

#end

uppss …

if iusepyhton:

print "I miss the end label"

print "A simple Copy/Paste can screw up your code"     

#end

Pete Yadlowsky wrote:

Better, but no cigar I’m afraid. One of the things that makes Python so
clean-looking is the total absence of block delimiters. That’s what I’m going
for. I also like not having to remember to add them. If it looks right
block-indent-wise, it is right syntax-wise. I want that immediate visual
connection. Thanks, though.

Then stick with Python.

-Kent

Just out of curiosity, is it possible to write source filters in Ruby?
Damian Conway has a module that in 54 lines provides the Python
convention for Perl:

 use Language::Pythonesque; # this semicolon yet needed

 sub foo
     my $x = shift
     $x*2

 for my $i (1..10)
     print foo $i
     print "\n"

 print "OK, it works.\n"

How devil!!!

– fxn

···

On Jan 9, 2004, at 12:31 AM, Joe Mason wrote:

The OP would be better off writing a script to parse his code with
Python-like indentation rules, and add delimiters when appropriate.

Oh, god, that’s hard to follow!

I don’t disagree, but that’s precisely why I personally don’t care for
Python’s indentation-based scope.

That means if you forget an end, you get a weird broken block structure
that could do anything. The whole point of Python’s delimiting is that
it’s not possible to have a mismatch between what the programmer and the
interpreter think the structure is.

Oh, but it is possible for there to be a mismatch between the programmer’s
conception and the interpreter’s conception of the scope based on structure.
Simply mix tabs and spaces (evil, but it happens). These are also hard to
find in some editors.

I don’t want my indentation to specify scope. It’s idiotic; I will sometimes
“unindent” code for clarity, just as I will sometimes further indent code
for clarity. In neither case do I want it to be scope.

The OP would be better off writing a script to parse his code with Python-
like indentation rules, and add delimiters when appropriate.

Absolutely, if that’s what the OP wants. Fortunately, this is not
necessarily hard to do (it could probably be done with regexp matching), and
just as fortunately, it seems highly unlikely that Matz will ever make the
mistake that Guido made.

-austin

···

On Fri, 9 Jan 2004 08:31:41 +0900, Joe Mason wrote:

austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.01.08
* 22.45.57

Kent R. Spillner wrote:

Pete Yadlowsky wrote:

Better, but no cigar I’m afraid. One of the things that makes Python
so clean-looking is the total absence of block delimiters. That’s what
I’m going for. I also like not having to remember to add them. If it
looks right block-indent-wise, it is right syntax-wise. I want that
immediate visual connection. Thanks, though.

Then stick with Python.

Or do what I do: Use Ruby in spite of whatever minor flaws you might
perceive in it.

It will never satisfy everybody. Happily, it will never even
satisfy Matz, who I expect will keep improving it for a long
time.

But I don’t think Ruby will ever have significant whitespace.

Hal

Xavier Noria wrote:

Just out of curiosity, is it possible to write source filters in Ruby?
Damian Conway has a module that in 54 lines provides the Python
convention for Perl:

use Language::Pythonesque; # this semicolon yet needed

sub foo
    my $x = shift
    $x*2

for my $i (1..10)
    print foo $i
    print "\n"

print "OK, it works.\n"

How devil!!!

– fxn

I am sure you could do something like

require ‘make_me_like_python’

ptyhon_it <<PYTHON_LIKE
def foo(x)
puts(x)

foo(“hello world”)

PYTHON_LIKE

the python_it just adds ends when indentation decreases.

I am also so sure that someone else on the list will have far simpler
way to doing this.

Ralph

OP?

···

On Thursday 08 January 2004 10:49 pm, Austin Ziegler wrote:

The OP would be better off writing a script to parse his code with
Python- like indentation rules, and add delimiters when appropriate.

Absolutely, if that’s what the OP wants.


Pete Yadlowsky
ITC Unix Systems Support
University of Virginia

Except for newlines, which have been significant from the beginning
because of Ruby’s line-based syntax, and spaces before parentheses in
argument lists, which are a common source of FAQs. But we know what you
meant. :wink:

Tim Bates

···

On Fri, Jan 09, 2004 at 08:01:53AM +0900, Hal Fulton wrote:

But I don’t think Ruby will ever have significant whitespace.


tim@bates.id.au

Kent R. Spillner wrote:

Then stick with Python.

Or do what I do: Use Ruby in spite of whatever minor flaws you might
perceive in it.

That’s what I’m doing now. In fact, that’s what I’ve done with every language
I’ve ever written in. But I’m still going to offer the occasional suggestion
for improvement. There’s no guarantee it’ll get implemented, but it’s
guaranteed that it won’t if no one speaks up.

But I don’t think Ruby will ever have significant whitespace.

Well, we can always ask. You never know.

···

On Thursday 08 January 2004 06:01 pm, Hal Fulton wrote:


Pete Yadlowsky
ITC Unix Systems Support
University of Virginia

Back in 1985 the company I work for decided to rewrite its entire PL/I
code base in the then-new “C” programming language. PL/I, if you’re not
familiar with it, uses DO and END keywords to delimit blocks.

The programmers didn’t like C’s new-fangled brace-delimited blocks, so
they all created little header files with two macros:

#define DO {
#define END }

and started coding

if (x > 0) DO
/* stuff */
END

and were happy. For about a month, after which they collectively said
“screw it, you can’t make C into PL/I no matter how much preprocessing you
do”, deleted the header files, and started using braces.

···

On Fri, 09 Jan 2004 09:44:33 +0900, Ralph Mason wrote:

I am sure you could do something like

require ‘make_me_like_python’

Original Poster. That would be you. :slight_smile:

-austin

···

On Fri, 9 Jan 2004 12:59:47 +0900, Pete Yadlowsky wrote:

On Thursday 08 January 2004 10:49 pm, Austin Ziegler wrote:

The OP would be better off writing a script to parse his code with
Python- like indentation rules, and add delimiters when appropriate.
Absolutely, if that’s what the OP wants.
OP?


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.01.09
* 00.05.52

Hi,

Then stick with Python.

Or do what I do: Use Ruby in spite of whatever minor flaws you might
perceive in it.

Or do what I did: Design new language without flaws from your point of
view. But I can tell it’s fun but hard way. :wink:

But I don’t think Ruby will ever have significant whitespace.

Ruby will never lose “end”.

						matz.
···

In message “Re: block delimiting” on 04/01/09, Hal Fulton hal9000@hypermetrics.com writes:

Original Poster.

-Mark

···

On Fri, Jan 09, 2004 at 12:59:47PM +0900, Pete Yadlowsky wrote:

On Thursday 08 January 2004 10:49 pm, Austin Ziegler wrote:

The OP would be better off writing a script to parse his code with
Python- like indentation rules, and add delimiters when appropriate.

Absolutely, if that’s what the OP wants.

OP?

Can you provide an example, I’m not sure what you mean.

···

On Friday, 9 January 2004 at 8:04:38 +0900, Tim Bates wrote:

On Fri, Jan 09, 2004 at 08:01:53AM +0900, Hal Fulton wrote:

But I don’t think Ruby will ever have significant whitespace.

Except for … spaces before parentheses in argument lists


Jim Freeze

Q: How many IBM CPU’s does it take to execute a job?
A: Four; three to hold it down, and one to rip its head off.

Tim Hunter wrote:

I am sure you could do something like

require ‘make_me_like_python’

Back in 1985 the company I work for decided to rewrite its entire PL/I
code base in the then-new “C” programming language. PL/I, if you’re not
familiar with it, uses DO and END keywords to delimit blocks.

The programmers didn’t like C’s new-fangled brace-delimited blocks, so
they all created little header files with two macros:

#define DO {
#define END }

and started coding

if (x > 0) DO
/* stuff */
END

and were happy. For about a month, after which they collectively said
“screw it, you can’t make C into PL/I no matter how much preprocessing you
do”, deleted the header files, and started using braces.

I wish the reverse about Ruby, if I could change one thing it would be
it’s block structure so I could write

class Foo{

def foo(x){
    #code
}

}

{ x+=12; y=9 } if a > b

if x {
do_this_and_that()
z=z+1;
}

All the other languages I work with are really ‘c’ style, and ruby is
kind of but not really.

Ralph

···

On Fri, 09 Jan 2004 09:44:33 +0900, Ralph Mason wrote:

Well, newlines in a line/expression-oriented language aren’t a big deal. I
am bothered a bit by the foo( and foo ( discrepancy, even though I
personally prefer the former by far.

-austin

···

On Fri, 9 Jan 2004 08:04:38 +0900, Tim Bates wrote:

On Fri, Jan 09, 2004 at 08:01:53AM +0900, Hal Fulton wrote:

But I don’t think Ruby will ever have significant whitespace.
Except for newlines, which have been significant from the beginning
because of Ruby’s line-based syntax, and spaces before parentheses in
argument lists, which are a common source of FAQs. But we know what you
meant. :wink:


austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.01.08
* 22.43.52

foo(bar) # valid
foo (bar) # invalid

Jim Freeze wrote:

···

On Friday, 9 January 2004 at 8:04:38 +0900, Tim Bates wrote:

Can you provide an example, I’m not sure what you mean.