[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

error:- "regex literal in condition"

John Maclean

1/20/2006 5:33:00 PM

Hi Guys,

Simple script that spits out "Ruby" if it was typed at stdin. What's the error, see below.
#!/usr/bin/env ruby

while gets
if /Ruby/
print
end
end


jayeola@tp20$ ruby fx/ruby/p22
fx/ruby/p22:4: warning: regex literal in condition
haha
Ruby
Ruby


--
John Maclean
MSc (DIC)
07739 171 531



37 Answers

Malte Milatz

1/20/2006 5:52:00 PM

0

John Maclean:
> while gets
> if /Ruby/
> print
> end
> end

You may feel more comfortable writing this:

while line = gets
if line =~ /Ruby/
print line
end
end

And if you want to make sure that the line is read from stdin, you'll want
to write STDIN.gets instead of simply gets, because Kernel#gets looks at the
files specified on the command line and only calls STDIN.gets if there
aren't any.

Malte

Florian Groß

1/20/2006 6:08:00 PM

0

Zach

1/20/2006 6:21:00 PM

0

This is an ignorant question to pose, but here I go anyway.

Does anyone see advantages to using Hungarian Case to variable names in
Ruby, or do you think it may hinder as some people call "accidental
abstraction" [Bill Davis] ? Since Ruby is big with "Duck Typing", would
using Hungarian Case be more of a verbal obstacle than a more
descriptive variable. What about varying degrees, such as for integers,
doubles, strings, and o for Objects, but not exhaustive?

(For those who don't know about Hungarian typing, it would similar to an
integer you would name "counter" being named "iCounter" or a variable
you would normally name "duck" be "oDuck" because it is an object)

I know this is a rather old topic to be bringing into a newer
technology, but I'm curious on what your all's take is on this.

-Zach



dblack

1/20/2006 6:34:00 PM

0

Daniel Cedilotte

1/20/2006 6:44:00 PM

0


> Does anyone see advantages to using Hungarian Case to variable names in
> Ruby, or do you think it may hinder as some people call "accidental
> abstraction" [Bill Davis] ? Since Ruby is big with "Duck Typing", would
> using Hungarian Case be more of a verbal obstacle than a more
> descriptive variable. What about varying degrees, such as for integers,
> doubles, strings, and o for Objects, but not exhaustive?

IMHO, I've never seen the use for it. As far as I know, variable names
should be able to tell you what it holds at a glance. I am however of
the old school of programming and hence, might not be the best person to
give my opinion but none the less, I still find that Hungarian Notation
is a big waste of time.




james_b

1/20/2006 6:52:00 PM

0

dblack@wobblini.net wrote:

>
> Tagging variables based on the class of the objects to which they
> refer seems to me to be aggressively anti-duck-typing. It's also ugly
> :-) I think I'll stick with the traditional style.
>

Class and object names should be clear enough to reflect what that are
and what they are for. Ideally no one is still trying to conserve space
or finger power by naming things 'c' or 'x' or 'ssn' except for very
targeted use (e.g., short-scoped disposable values).

If you have a variable that refers, say, to an instance of a class
representing a hotel reservation, name it as such:
current_hotel_reservation. Not hr_curr or the like.

James


--

http://www.ru... - Ruby Help & Documentation
http://www.artima.c... - The Journal By & For Rubyists
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys
http://www.30seco... - Building Better Tools


Tim Hunter

1/20/2006 7:04:00 PM

0

Hungarian notation has never been useful except in C code before C
compilers started doing a reliable job of identifying type mismatches,
which was about 20 years ago. Since then there's been no reason for
this practice in C code. It's an ugly and fragile hack that was just
barely justifiable then and is simply execrable now.

Mike Fletcher

1/20/2006 7:08:00 PM

0

Zach wrote:
[...]
> Does anyone see advantages to using Hungarian Case to variable names in
> Ruby, or do you think it may hinder as some people call "accidental
> abstraction" [Bill Davis] ? Since Ruby is big with "Duck Typing", would
> using Hungarian Case be more of a verbal obstacle than a more
> descriptive variable. What about varying degrees, such as for integers,
> doubles, strings, and o for Objects, but not exhaustive?
>
> (For those who don't know about Hungarian typing, it would similar to an
> integer you would name "counter" being named "iCounter" or a variable
> you would normally name "duck" be "oDuck" because it is an object)

See this article on what Hungarian notation really was meant to help
with (it was meant to provide semantic type (this value is used for X)
not data type (this value is an int)).

http://www.joelonsoftware.com/articles/...

--
Posted via http://www.ruby-....


James Gray

1/20/2006 7:13:00 PM

0

On Jan 20, 2006, at 12:21 PM, Zach wrote:

> Does anyone see advantages to using Hungarian Case to variable
> names in
> Ruby, or do you think it may hinder as some people call "accidental
> abstraction" [Bill Davis] ?

I assume you know this, but just to be sure, Joel on Software has a
semi-famous article about the virtues of Hungarian Notation:

http://www.joelonsoftware.com/articles/...

If you make it all the way to the end of that, it talks about how the
notation is intended to show a "kind", not "type". When used that
way, I can't decide if it interferes with Duck Typing or not... A
great example is escaping me.

It may indeed be useful, but it is hard to argue that it isn't ugly. ;)

James Edward Gray II



Zach

1/20/2006 7:17:00 PM

0

Actually I hadn't read this article, but I've heard of Joel. Thanks to
the both of you for pointing it out.

-Zach

"I assume you know this, but just to be sure, Joel on Software has a
semi-famous article about the virtues of Hungarian Notation:

http://www.joelonsoftware.com/articles/...

If you make it all the way to the end of that, it talks about how the
notation is intended to show a "kind", not "type". When used that way,
I can't decide if it interferes with Duck Typing or not... A great
example is escaping me.

It may indeed be useful, but it is hard to argue that it isn't ugly. ;)

James Edward Gray II "

Mike Fletcher wrote:

>Zach wrote:
>[...]
>
>
>>Does anyone see advantages to using Hungarian Case to variable names in
>>Ruby, or do you think it may hinder as some people call "accidental
>>abstraction" [Bill Davis] ? Since Ruby is big with "Duck Typing", would
>>using Hungarian Case be more of a verbal obstacle than a more
>>descriptive variable. What about varying degrees, such as for integers,
>>doubles, strings, and o for Objects, but not exhaustive?
>>
>>(For those who don't know about Hungarian typing, it would similar to an
>>integer you would name "counter" being named "iCounter" or a variable
>>you would normally name "duck" be "oDuck" because it is an object)
>>
>>
>
>See this article on what Hungarian notation really was meant to help
>with (it was meant to provide semantic type (this value is used for X)
>not data type (this value is an int)).
>
>http://www.joelonsoftware.com/articles/...
>
>
>