From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.36.55.144 with SMTP id r138mr4284109itr.11.1510929941260; Fri, 17 Nov 2017 06:45:41 -0800 (PST) X-Received: by 10.157.81.193 with SMTP id d1mr95299oth.13.1510929941170; Fri, 17 Nov 2017 06:45:41 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.kjsl.com!usenet.stanford.edu!i6no1044547itb.0!news-out.google.com!x87ni1588ita.0!nntp.google.com!i6no1044545itb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 17 Nov 2017 06:45:40 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=155.148.6.150; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 155.148.6.150 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <6bc0f887-a3bb-4aee-9d89-3e0fdfc456d5@googlegroups.com> Subject: Re: Comparing version numbers From: Shark8 Injection-Date: Fri, 17 Nov 2017 14:45:41 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: feeder.eternal-september.org comp.lang.ada:48961 Date: 2017-11-17T06:45:40-08:00 List-Id: On Sunday, November 12, 2017 at 7:39:15 PM UTC-7, Victor Porton wrote: > Not sure if it is quite on-topic, because it is more about general=20 > programming ideas rather than about Ada. (However, a solution in Python o= r=20 > Ruby or JavaScript would more likely used regexps than Ada.) Please don't use regular expressions -- speaking as a software engineer who= 's done maintenance for most of my career Regular Expressions are horridly = brittle and often times the problem isn't Regular (and thus impossible for = Regular Expressions to handle) *or* the data you're operating on changes so= you'd have to rewrite and/or include another Regular Expression to handle = it. >=20 > Suppose I have two version numbers of a software. I need to check which o= f=20 > the two is greater. >=20 > Lexical order string comparison does not work: >=20 > "2.3" vs "11.4". >=20 > I could split it by "." and compare the numbers. But a component of a=20 > version numbers may be nonnumeric like: >=20 > "1.2beta". >=20 > What to do? Hm, I would make a type for handling version-numbers explicitly: Package Versioning is Type Version_Number is private; =20 -- Whatever you actually have in a version. Function Create( Major, Minor, Natural; Build : Positive; Beta : Boolean= :=3D False ) return Version_Number; -- Plus accessors: Function Major( Version : Version_Number ) return Natural; --... -- Plus operations. Procedure Increment_Build (Version in out : Version_Number); Procedure Reset_Build (Version in out : Version_Number); Procedure Increment (Version in out : Version_Number; Major : Bool= ean :=3D False ); --... Function Parse( Input : String ) return Version_Number; Function Image( Input : Version_Number ) return String; Private Type Version_Number is record Major_Number, Minor_Number : Natural; Build : Positive; Beta : Boolean :=3D False end record; End Versioning; The advantage of doing something like this is that it forces you to think a= bout the structure you're using, not blindly flailing about with strings th= at "look like" versions -- remember, in Ada model the problem-space first, = not the solution-space; take advantage of the Fundamental Theory of Ada: Ty= pes (see http://blog.kickin-the-darkness.com/2007/08/fundamental-theory-of-= ada.html ). >=20 > It should work for example for all Debian packages containing interpreter= s=20 > (for example, "2.7" for "python" package). I'm unfamiliar w/ Debian's scheme, but would be unsurprised if the version = field is unstructured text (Unix, and Linux too, seems to be rather enamore= d with unstructured text).