Path: csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.xdsl-87-79-255-186.netcologne.de!not-for-mail From: Patrick Roemer Newsgroups: comp.lang.java.programmer Subject: Re: double == double Date: Mon, 17 Oct 2016 19:04:00 +0200 Organization: news.netcologne.de Distribution: world Message-ID: References: <8737k0qd38.fsf@golem.phantasia.org> <87zim5es30.fsf@golem.phantasia.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Mon, 17 Oct 2016 17:04:00 +0000 (UTC) Injection-Info: newsreader4.netcologne.de; posting-host="xdsl-87-79-255-186.netcologne.de:87.79.255.186"; logging-data="19483"; 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 X-Mozilla-News-Host: news://news.netcologne.de In-Reply-To: Xref: csiph.com comp.lang.java.programmer:35802 Responding to a.laforgia@gmail.com: > On Monday, 17 October 2016 03:51:55 UTC+1, Arne Vajhøj wrote: >> Having data and methods operating on the data separate is >> very non-OO'ish in my book. > > That's a kind of purist approach that I find very little pragmatic. Having methods that act on data is how OO is normally implemented. > > This: > > double d1 = 3.4; > double d2 = 5.6; > double dMax = Math.max(d1, d2); > > is certainly better than this: > > class PairOfDoubles { > double d1; > double d2; > > public PairOfDoubles(double d1, double d2) { > this.d1 = d1; > this.d2 = d2; > } > > public double max() { > return d1 >= d2 ? d1 : d2; > } > } Doubles are not objects in Java, which may be considered a flaw in the language itself from an OO point of view, so it's a bit problematic to use them in a discussion of good OO design. In other OO (or hybrid) languages the max API looks different than in Java, and the Java way would likely be considered "non-OO". Take Scala,... scala> 1.23.max(3.14) res0: Double = 3.14 ...Smalltalk,... st> 1.23 max: 3.14 3.14 ...or, kind of an outlier, Ruby. irb(main):001:0> [1.23, 3.14].max => 3.14 "Normally" one might add the operation to the type itself in Java, as well. Exceptions are multiple possible implementations given a single type (e.g. when choosing Comparator over Comparable), 3rd party classes one cannot extend with new methods, or simply lack of objects to get all OO about at all (your example). Best regards, Patrick