Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BA6CF7C8D for ; Mon, 15 Aug 2011 22:54:10 +0000 (UTC) Received: (qmail 10153 invoked by uid 500); 15 Aug 2011 22:54:10 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 10002 invoked by uid 500); 15 Aug 2011 22:54:09 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 9994 invoked by uid 99); 15 Aug 2011 22:54:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Aug 2011 22:54:09 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of garydgregory@gmail.com designates 209.85.210.169 as permitted sender) Received: from [209.85.210.169] (HELO mail-iy0-f169.google.com) (209.85.210.169) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 Aug 2011 22:54:04 +0000 Received: by iym1 with SMTP id 1so8071933iym.0 for ; Mon, 15 Aug 2011 15:53:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Y1CVI9HYWaBF/nI3U/LDvVX8P9cDgAoQyTA75OGFoV4=; b=qh4XPznBE/EvxEubLosumOUrteXsFeih94r9fnNmbmLRaSw3M0QI4DnBvUmDvTjTKY N2LSrhXztWvkmB41gDCtZz7RbkWOuKPwL/B+9YFBbEZzOS8AXOdB1k24Vyv53KHjTPI+ Apxvs1tx8YATa1BiiPNyDFpz6RH41i+xtTmWI= MIME-Version: 1.0 Received: by 10.231.4.3 with SMTP id 3mr6435086ibp.72.1313448823962; Mon, 15 Aug 2011 15:53:43 -0700 (PDT) Received: by 10.231.35.205 with HTTP; Mon, 15 Aug 2011 15:53:43 -0700 (PDT) In-Reply-To: References: <7594888142810638917@unknownmsgid> Date: Mon, 15 Aug 2011 18:53:43 -0400 Message-ID: Subject: Re: [codec] Generics added in a SVN branch From: Gary Gregory To: Commons Developers List Content-Type: multipart/alternative; boundary=00151774123c953f3c04aa932249 --00151774123c953f3c04aa932249 Content-Type: text/plain; charset=UTF-8 On Mon, Aug 15, 2011 at 10:12 AM, sebb wrote: > On 14 August 2011 22:38, Gary Gregory wrote: > > Hi, > > > > On Aug 14, 2011, at 10:19, sebb wrote: > > > >> On 14 August 2011 03:02, sebb wrote: > >>> On 12 August 2011 20:56, Gary Gregory wrote: > >>>> Hello All: > >>>> > >>>> For a first cut at generics support in Codec, please checkout the > >>>> branch > https://svn.apache.org/repos/asf/commons/proper/codec/branches/generics > >>>> > >>>> I wrote a migration guide in the root of the project called > >>>> Codec2-Migration.htm. > >>>> > >>>> Let's discuss. > >>> > >>> The original code used Encoder and Decoder interfaces which operated > >>> on Object, and extended these with > >>> BinaryEncoder (byte[]) > >>> StringEncoder(String) > >>> > >>> So for example StringEncoder classes need to implement > >>> encode(Object) : Object > >>> encode(String) : String > >>> > >>> As far as I can tell, those interfaces cannot be directly generified, > >>> because type erasure causes a method signature clash. > >>> So adding generics here means breaking binary compatibilty. > >>> > >>> Question is, what does adding generics to these interfaces actually > provide? > >>> Would it not be just as effective to deprecate Decoder and Encoder, > >>> and code can then use either BinaryEncoder or StringEncoder (etc)? > >>> > >>> At the moment test code is of the form: > >>> > >>> Encoder enc = new Base64(); > >>> ... > >>> byte [] ba = (byte[]) enc.encode(binary)); // unchecked cast > >>> > >>> However this could be written: > >>> > >>> BinaryEncoder enc = new Base64(); > >>> ... > >>> byte [] ba = enc.encode(binary)); // no cast needed > >>> > >> > >> Note that the Encoder/Decoder interfaces do not _require_ > generification. > >> > > > > Well sure. Strictly speaking that's true but I still like the branch > > code better. > > > >> The only non-generified part of trunk is StringEncoderComparator. > >> > > > > I do not quite look at it that way, since I created the branch ;) if > > you just want to fix warnings then yes that class needs patching. But > > my claim in the branch is that the component is better and type-safe > > with generics. > > > >> This appears from the name as if it compares Strings, but in fact it > >> compares Objects in the current code. > >> Making it implement Comparator fixes the warning without > >> compromising binary (or source?) compatibility. > >> > >> The StringEncoders generate an EncoderException if the parameter is > >> not a String. > >> This does mean that comparison with a non-String will return 0 (equal) > >> which is rather strange, but that is the way that the code current > >> works. > > > > That sure sounds like a bug. > > Well, the method .StringEncoderComparator.compare(Object, Object) Javadoc > says: > > @return the Comparable.compareTo() return code or 0 if an encoding > error was caught. > > Does seem like a design bug, as one cannot distinguish failure from > equality. > > >> > >> So what I suggest is - let's release Codec as a binary compatible > >> implementation, at least for now. > > > > ATM there incompat changes due to deprecations and other bits. > > Yes, but those could be reverted if necessary. > > >> > >> If we do decide to break binary compatibility in a later release, then > >> I think the Encoder/Decoder hierarchy needs a bit more work. > >> For example, several of the new xxxCodec classes only implement > >> Decoder, not Encoder; this is because of the need to avoid erasure > >> clashes. > > > > Another set of refinements the ;) > > I don't think the redesign goes quite far enough to fix the interface > inheritance problem. > > What I'm suggesting is to take smaller steps to achieve the goal. > > Release a binary-compatible version now - which has lots of other > useful fixes - and release a completely new version later. > If problems are found with the new stuff, any API changes can be > rolled into the next major version. > Do you mean something like: - Create a branch for 1.6 from trunk now: - Branch 1.6: Revert deprecations and other changes to create a binary compatible release with 1.5. - Release 1.6. - Big changes as Codec2 - Possible Codec3 ? Gary > >> > >> I just wonder if trying to use generics here is not causing more > >> problems than it solves? > >> It's not as if there are lots of different types that are used here - > >> only String, byte[] and char[]. > >> Perhaps we could just add CharEncoder/CharDecoder interfaces instead? > > > > Please see my proposal for the typing of the new BM encoder which I > > want to type as Set encode(String) in a previous email. > > > > Thank you, > > Gary > > > >> > >>>> I plan on not touching trunk until the generics code is flushed out > >>>> and brought back to trunk. > >>>> > >>>> Thank you, > >>>> Gary > >>>> > >>>> -- > >>>> http://garygregory.wordpress.com/ > >>>> http://garygregory.com/ > >>>> http://people.apache.org/~ggregory/ > >>>> http://twitter.com/GaryGregory > >>>> > >>>> --------------------------------------------------------------------- > >>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > >>>> For additional commands, e-mail: dev-help@commons.apache.org > >>>> > >>>> > >>> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > >> For additional commands, e-mail: dev-help@commons.apache.org > >> > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > > For additional commands, e-mail: dev-help@commons.apache.org > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > -- Thank you, Gary http://garygregory.wordpress.com/ http://garygregory.com/ http://people.apache.org/~ggregory/ http://twitter.com/GaryGregory --00151774123c953f3c04aa932249--