Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35801
| Path | csiph.com!1.us.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!news.unit0.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.xdsl-87-79-255-186.netcologne.de!not-for-mail |
|---|---|
| From | Patrick Roemer <sangamon@netcologne.de> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: double == double |
| Date | Mon, 17 Oct 2016 18:58:09 +0200 |
| Organization | news.netcologne.de |
| Distribution | world |
| Message-ID | <nu2vv1$ikt$1@newsreader4.netcologne.de> (permalink) |
| References | <double-20161012130409@ram.dialup.fu-berlin.de> <ntledh$lfi$1@dont-email.me> <8737k0qd38.fsf@golem.phantasia.org> <87zim5es30.fsf@golem.phantasia.org> <nttf6l$nml$1@gioia.aioe.org> <ntu9de$6uj$1@dont-email.me> <ntuhmi$cdr$1@gioia.aioe.org> <ntuntn$slf$2@dont-email.me> <nu00a0$5sj$1@gioia.aioe.org> <nu00ks$edh$5@dont-email.me> <nu063a$edp$1@gioia.aioe.org> <nu075n$4cs$1@dont-email.me> <nu0bcj$nbt$1@gioia.aioe.org> <nu0dsb$kv3$3@dont-email.me> <nu0g1b$vt5$2@gioia.aioe.org> <nu0qtc$eiu$1@dont-email.me> <nu1e88$9gn$1@gioia.aioe.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Mon, 17 Oct 2016 16:58:09 +0000 (UTC) |
| Injection-Info | newsreader4.netcologne.de; posting-host="xdsl-87-79-255-186.netcologne.de:87.79.255.186"; logging-data="19101"; mail-complaints-to="abuse@netcologne.de" |
| User-Agent | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.24) Gecko/20100411 Thunderbird/2.0.0.24 Mnenhy/0.7.6.0 |
| In-Reply-To | <nu1e88$9gn$1@gioia.aioe.org> |
| Xref | csiph.com comp.lang.java.programmer:35801 |
Show key headers only | View raw
Responding to Arne Vajhøj:
> On 10/16/2016 5:19 PM, 4ndre4 wrote:
>> On 16/10/2016 19:14, Arne Vajhøj wrote:
>>
>> [...]
>>> But that code is not using String as version
>>
>> Erm... how about this? :) I don't see how this is less OO-ish than the
>> previous one, but hey... okay!...:
>>
>> List<String> versions = new ArrayList<String>();
>>
>> versions.add("1.9.0-123");
>> versions.add("1.10.0-123");
>> versions.add("1.7.0-123");
>> versions.add("1.7.0-123");
>> versions.add("1.7.0-10");
>> versions.add("1.7.0-9");
>>
>> Collections.sort(versions, new VersionComparator());
>>
>> ...
>>
>> static class VersionComparator implements Comparator<String> {
>
>> public int compare(String version1, String version2) {
>> try {
>> ParsedVersion pv1 = parse(version1);
>> ParsedVersion pv2 = parse(version2);
>> if (pv1.equals(pv2)) return 0;
>> if (pv1.lessThan(pv2)) return -1;
>> return 1;
>> } catch (InvalidVersionException e) {
>> throw new IllegalArgumentException(e);
>> }
>> }
>
> Having data and methods operating on the data separate is
> very non-OO'ish in my book.
I don't think this describes the actual problem well. There may be
perfectly good, OO-compatible reasons to separate comparison logic from
the domain class - after all, that's why Comparator exists. For example,
there may be occasions when one wants to compare only based on the major
(major + minor,...) version parts.
But this code defies a more general programming principle: Describe your
concepts as dedicated types and define operations for those types.
Passing an opaque string around to be interpreted as a version only
"when needed" feels fishy to me in any paradigm.
With this approach, one has to rely on variable names and comments to
know what the string is supposed to represent. It is inefficient,
because one is bound to re-parse on every comparison. And there's no
easy way of knowing whether a given variable holds a valid version
number or whether one has to be prepared for an exception upon
comparison. With a dedicated Version type, you parse once at whatever
boundary the string enters the system, and from then on you have a
guaranteed valid version with a "speaking" type that can be compared
efficiently and that can easily be extended with other version-specific
functionality in future, erm, versions.
Best regards,
Patrick
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: double == double Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-12 09:39 -0400
Re: double == double Michael Jung <miju@golem.phantasia.org> - 2016-10-13 21:10 +0200
Re: double == double Michael Jung <miju@golem.phantasia.org> - 2016-10-15 14:04 +0200
Re: double == double Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-15 09:13 -0400
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-15 10:32 -0400
Re: double == double Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-15 10:46 -0400
Re: double == double Michael Jung <miju@golem.phantasia.org> - 2016-10-15 17:44 +0200
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-15 17:36 +0100
Re: double == double Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-15 14:15 -0400
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-15 19:41 +0100
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-15 20:39 -0400
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-15 10:41 -0400
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-15 23:09 +0100
Re: double == double Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-15 18:28 -0400
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-16 03:13 +0100
Re: double == double Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-16 08:37 -0400
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-16 14:06 +0100
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-15 20:30 -0400
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-16 03:16 +0100
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-16 03:18 +0100
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-16 09:45 -0400
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-16 14:51 +0100
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-16 11:24 -0400
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-16 16:43 +0100
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-16 12:54 -0400
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-16 18:37 +0100
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-16 14:14 -0400
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-16 22:19 +0100
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-16 22:49 -0400
Re: double == double a.laforgia@gmail.com - 2016-10-17 01:53 -0700
Re: double == double Patrick Roemer <sangamon@netcologne.de> - 2016-10-17 19:04 +0200
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-17 20:17 +0100
Re: double == double Patrick Roemer <sangamon@netcologne.de> - 2016-10-17 23:11 +0200
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-17 22:46 +0100
Re: double == double Patrick Roemer <sangamon@netcologne.de> - 2016-10-18 18:55 +0200
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-18 18:52 +0100
Re: double == double Patrick Roemer <sangamon@netcologne.de> - 2016-10-20 15:03 +0200
True O-O [Was: double == double] Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-10-17 18:06 -0400
Re: True O-O Patrick Roemer <sangamon@netcologne.de> - 2016-10-18 18:32 +0200
Re: True O-O [Was: double == double] Arne Vajhøj <arne@vajhoej.dk> - 2016-10-19 22:09 -0400
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-19 21:58 -0400
Re: double == double Patrick Roemer <sangamon@netcologne.de> - 2016-10-17 18:58 +0200
Re: double == double 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-17 20:32 +0100
Re: double == double Patrick Roemer <sangamon@netcologne.de> - 2016-10-17 23:21 +0200
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-19 21:38 -0400
Re: double == double Arne Vajhøj <arne@vajhoej.dk> - 2016-10-19 21:47 -0400
Re: double == double Patrick Roemer <sangamon@netcologne.de> - 2016-10-20 15:01 +0200
csiph-web