Elseif v. elsif?

On the other hand. I once was talking to the late John Cocke. John
was one of the oldest language gurus at IBM, and was best known for
his work on optimizing compilers, and later for fostering RISC
architectures which relied on such compilation technology.

John told me that when he wrote his first FORTRAN compiler, he had it
accept something like 7 different spellings of the keyword CONTINUE,
because "I'll be damned if I'll let any compiler I write tell me I
can't spell."

···

On 3/7/07, John Joyce <dangerwillrobinsondanger@gmail.com> wrote:

Remember in those days, heck even in the 80's languages and tools
(programs) used the shortest names possible because computing power
and memory were at a premium so even saving one character made a
difference. Thus we get all these sick little names for Unix tools,
love them or hate them.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

My output is:

~/2testing/dir1$ ruby rubyHelloWorld.rb
Hello SallyJaneBob!

ruby version:

~/2testing/dir1$ ruby -v
ruby 1.8.2 (2004-12-25) [universal-darwin8.0]

···

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

That's because you're not exercising the section under @names.nil?

Try: mg = MegaGreeter.new(nil)

···

On Wed, Mar 07, 2007 at 07:54:15PM +0900, 7stud 7stud wrote:

If I run the following code, I don't get any errors:

class MegaGreeter
        attr_accessor :names

        #constructor
        def initialize(names = "world")
                @names = names
        end

        #functions:
        def say_hi
                if @names.nil?
                        puts "..."
                elseif @names.respond_to?("each")
                        @names.each do |name|
                                puts "Hello #{name}!"
                        end
                else
                        puts "Hello #{@names}!"
                end
        end
end
if __FILE__ == $0
        mg = MegaGreeter.new(["Sally", "Jane", "Bob"])
        mg.say_hi
end

7stud 7stud schrieb:

(...)
If I run the following code, I don't get any errors:

class MegaGreeter
        attr_accessor :names

        #constructor
        def initialize(names = "world")
                @names = names
        end

        #functions:
        def say_hi
                if @names.nil?
                        puts "..."
                elseif @names.respond_to?("each")
                        @names.each do |name|
                                puts "Hello #{name}!"
                        end
                else
                        puts "Hello #{@names}!"
                end
        end
end
if __FILE__ == $0
        mg = MegaGreeter.new(["Sally", "Jane", "Bob"])
        mg.say_hi
end

Hi 7stud,

when reading (compiling) your code, Ruby can only detect syntactic errors, and your code is syntactically correct. Other errors can only be determined at run time. Let me show you...

You get an error when you try your code with another instance:

   mg2 = MegaGreeter.new(nil)
   mg2.say_hi

Output:

   ...
   in `say_hi': undefined method `elseif' (NoMethodError)

This error message shows that Ruby tried to execute the method #elseif, which obviously isn't defined. Ruby cannot decide in advance whether there will be an error or not:

   mg3 = MegaGreeter.new(nil)

   def mg3.elseif(arg)
     puts "Hello from elseif with arg #{arg}"
   end

   mg3.say_hi

This code defines the method #elseif for the object mg3. The output is:

   ...
   Hello from elseif with arg false
   in `say_hi': undefined method `each' for nil:NilClass (NoMethodError)

You can see that the #elseif method is called, but then there's an error in the next line: because @names is nil in this case, we call the method #each on the object nil, which isn't defined.

I should have said: normally it isn't defined. We can change this:

   def nil.each
     yield "nil"
   end

   mg3.say_hi

This code defines the method #each for the object nil, so that it passes the string "nil" to the block. The output is:

   ...
   Hello from elseif with arg true
   Hello nil!

You can see that your code executes fine in this case. This can only be determined by actually running the code. Ruby is very dynamic, which sometimes isn't an advantage, as has been in your case. But it can be a very powerful tool, which is why we all hang out here.

Regards,
Pit

Austin Ziegler wrote the following on 07.03.2007 19:52 :

There's absolutely nothing of value in what Jenda says at this point.

I don't agree. Thunderbird may be able to learn how to automatically put
trolls in my Junk folder thanks to him/her. Please continue Jenda, this
is a high trafic list, I need some material :slight_smile:

Lionel

I agree with you insofar as "this version". I'm under the impression
that the posts are coming from someone posing as Jenda. It appears
that ruby-forum.com does send a activation email, but perhaps someone
hacked Jenda's email account or hacked the ruby-forum.com account post
activation. I just find it hard to believe that someone who'd been so
esteemed in the Perl community would stoop to the behavior we've seen
on this list, nor that they would refer to "Pearl"[1] in any forum...

Jacob Fugal

[1] ruby-talk:242290

···

On 3/7/07, Austin Ziegler <halostatue@gmail.com> wrote:

Jenda, at least this version of Jenda since others seem to recognise
said person as a positive influence in the Perl world at one point, is
a troll.

Damn, it's also the name of my top secret fork of Ruby for MS Windows.
Windows + Ruby = Wuby. :slight_smile:

I'm dwivin' in my car...

Dan

···

On Mar 7, 11:14 pm, Chad Perrin <per...@apotheon.com> wrote:

On Thu, Mar 08, 2007 at 03:50:17AM +0900, 7stud 7stud wrote:
> > Don't worry. They'll go away. The Wuby moto is break what works, rename
> > what's commonly known and add gotchas for fun.

> I've seen it mentioned a couple of times--what the heck is wuby?

It's a sarcastic, trollish way of saying "Ruby" if you're trying to
convey a sense that it is childish.

Interesting, but if you type CONTINUE or elsif that many times and get error messages, you're going to learn to spell it.

···

On Mar 9, 2007, at 6:37 AM, Rick DeNatale wrote:

On the other hand. I once was talking to the late John Cocke. John
was one of the oldest language gurus at IBM, and was best known for
his work on optimizing compilers, and later for fostering RISC
architectures which relied on such compilation technology.

John told me that when he wrote his first FORTRAN compiler, he had it
accept something like 7 different spellings of the keyword CONTINUE,
because "I'll be damned if I'll let any compiler I write tell me I
can't spell."

I could explain why, but just follow Stefano's advice and put "then"
after each if elsif and elseif and you will see.

Robert

···

On 3/7/07, 7stud 7stud <dolgun@excite.com> wrote:

My output is:

~/2testing/dir1$ ruby rubyHelloWorld.rb
Hello SallyJaneBob!

ruby version:

~/2testing/dir1$ ruby -v
ruby 1.8.2 (2004-12-25) [universal-darwin8.0]

--
Posted via http://www.ruby-forum.com/\.

--
We have not succeeded in answering all of our questions.
In fact, in some ways, we are more confused than ever.
But we feel we are confused on a higher level and about more important things.
-Anonymous

You spoiled it :wink:
but this is a good way to explain it too...

···

On 3/7/07, Brian Candler <B.Candler@pobox.com> wrote:

On Wed, Mar 07, 2007 at 07:54:15PM +0900, 7stud 7stud wrote:
> If I run the following code, I don't get any errors:
>
> class MegaGreeter
> attr_accessor :names
>
> #constructor
> def initialize(names = "world")
> @names = names
> end
>
> #functions:
> def say_hi
> if @names.nil?
> puts "..."
> elseif @names.respond_to?("each")
> @names.each do |name|
> puts "Hello #{name}!"
> end
> else
> puts "Hello #{@names}!"
> end
> end
> end
> if __FILE__ == $0
> mg = MegaGreeter.new(["Sally", "Jane", "Bob"])
> mg.say_hi
> end

That's because you're not exercising the section under @names.nil?

Try: mg = MegaGreeter.new(nil)

--
We have not succeeded in answering all of our questions.
In fact, in some ways, we are more confused than ever.
But we feel we are confused on a higher level and about more important things.
-Anonymous

Perhaps at the "Ruby from other languages" page :
Ruby From Other Languages

I did a search on the C/C++ page for 'elsif' and it wasn't found.

Ruby isn't the only language that does that.
"Different" would be more like the way bash does it: "elif"

To me 'elif' stands out like a red flag. 'elsif' is a more subtle
differentiation, and I couldn't spot it even though I had the problem
narrowed down to 3 lines of code. The "Ruby in 20 Minutes" tutorial is
obviously geared to the experienced programmer(beginner's don't know
what classes are or what an 'attr_accessor' is), so I would suggest
putting this in the tutorial:

LOOK AT THE ELSIF SYNTAX CAREFULLY--IT'S 'ELSIF' NOT 'ELSEIF'

with the 'E' in elseif in red.

···

--
Posted via http://www.ruby-forum.com/\.

> Jenda, at least this version of Jenda since others seem to recognise
> said person as a positive influence in the Perl world at one point, is
> a troll.

I agree with you insofar as "this version". I'm under the impression
that the posts are coming from someone posing as Jenda. It appears
that ruby-forum.com does send a activation email, but perhaps someone
hacked Jenda's email account or hacked the ruby-forum.com account post
activation. I just find it hard to believe that someone who'd been so
esteemed in the Perl community would stoop to the behavior we've seen
on this list, nor that they would refer to "Pearl"[1] in any forum...

now that might be a stupid - although unlike - typo.
the behavior is strange though if the info concerning the person is
correct maybe I should search the archives.
Or maybe my first idea to contact CPAN is a good one too, imagine the
poor guy if his address is spoofed...

What'd you think?

Robert

···

On 3/7/07, Jacob Fugal <lukfugl@gmail.com> wrote:

On 3/7/07, Austin Ziegler <halostatue@gmail.com> wrote:

Jacob Fugal

[1] ruby-talk:242290

--
We have not succeeded in answering all of our questions.
In fact, in some ways, we are more confused than ever.
But we feel we are confused on a higher level and about more important things.
-Anonymous

Ahh, the silver lining.

···

On Thu, Mar 08, 2007 at 04:20:27AM +0900, Lionel Bouton wrote:

Austin Ziegler wrote the following on 07.03.2007 19:52 :
>
> There's absolutely nothing of value in what Jenda says at this point.

I don't agree. Thunderbird may be able to learn how to automatically put
trolls in my Junk folder thanks to him/her. Please continue Jenda, this
is a high trafic list, I need some material :slight_smile:

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Amazon.com interview candidate: "When C++ is your
hammer, everything starts to look like your thumb."

Cheer up you can still call it Microruby :wink:
R

···

On 3/8/07, Daniel Berger <djberg96@gmail.com> wrote:

On Mar 7, 11:14 pm, Chad Perrin <per...@apotheon.com> wrote:
> On Thu, Mar 08, 2007 at 03:50:17AM +0900, 7stud 7stud wrote:
> > > Don't worry. They'll go away. The Wuby moto is break what works, rename
> > > what's commonly known and add gotchas for fun.
>
> > I've seen it mentioned a couple of times--what the heck is wuby?
>
> It's a sarcastic, trollish way of saying "Ruby" if you're trying to
> convey a sense that it is childish.

Damn, it's also the name of my top secret fork of Ruby for MS Windows.
Windows + Ruby = Wuby. :slight_smile:

I'm dwivin' in my car...

Dan

--
We have not succeeded in answering all of our questions.
In fact, in some ways, we are more confused than ever.
But we feel we are confused on a higher level and about more important things.
-Anonymous

Hey . . . if you were really planning a "top secret fork of Ruby for MS
Windows", I'd say Wuby would be an *excellent* name for the language.
One wonders, however, why you'd need to fork it for Windows.

···

On Thu, Mar 08, 2007 at 09:35:06PM +0900, Daniel Berger wrote:

On Mar 7, 11:14 pm, Chad Perrin <per...@apotheon.com> wrote:
> On Thu, Mar 08, 2007 at 03:50:17AM +0900, 7stud 7stud wrote:
> > > Don't worry. They'll go away. The Wuby moto is break what works, rename
> > > what's commonly known and add gotchas for fun.
>
> > I've seen it mentioned a couple of times--what the heck is wuby?
>
> It's a sarcastic, trollish way of saying "Ruby" if you're trying to
> convey a sense that it is childish.

Damn, it's also the name of my top secret fork of Ruby for MS Windows.
Windows + Ruby = Wuby. :slight_smile:

I'm dwivin' in my car...

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"The measure on a man's real character is what he would do
if he knew he would never be found out." - Thomas McCauley

and a good argument for code coverage testing (e.g. rcov)

···

On Wed, Mar 07, 2007 at 08:05:14PM +0900, Robert Dober wrote:

>That's because you're not exercising the section under @names.nil?
>
>Try: mg = MegaGreeter.new(nil)
>
>
You spoiled it :wink:
but this is a good way to explain it too...

That's because you're not exercising the section under @names.nil?
Try: mg = MegaGreeter.new(nil)

You spoiled it :wink:
but this is a good way to explain it too...

What does that have to do with anything?

Good points Stefano, conclusion *always* use "then" :slight_smile:

My first exposure to Ruby is the "Ruby in 20 Minutes" tutorial. If it's
good practice to always use 'then', how about putting it in the
tutorial?

···

--
Posted via http://www.ruby-forum.com/\.

Really, your complaint amounts to nothing more than "I'm more used to
the way language A does it than the way language B does it -- so
language B must be wrong."

Technically speaking, "elseif", "elsif", and "elif" are equally "wrong".
To do it right, you'd have to make it "else if".

···

On Wed, Mar 07, 2007 at 08:08:35PM +0900, 7stud 7stud wrote:

To me 'elif' stands out like a red flag. 'elsif' is a more subtle
differentiation, and I couldn't spot it even though I had the problem
narrowed down to 3 lines of code. The "Ruby in 20 Minutes" tutorial is
obviously geared to the experienced programmer(beginner's don't know
what classes are or what an 'attr_accessor' is), so I would suggest
putting this in the tutorial:

LOOK AT THE ELSIF SYNTAX CAREFULLY--IT'S 'ELSIF' NOT 'ELSEIF'

with the 'E' in elseif in red.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"It's just incredible that a trillion-synapse computer could actually
spend Saturday afternoon watching a football game." - Marvin Minsky

For the record, I find a few of Ruby's naming choices silly and
non-intuitive as well. "elsif", regardless of it's language lineage,
IS kinda weird and easy to miss. "case" should have been "switch".
And almost any of the proposed alternatives to "inject" would be
preferable - with my personal preferance being "fold".

But I'm so used to dealing with language eccentricities, and Ruby's
features give me so much joy, that it's easy to overlook such
nitpicks.

···

--
Avdi

Robert Dober wrote:

···

On 3/7/07, Jacob Fugal <lukfugl@gmail.com> wrote:

On 3/7/07, Austin Ziegler <halostatue@gmail.com> wrote:
> Jenda, at least this version of Jenda since others seem to recognise
> said person as a positive influence in the Perl world at one point, is
> a troll.

I agree with you insofar as "this version". I'm under the impression
that the posts are coming from someone posing as Jenda. It appears
that ruby-forum.com does send a activation email, but perhaps someone
hacked Jenda's email account or hacked the ruby-forum.com account post
activation. I just find it hard to believe that someone who'd been so
esteemed in the Perl community would stoop to the behavior we've seen
on this list, nor that they would refer to "Pearl"[1] in any forum...

now that might be a stupid - although unlike - typo.
the behavior is strange though if the info concerning the person is
correct maybe I should search the archives.
Or maybe my first idea to contact CPAN is a good one too, imagine the
poor guy if his address is spoofed...

What'd you think?

Observe:

http://66.102.9.104/search?q=cache:xXEIdNOg_48J:www.perlmonks.org/%3Fnode_id%3D81566+jenda+ruby&hl=en&ct=clnk&cd=3&gl=uk&client=firefox-a

Not definitive, but certainly interesting. Also:

http://66.102.9.104/search?q=cache:95o0skP5sNAJ:www.perlmonks.org/%3Fnode_id%3D92976+jenda+ruby&hl=en&ct=clnk&cd=4&gl=uk&client=firefox-a

--
Alex