[squeak-dev] Re: 1.0 not a valid VersionNumber?

Bert Freudenberg bert at freudenbergs.de
Wed Apr 9 18:45:07 UTC 2008


On 09.04.2008, at 10:54, Brett Kosinski wrote:
>> Stephen Pair wrote:
>>
>>>   Simplified example. The real version number I'm interested in  
>>> looks
>>>   like "1.0.34". But it looks like VersionNumber is a no-go for me
>>>   anyway as you can't even compare, e.g., '1.1.1' asVersion <=  
>>> '1.2.3'
>>>   asVersion. Does anyone actually use VersionNumber? I must be  
>>> missing
>>>   the real use cases for it.
>>>
>>>
>>> I'm curious whether you'd expect this to return true or false (I'm  
>>> guess
>> true).  The reason it refuses that compasion is that #< is meant to  
>> test
>> whether a given version number is an ancestor of another.  If you  
>> want the
>> stringish comparison behavior, you could just use string.
>>>
>>
>> I wish...
>>
>>  '1.1.2' < '1.12.3'
>>
>> => false
>
> Yeah, fundamentally, what you're asking just doesn't make sense for
> the semantics of the VersionNumber class.  You're basically comparing
> two revisions on different branches,.
>
> It sounds to me like you need a separate ReleaseNumber class, or
> something similar, that uses major.minor.patchlevel.  Internally,
> though, you should just be incrementing the VersionNumber
> sequentially... then mapping the VersionNumber to some ReleaseNumber
> when a release gets cut.


I like a "natural ordering" approach to this: split the string into  
runs of letters, digits, and others. Then compare numerically for all- 
digit runs and alphabetically for the rest:

SequenceableCollection>>sortsBefore: anotherCollection
	1 to: self size do: [:i |
		(self at: i) < (anotherCollection at: i) ifTrue: [^true].
		(anotherCollection at: i) < (self at: i) ifTrue: [^false]].
	^self size < anotherCollection size


String>>findSortTokens
	| in p |
	^Array streamContents: [:tokens |
		in := self readStream.
		p := in position.
		[in atEnd] whileFalse: [
			[in atEnd not and: [in peek isLetter]] whileTrue: [in next].
			in position > p ifTrue:
				[tokens nextPut: (self copyFrom: p+1 to: (p := in position))].
			[in atEnd not and: [in peek isDigit]] whileTrue: [in next].
			in position > p ifTrue:
				[tokens nextPut: (self copyFrom: p+1 to: (p := in position))  
asNumber].
			[in atEnd not and: [in peek isAlphaNumeric not]] whileTrue: [in  
next].
			in position > p ifTrue:
				[tokens nextPut: (self copyFrom: p+1 to: (p := in position))]]]

'1.1alpha' findSortTokens sortsBefore: '1.10beta' findSortTokens => true

(I also like this order for file lists in general - the Mac Finder  
uses something similar)

- Bert -





More information about the Squeak-dev mailing list