[ANN] FormatR 1.06

A new release of FormatR is out, 1.06. FormatR provides perl-like
formats for ruby plus some options the perl versions don’t have like
scientific notation formats. This release introduces the ability to
read in text and an associated format and return values for the
variables used to make the given text.

       enjoy,
         Paul

Homepage
http://www.crhc.uiuc.edu/~rubel/FormatR/

For example, if you had a format that looks like the following:
f = <<FORMAT
@@ Blah @@ }Blah @< @|| @#.#'
var_one,var_one,var_one,var_one, var_two, var_three, var_four
@<<< @<<<
var_one,var_one
FORMAT

and the following variables:
var_one, var_two, var_three, var_four = 1, 2, 3, 4.3

You could read the values in like so:
reader = FormatReader.new (format)
res = reader.readFormat (output)

assert (res[‘var_one’] == var_one.to_s)
assert (res[‘var_two’] == var_two.to_s)
assert (res[‘var_three’] == var_three.to_s)
assert (res[‘var_four’] == var_four)

Is there an accepted standard as to when to use {} vs do/end?

···

=====

Use your computer to help find a cure for cancer: http://members.ud.com/projects/cancer/

Yahoo IM: michael_s_campbell


Do You Yahoo!?
Yahoo! Health - Feel better, live better

The nearest thing to a standard is this
(which I practice, and I think I got it
from the Pragmatic Programmers).

Use do-end for multi-line blocks and {}
for single lines.

Just a convention – the language doesn’t
require it.

On the other hand, there is a precedence
issue with these two, so that sometimes
a statement will be interpreted differently
with these two constructs. It’s a rare thing,
so I don’t think it really trips anyone up.

I can’t remember the details, but I think it’s
in the FAQ.

Hal Fulton

···

----- Original Message -----
From: “Michael Campbell” michael_s_campbell@yahoo.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, July 30, 2002 9:19 AM
Subject: Style question

Is there an accepted standard as to when to use {} vs do/end?

I personally like the {} for the simple reason that it is easy
to test for matching pairs in vi.

eg

[1,2,3].each { |x|
do something…
}

To me this is easier to debug and looks as elegant as

[1,2,3].each do |x|
do something…
end

$0.02

···

On Tue, Jul 30, 2002 at 11:19:52PM +0900, Michael Campbell wrote:

Is there an accepted standard as to when to use {} vs do/end?


Jim Freeze
If only I had something clever to say for my comment…
~

Is there an accepted standard as to when to use {} vs do/end?

I personally like the {} for the simple reason that it is easy
to test for matching pairs in vi.

This has been my thought as well. Too, coming from a c/C++/Java
lineage, it “reads” better to me but that’s a function of my context,
not the language necessarily.

···

— Jim Freeze jim@freeze.org wrote:

On Tue, Jul 30, 2002 at 11:19:52PM +0900, Michael Campbell wrote:

[1,2,3].each { |x|
do something…
}

To me this is easier to debug and looks as elegant as

[1,2,3].each do |x|
do something…
end

=====

Use your computer to help find a cure for cancer: http://members.ud.com/projects/cancer/

Yahoo IM: michael_s_campbell


Do You Yahoo!?
Yahoo! Health - Feel better, live better

Note that matchit will also let you bounce between e.g. do/end pairs
in Vim.

···

On Tuesday 30 July 2002 09:53 pm, Jim Freeze wrote:

On Tue, Jul 30, 2002 at 11:19:52PM +0900, Michael Campbell wrote:

Is there an accepted standard as to when to use {} vs do/end?

I personally like the {} for the simple reason that it is easy
to test for matching pairs in vi.


Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE

Jim Freeze wrote:

I personally like the {} for the simple reason that it is easy
to test for matching pairs in vi.

eg

[1,2,3].each { |x|
do something…
}

Unfortunately for me, what reads well to me is:
[1, 2, 3].each
{ |x| do something…
}
with the braced aligned. The Ruby interpreter, however, disagrees with me.

···


– Charles Hixson
Gnu software that is free,
The best is yet to be.

Is there an accepted standard as to when to use {} vs do/end?

I personally like the {} for the simple reason that it is easy
to test for matching pairs in vi.

eg

[1,2,3].each { |x|
do something…
}

To me this is easier to debug and looks as elegant as

[1,2,3].each do |x|
do something…
end

Let me ask a related question: is there a accepted standard
of where the |…| go?

This is what I have been doing:

One-liners look like:

[1, 2, 3].each { |x| p x }

Multi-liners can look like:

[1, 2, 3].each { |x|
    p x
    p x + 1
}

or

[1, 2, 3].each {
    >x>
    p x
    p x + 1
}

or

[1, 2, 3].each do
    >x>
    p x
    p x + 1
end

I don’t often use “do |x|\n” … not sure why.

I’m trying to decide which of the 3 multi-line versions to commit
to using, but it seems there’s no One True Way from the sample
code I’ve been reading over …

– Dossy

···

On 2002.07.31, Jim Freeze jim@freeze.org wrote:

On Tue, Jul 30, 2002 at 11:19:52PM +0900, Michael Campbell wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

What’s really unfortunate, though, is that Vim has some killer features
dealing with {…} blocks (on account of its C heritage and the plain
ubiqity of such blocks.

For example, you can delete, change, indent, or do whatever you like to the
contents of {…} (or (…), […], etc.) in an instant, no matter where the
cursor is in the block.

Obviously, this functionality does not apply to do…end blocks. Despite
this loss, I still use do…end because it seems more fitting for Ruby.

Sigh…

Gavin

···

On Tuesday 30 July 2002 09:53 pm, Jim Freeze wrote:

On Tue, Jul 30, 2002 at 11:19:52PM +0900, Michael Campbell wrote:

Is there an accepted standard as to when to use {} vs do/end?

I personally like the {} for the simple reason that it is easy
to test for matching pairs in vi.

Note that matchit will also let you bounce between e.g. do/end pairs
in Vim.


Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE

I agree…or even better (for me):
[1, 2, 3].each
do |x|
something(x)
end

That way at a glance I can see exactly where the block begins and ends, which
takes me a few fractions of a second longer (but enough to bother me) when the
‘do’ is on the previous line. It’s even more helpful when the block is well
indented.

···

On Thu, Aug 01, 2002 at 04:53:44AM +0900, Charles Hixson wrote:

Unfortunately for me, what reads well to me is:
[1, 2, 3].each
{ |x| do something…
}
with the braced aligned. The Ruby interpreter, however, disagrees with me.


http://mas.cs.umass.edu/~rawlins

There is no enemy
anywhere.

me.

Yes, that’s how I write C/C++ and Java and Javascript, etc.

But Ruby is “semi-line-oriented.”

Yet if you find some way of continuing the
line, you could do this. Very ugly, though:

[1, 2, 3].each
{|x|

}

Hal

···

----- Original Message -----
From: “Charles Hixson” charleshixsn@earthlink.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, July 31, 2002 2:53 PM
Subject: Re: Style question

Unfortunately for me, what reads well to me is:
[1, 2, 3].each
{ |x| do something…
}
with the braced aligned. The Ruby interpreter, however, disagrees with

I use this one: > > [1, 2, 3].each { |x| > p x > p x + 1 > } > But I admit to changing my mind occasionally. I like having all of loop initialization on one line. Less eye movement? :-)
···

On Saturday 10 August 2002 06:52 pm, Dossy wrote:

Hi –

Let me ask a related question: is there a accepted standard
of where the |…| go?

This is what I have been doing:

One-liners look like:

[1, 2, 3].each { |x| p x }

Multi-liners can look like:

[1, 2, 3].each { |x|
    p x
    p x + 1
}

or

[1, 2, 3].each {
    >x>
    p x
    p x + 1
}

or

[1, 2, 3].each do
    >x>
    p x
    p x + 1
end

I don’t often use “do |x|\n” … not sure why.

That’s the one I like for multi-line ones :slight_smile: I personally don’t like
the |x| on a separate line – it always jolts visually, sort of the
visual equivalent of how it sounds when people read poetry and pause
at the end of each line whether it needs it or not.

I really like the majority of guidelines in:
http://www.jin.gr.jp/~nahi/RWiki/?cmd=view;name=RubyCodingConvention

David

···

On Sun, 11 Aug 2002, Dossy wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

What’s really unfortunate, though, is that Vim has some killer features
dealing with {…} blocks (on account of its C heritage and the plain
ubiqity of such blocks.

For example, you can delete, change, indent, or do whatever you like to the
contents of {…} (or (…), […], etc.) in an instant, no matter where the
cursor is in the block.

Obviously, this functionality does not apply to do…end blocks. Despite
this loss, I still use do…end because it seems more fitting for Ruby.

I decided some time ago not to be a slave to the language, but
to be a slave to my editor. :slight_smile:

I have chosen the lowest common demoninator, ie, I use spaces
instead of tabs and I use {} instead of do end. This lets
me edit easily whether I use vi, vim, gvim, emacs,
emacs+ruby extensions, etc, and have my code still look uniform
in any editor,

Jim

···

On Thu, Aug 01, 2002 at 12:59:01AM +0900, Gavin Sinclair wrote:

On Tuesday 30 July 2002 09:53 pm, Jim Freeze wrote:

On Tue, Jul 30, 2002 at 11:19:52PM +0900, Michael Campbell wrote:

Is there an accepted standard as to when to use {} vs do/end?

I personally like the {} for the simple reason that it is easy
to test for matching pairs in vi.

Note that matchit will also let you bounce between e.g. do/end pairs
in Vim.


Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE


Jim Freeze
If only I had something clever to say for my comment…
~

It used to bother me to see code in C/C++ that was
of the form

for() {
…do something
}

I was a big proponent of

for()
{
…do something
}

But after using Ruby for a year, seeing that in C/C++
doesn’t bother me as much. (In fact, the brace on the first
line is a coding standard for the bsd kernel, so I guess
it must not be all that bad. :slight_smile:

Also, this style has never bothered me in Ruby. I’m not sure why.

···

On Thu, Aug 01, 2002 at 07:26:54AM +0900, Hal E. Fulton wrote:

Yes, that’s how I write C/C++ and Java and Javascript, etc.

But Ruby is “semi-line-oriented.”

Yet if you find some way of continuing the
line, you could do this. Very ugly, though:

[1, 2, 3].each
{|x|

}


Jim Freeze
If only I had something clever to say for my comment…
~

If you can’t indent a do-end block by starting at the “do” line and
typing “>/end^M” then I might be willing to go out on a limb and
say that your block is trying to do too much and needs to be
refactored.

:wink:

Seriously, no offense meant.

– Dossy

···

On 2002.08.01, Gavin Sinclair gsinclair@soyabean.com.au wrote:

What’s really unfortunate, though, is that Vim has some killer features
dealing with {…} blocks (on account of its C heritage and the plain
ubiqity of such blocks.

For example, you can delete, change, indent, or do whatever you like to the
contents of {…} (or (…), […], etc.) in an instant, no matter where the
cursor is in the block.

Obviously, this functionality does not apply to do…end blocks. Despite
this loss, I still use do…end because it seems more fitting for Ruby.


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

I use this one: > > [1, 2, 3].each { |x| > p x > p x + 1 > } > But I admit to changing my mind occasionally. I like having all of loop initialization on one line. Less eye movement? :-)

I think of that first line as scaffolding for the loop, and the rest as the
actual work code.

Allotting extra white space suggests some degree of importance, which
something as pedestrian as |x| doesn’t deserve.

James

···

On Saturday 10 August 2002 06:52 pm, Dossy wrote:

Does anybody know where I can find the windows binaries to play with
ming in ruby??

-Rich

I decided some time ago not to be a slave to the language, but
to be a slave to my editor. :slight_smile:

:slight_smile: Perhaps that goes along with Dave and Andy’s doctrine of
“Use one editor well.”

I have chosen the lowest common demoninator, ie, I use spaces
instead of tabs and I use {} instead of do end. This lets
me edit easily whether I use vi, vim, gvim, emacs,
emacs+ruby extensions, etc, and have my code still look uniform
in any editor,

I’ll certainly agree with you on the tabs. I know that
many people use them at the rate of one per second, but
to me they are the curse of mankind (that and the missing
carriage return at the end of a UNIX line).

I’m going to be forced to learn to script (or whatever) in vim
just so I can fix the tab-happy HTML thing.

Hal

···

----- Original Message -----
From: “Jim Freeze” jim@freeze.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, July 31, 2002 11:07 AM
Subject: Re: Style question

> I have chosen the lowest common demoninator, ie, I use spaces > instead of tabs and I use {} instead of do end. This lets > me edit easily whether I use vi, vim, gvim, emacs, > emacs+ruby extensions, etc, and have my code still look uniform > in any editor, > This is fine if you do not expect to share your code with others who choose not to use vim. There are actually two common denominators: one for your own ease and one for others. Tabs allow others to view with their own preferences. Some use two spaces, some four, etc. for a tab. Spaces force others to use your preferences.
···

On Wednesday 31 July 2002 11:07 am, Jim Freeze wrote: