Subject: [sup-talk] In next: thread-view-mode labelling No method join for Set

From: [email-masked] (Wirt Wolff)
Date: Wed, 19 Aug 2009 14:41:54 -0600

Lots of great improvements in next. Love the utf8.

When I try to 'l'abel in thread view mode, however, sup crashes with

--- NoMethodError from thread: main
undefined method `join' for #<Set: {:list, :xm}>
./lib/sup/buffer.rb:506:in `ask_for_labels'
./lib/sup/util.rb:520:in `send'
./lib/sup/util.rb:520:in `method_missing'
./lib/sup/modes/thread-view-mode.rb:253:in `edit_labels'
./lib/sup/mode.rb:50:in `send'
./lib/sup/mode.rb:50:in `handle_input'
./lib/sup/buffer.rb:260:in `handle_input'

----------------------------------------

Most recent commit is
    Merge branch 'various-api-refactors' into next
commit 3de96fb9b308afe600c7ccfcee75913f039ef4f6

run with % ruby -Ilib bin/sup

----------------------------------------

Advice how to fix?

thanks,

-- 
wmw

---

From: [email-masked] (Carl Worth)
Date: Wed, 19 Aug 2009 17:31:12 -0700

> Lots of great improvements in next. Love the utf8.

Agreed. These are very nice.

> ./lib/sup/buffer.rb:506:in `ask_for_labels'

I'm getting that too. It bisected down to the following which is not
so surprising:

    commit 7aea418a8a62b7070eee764475fcfc0bdd8d58dd
    Author: William Morgan <wmorgan-sup at masanjin.net>
    Date:   Tue Aug 11 16:00:52 2009 -0400

        maintain labels as Sets rather than arrays

I've attached a patch that at least makes the crashes I was able ro
reproduce go away. But I have no idea if I got them all of course[*].
And please let me know if I'm doing anything wrong. I'm new to ruby as
well as sup here, so go easy on me, please! :-)

-Carl

[*] Totally off-topic: This is one of the things about "dynamically
typed" languages that I've never been able to wrap my brain around. I
really like that with static typing I can trust the compiler to help
me be very thorough if I make a type change like this, (and catch all
the cases before shipping any code). Instead, here, there's a hard
task of exercising every possible code path (at run time) before we
know if there are any type errors still lingering. I've seen some
proponents of dynamically-typed languages argue that unit testing
should provide the same coverage that a statically-typed compiler
would, but I haven't seen that in practice.

You all definitely have a lot more experience with ruby than I do, so
I'm honestly interested in learning form your experience. What do you
do to deal with cases like this?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Convert-a-couple-of-arrays-to-sets-for-labels.patch
Type: application/octet-stream
Size: 1685 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20090819/c4120e6d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20090819/c4120e6d/attachment.bin>

---

From: [email-masked] (Ben Walton)
Date: Wed, 19 Aug 2009 22:57:25 -0400

> would, but I haven't seen that in practice.

The term you'll see bandied about in ruby circles/books/etc is 'duck
typing' which coming from strongly typed languages is definitely
something that takes some getting used to.  Basically, instead of
caring about the type of the object, you case about what the object
does.  If it walks like a duck and quacks like a duck, treat it like a
duck.

A very simple example is a function that expects to append data to
another object.  You could pass it a string (which uses << to append)
or an array (which uses << to push elements on the end).  If you
originally passed a string, but found performance (memory ->
realloc()) issues, you could swap the string object for an array
object and do array.join when everything is collected into array
elements.

Then, you'll see many examples where there is code like:

raise SomeException, "blah" unless someobject.respond_to?(:somemethod)

Your code doesn't care _what kind_ of object it gets as long as it
knows _how_ to talk to it.

Personally, I really like this.  Ruby isn't perfect by any stretch,
but of all the languages I've used, it's hands down the most fun to
write.

-Ben
-- 
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302

GPG Key Id: 8E89F6D2; Key Server: pgp.mit.edu
Contact me to arrange for a CAcert assurance meeting.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20090819/a644ea46/attachment.bin>

---

From: [email-masked] (Carl Worth)
Date: Wed, 19 Aug 2009 21:03:08 -0700

Excerpts from Ben Walton's message of Wed Aug 19 19:57:25 -0700 2009:
> > the cases before shipping any code).
...
> does.  If it walks like a duck and quacks like a duck, treat it like a

Yes, I understand that just fine. But two points:

1. That's not actually helping in the current case where we're trying
   to do simple things like '+' and the distinction between Set and
   Array is causing problems. (See the patch where we're having to add
   .to_a and Set.new to coerce things.) So, here, at least things are
   falling down. So somehow something in ruby isn't living up to the
   concept here.

> knows _how_ to talk to it.

2. Even with the "duck typing" I'd still like to express this
   constraint in a way that is decidable statically. I've definitely
   failed as a programmer if a user sees a runtime exception like
   that. Sytems with sophisticated runtimes are very interesting to
   me. It's just discouraging to me that so many such systems fail to
   actually help me avoid problems like this before the user is
   running my code.

> but of all the languages I've used, it's hands down the most fun to

That could still be the case for me here. I haven't tried much with it
yet, so I don't have any strong opinion there yet. :-)

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20090819/aae17dcd/attachment.bin>

---

From: [email-masked] (Ben Walton)
Date: Thu, 20 Aug 2009 20:16:23 -0400

>    falling down. So somehow something in ruby isn't living up to the

You're correct.  The difference between fixing this in Ruby vs fixing
this in a strongly typed language though is that you could implement
Set#join such that the code expecting an array wouldn't know the
difference _or_ you could have that code use kind_of?(Array) to ensure
it was getting the type of argument it was expecting.  Both are
technically correct.

In a strongly typed language, you'd have to modify the acceptable
arguments (function definition) and ensure everything that called the
function passed something acceptable or provide an overloaded version
(if you're working with a language that supports it).

Those are correct solutions too.

>    actually help me avoid problems like this before the user is

Bugs are bugs! :)  Static typing only goes so far to prevent some of
this stuff...just look what you can make a C compiler do with funky
casts.  I take your point though.

-Ben

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/sup-talk/attachments/20090820/575e53e4/attachment.bin>

---

From: [email-masked] (William Morgan)
Date: Mon, 24 Aug 2009 11:13:43 -0700

Reformatted excerpts from Carl Worth's message of 2009-08-19:
> reproduce go away.

Applied, thanks!

> would, but I haven't seen that in practice.

You're right, this is a classic example of the type of bug that would be
caught with static typing. Unit tests are the canonical answer. I'd
argue that unit tests provide better error checking than static typing,
since they allow you to capture the exact set of errors you're
interested in, rather than the set of type mismatches that a
type-checker can detect. (IMO the two sets rarely have more than a very
small overlap.)

Unit tests are only useful, of course, if you write them. Sup doesn't
have very many. I've made an explicit choice to spend my oh-so-limited
Sup time adding new features rather than ensuring a rock-solid platform.
The occasional bug like this is the price we all pay. But it's a matter
of tradeoffs---I do believe that if I were using a statically-typed
language, development would be significantly slower, and Sup would be
nowhere near the point it is now. I have no proof of this statement, of
course.

And if anyone wants to retrofit some unit tests, I'm more than happy to
accept them!
-- 
William <wmorgan-sup at masanjin.net>

---

From: [email-masked] (Nicolas Pouillard)
Date: Tue, 25 Aug 2009 09:44:11 +0200

> > would, but I haven't seen that in practice.

[...]

> I do believe that if I were using a statically-typed

I don't really want to start troll on this subject... However it depends
on what kind of statically-typed language to talk about, if you mean Java
or C++ then I agree with you, the development would be much sloooower.
Although if we take a language like Haskell (or OCaml, or Scala...) the
development become really competitive.

Best regards,

-- 
Nicolas Pouillard
http://nicolaspouillard.fr