[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Typed ruby

Joe K

4/26/2008 7:46:00 PM

I realize there is a holy war attached to this subject, but it would be nice
to see a standard notation or library that would give 'types' to variables
and methods, thereby potentially useful for IDE auto-completion; and useful
for the sake of programmer sanity in general. Currently I document all of
my methods and most of my variables with types, seeing no purpose to
re-using variables for different purposes

Is there an endeavor underway anywhere to provide a standard format for
this? If so, I'd like to use it. A quick google search brings up nothing.
24 Answers

Huw Collingbourne

4/26/2008 8:00:00 PM

0

Joe K wrote:
> I realize there is a holy war attached to this subject, but it would be
> nice
> to see a standard notation or library that would give 'types' to
> variables
> and methods, thereby potentially useful for IDE auto-completion; and
> useful


We already do this in Ruby In Steel (see the IntelliSense section and
the part about 'type assertions' mid-way down this page:
http://www.sapphir.../Ruby-In-Steel-Develope... ).

The way we do this currently is by allowing people to assert argument
types and return types in comment blocks. That means that they can gain
extra code-completion and parameter hint capabilities in the Ruby In
Steel IDE without in any way changing the meaning of the Ruby code
itself.

best wishes
Huw Collingbourne

SapphireSteel Software
Ruby and Rails In Visual Studio
http://www.sapphir...
--
Posted via http://www.ruby-....

David A. Black

4/26/2008 8:27:00 PM

0

Hi --

On Sun, 27 Apr 2008, Joe K wrote:

> I realize there is a holy war attached to this subject, but it would be nice
> to see a standard notation or library that would give 'types' to variables
> and methods, thereby potentially useful for IDE auto-completion; and useful
> for the sake of programmer sanity in general. Currently I document all of
> my methods and most of my variables with types, seeing no purpose to
> re-using variables for different purposes
>
> Is there an endeavor underway anywhere to provide a standard format for
> this? If so, I'd like to use it. A quick google search brings up nothing.

Reading between the lines, I suspect you mean class rather than type,
and it's pretty easy to check objects for their class/module ancestry.
The problem is that Ruby objects have a life that's independent of
their ancestry, so things like #is_a? don't really cover the bases.

In general I wouldn't worry too much about it. For whatever reason,
lots of Ruby programmers seem to be pretty sane :-)


David

--
Rails training from David A. Black and Ruby Power and Light:
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
INTRO TO RAILS June 24-27 London (Skills Matter)
See http://www.r... for details and updates!

Phlip

4/26/2008 8:37:00 PM

0

> I realize there is a holy war attached to this subject, but it would be
> nice
> to see a standard notation or library that would give 'types' to variables
> and methods, thereby potentially useful for IDE auto-completion

Is it just my imagination, or do languages that make auto-complete
super-easy for an editor...

....tend to generate 10 times the source code as a Ruby program?

Hmm. Maybe someone's not being as DRY as they could be there...


M. Edward (Ed) Borasky

4/26/2008 10:19:00 PM

0

Huw Collingbourne wrote:
> We already do this in Ruby In Steel (see the IntelliSense section and
> the part about 'type assertions' mid-way down this page:
> http://www.sapphiresteel.com/Ruby-In-Steel-Develope... ).
>
> The way we do this currently is by allowing people to assert argument
> types and return types in comment blocks. That means that they can gain
> extra code-completion and parameter hint capabilities in the Ruby In
> Steel IDE without in any way changing the meaning of the Ruby code
> itself.

And does it also mean that if the comments are incorrect, the IDE gives
you the wrong answer? How do you test for that?

I think we should probably keep the holy war (Ruby vs. Ada for large
projects where large teams need to communicate, tools for such projects,
etc.) going, because I think it's an important topic. Curiously enough,
a couple of years ago at a Scheme workshop, I heard some Schemers claim
that they "consistently" lost speed-coding contests to Java programmers,
all other things being equal, just because of Java's typing mechanisms.
So ...

Arlen Cuss

4/27/2008 12:17:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

Hi,

On Sun, Apr 27, 2008 at 5:50 AM, Joe K <jkauzlar@hotmail.com> wrote:

> and useful for the sake of programmer sanity in general. Currently I
> document all of
> my methods and most of my variables with types, seeing no purpose to
> re-using variables for different purposes


I think programmer sanity is probably helped by not having such a `feature'.
Reusing variables for different purposes is not at all what [not] `typing'
is about, and as David suggested, you possibly mean class, not type.
(singleton methods/whatever-you-want-to-call-them, for example? are they
part of the type? or something else?)

The point of duck typing is that you don't need to/you shouldn't document
the 'types', seeing no purpose to restrict your definition of what's
considered valid input. Surely if the object responds in all the ways you
ask it to, it's fit for the task?

Arlen

Simon Krahnke

4/27/2008 10:25:00 AM

0

* Joe K <jkauzlar@hotmail.com> (21:46) schrieb:

> I realize there is a holy war attached to this subject, but it would be nice
> to see a standard notation or library that would give 'types' to variables
> and methods, thereby potentially useful for IDE auto-completion;

Could you elaborate on this potential usefulness for auto-completion?

mfg, simon .... l

Marc Heiler

4/27/2008 12:52:00 PM

0

> I think we should probably keep the holy war (Ruby vs. Ada for large
> projects where large teams need to communicate, tools for such projects,
> etc.) going, because I think it's an important topic.

I think the Ruby vs Ada was ~more an interesting discussion than a "war"
:)
But I agree, no matter how this is called anyway, it is interesting.
--
Posted via http://www.ruby-....

Clifford Heath

4/27/2008 11:19:00 PM

0

Joe K wrote:
> Is there an endeavor underway anywhere to provide a standard format for
> this?

Not that I know of, but you might find my "chattr" gem useful.

Eivind Eklund

4/28/2008 8:27:00 AM

0

On Mon, Apr 28, 2008 at 12:20 AM, Clifford Heath <no@spam.please.net> wrote:
> Joe K wrote:
>
> > Is there an endeavor underway anywhere to provide a standard format for
> > this?
> >
>
> Not that I know of, but you might find my "chattr" gem useful.

Or, if you want to play with the ability to do complex yet structured
type declarations, http://people.freebsd.org/~eivind/r... -
this predates Gems.

Eivind.

Joe K

4/30/2008 8:58:00 PM

0


> I think programmer sanity is probably helped by not having such a
> `feature'. Reusing variables for different purposes is not at all what
> [not] `typing' is about, and as David suggested, you possibly mean class,
> not type. (singleton methods/whatever-you-want-to-call-them, for example?
> are they part of the type? or something else?)
>
> The point of duck typing is that you don't need to/you shouldn't document
> the 'types', seeing no purpose to restrict your definition of what's
> considered valid input. Surely if the object responds in all the ways you
> ask it to, it's fit for the task?
>
> Arlen


Arlen,

Maybe I'm not in the correct mindset of dynamic programming. I've always
found it difficult to remember return values/parameter-types (i.e. classes)
for a large number of methods. Don't get me wrong, I would much rather use
Ruby at work than Java, but with a good IDE, Java's entire API is available
in pop-up windows AS YOU TYPE. While developing in ruby, I have several
rdoc's open in my web browser, files open in several terminal windows, and
an IRB session open, all for reference purposes when I'm working with
unfamiliar APIs.

Huw Collinbourne's Visual Studio plug-in (link posted in this thread) seems
to have a good, if not slightly cumbersome, notation for giving hints to
the IDE. I prefer a more compact Haskell-like notation (e.g. String *
Integer -> String), but at this point, any standard notation would be
useful.

> Surely if the object responds in all the ways you
> ask it to, it's fit for the task?

Consider the common case of something like DataStructure#remove(). Does
remove take an index or the object to be removed? Usually the API developer
supports one use case or another but not both. You should not have to read
the code to figure out which it is.