Version comparison using strings can be faulty. #2024

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
5 participants
Contributor

bratish commented Jul 9, 2011

Version comparison using strings (in the situations like RUBY_VERSION < '1.9.2') can be faulty at times.
Gem::Version is now equipped with symbols for version comparison. It can be used like Gem.ruby_version < '1.9.2'.

Member

josevalim commented Jul 9, 2011

Instead of reopening Gem, maybe we should define ActiveSupport::GemVersion or something like that?

Owner

tenderlove commented Jul 9, 2011

This seems like a theoretic problem to me. In theory, it could break. In practice? I have doubts. I'm -1 on this.

Contributor

bratish commented Jul 10, 2011

@josevalim: Will that be very helpful? Internally Gem::Version#<=> is used for comparing. So in any case Gem will come into picture. What do you think?

@tenderlove: I believe, a problem is a problem and it must be addressed. With the string checking approach, Ruby major version 9 is not less than 10. Yeah, major version will not be there in very near future, but this is a failure. For minor version numbers also, is there a policy that prevents them rise past 9?

Additionally this is not only about Ruby versioning. Any gem/lib version can be checked/compared smartly with these methods.

tenderlove closed this Jul 10, 2011

Owner

tenderlove commented Jul 10, 2011

We will not monkey patch Gem. Otherwise @drbrain and @zenspider will be upset.

Let's revisit this in 6 years when 1.9.9 is released. In the mean time, we'll avoid the code complexity and maintenance burden of a problem that may (or may not) exist in the future.

Contributor

bratish commented Jul 10, 2011

As I said, this is not only about the Ruby version. This could have been helpful for other version checking also, like
Gem::Version.new(SomeGem::Version) > "x.y.z"

Member

josevalim commented Jul 10, 2011

But the usage inside Rails is limited only to RUBY_VERSION, so I stand by @tenderlove comment. Other people can require and use Gem::Version on their own. :)

Contributor

bratish commented Jul 10, 2011

ok.

Contributor

samuelkadolph commented Jul 10, 2011

There won't be a ruby 1.10. Matz said so.

Hi,

In message "Re: Next Major Version (was Re: Different semantics of Proc
and method call -- bug or feature?)"
on Thu, 3 Aug 2006 00:38:41 +0900, "N Okia" wrecklass1@gmail.com
writes:

|In keeping with your current numbering scheme, does this mean there
|will be a ruby 1.10 release?

The version letters will be stay in one letter each, so that 1.a will
be more likely than 1.10.

http://www.ruby-forum.com/topic/75670#116599

Hi,

In message "Re: Next Major Version (was Re: Different semantics of Proc
and method call -- bug or feature?)"
on Fri, 4 Aug 2006 00:26:39 +0900, "Rick DeNatale"
rick.denatale@gmail.com writes:

|> The version letters will be stay in one letter each, so that 1.a will
|> be more likely than 1.10.

|Matz,
|
|I hesitate to ask YOU this, but are you really sure you want to go that way.
|
|Almost every software package I've run across keeps each level of the
|version "number" as a number, so 1.10 would be much more in line with
|standard practice than 1.a

Ah, well, I forgot to put smiley after the sentence. No, we are not
going to name it neither "1.a" nor "1.10". 1.8.9 will be the last
release of the current stable series. And 1.9 will be the last of the
1.x.

http://www.ruby-forum.com/topic/75670#117142

drbrain commented Jul 10, 2011

Gem::Version uses Comparable and #<=> to define #<, #<=, etc.

The Gem::Version patch may be useful if altered <=> instead of all the methods Comparable defines.

Contributor

bratish commented Jul 10, 2011

@samuelkadolph: This reference is informative. Thank you.

@drbrain: I am sorry, but I couldn't get the whole (English is not my first language :( ) of your post. Please help.
By Comparable you mean [ http://www.ruby-doc.org/core/classes/Comparable.html ] right?
This Gem::Version patch uses spaceship to define others similar to Comparable module methods except #between?. Do you suggest to include that as well?

drbrain commented Jul 13, 2011

@bratish your patch is wrong. To use Comparable you define <=> to do what you need and let Comparable's <, <=, etc call <=> for you. Don't define the methods Comparable defines, it's there to help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment