Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #26514

Re: Fixing "typos" in enums...

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Fixing "typos" in enums...
Date 2013-11-15 20:10 +0100
Message-ID <ben9u0FeoueU1@mid.individual.net> (permalink)
References <slrnl8cing.mol.avl@gamma.logic.tuwien.ac.at>

Show all headers | View raw


On 15.11.2013 17:25, Andreas Leitgeb wrote:
> Let's assume, some non native English speaker writes up
> a library, that's really useful and gaining broader use.

> Eventually this misspelling goes into an enum constant,
> and by the time the first user reports it, the library
> is already too much in use to lightheartedly apply
> Plan "A" (namely fixing the typo and thereby inducing a
> compatibility issue)
>
> Now, Plan B could be to rename the enum constant, but add
> a public static field by the old bad name (initialized
> with the reference to the spelling-corrected field), to
> alleviate the compatibility issue at least for those who
> merely used the enum's field's name in their code.
>
>   // public enum Foo { FURST, SECOND }
>   public enum Foo { FIRST, SECOND; public static final FURST = FIRST; }
>
> Any user having done a switch over that enum will still
> need to modify his code. Ditto anyone doing string comparisons
> on foo.name(), but that is most probably a bad idea, anyway.

Not at all: a String could be read from some configuration file or 
database and then the corresponding enum value searched via valueOf() or 
values().

Another issue: serialized values.  You might be able to remedy that via 
the deserialization callbacks.  This is at least something that needs to 
be checked.

Even if certain practices are "bad ideas": they are applied nevertheless.

> PPS: a similar problem could arise with misspelled class names,
>    but that's not currently in my focus.

A published API is basically set in stone.  Keeping the wrong value 
might actually be the best option.

Cheers

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Fixing "typos" in enums... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-11-15 16:25 +0000
  Re: Fixing "typos" in enums... markspace <markspace@nospam.nospam> - 2013-11-15 09:05 -0800
    Re: Fixing "typos" in enums... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-11-18 17:20 +0000
      Re: Fixing "typos" in enums... markspace <markspace@nospam.nospam> - 2013-11-18 09:33 -0800
        Re: Fixing "typos" in enums... Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-11-18 13:37 -0500
        Re: Fixing "typos" in enums... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-11-18 18:58 +0000
          Re: Fixing "typos" in enums... markspace <markspace@nospam.nospam> - 2013-11-18 11:35 -0800
            Re: Fixing "typos" in enums... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-11-18 20:34 +0000
  Re: Fixing "typos" in enums... Robert Klemme <shortcutter@googlemail.com> - 2013-11-15 20:10 +0100
    Re: Fixing "typos" in enums... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-11-18 17:29 +0000
      Re: Fixing "typos" in enums... Robert Klemme <shortcutter@googlemail.com> - 2013-11-18 19:38 +0100
        Re: Fixing "typos" in enums... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-11-18 19:34 +0000
  Re: Fixing "typos" in enums... Jan Burse <janburse@fastmail.fm> - 2013-11-16 10:16 +0100
    Re: Fixing "typos" in enums... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-11-18 18:25 +0000
      Re: Fixing "typos" in enums... Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-11-18 13:45 -0500
        Re: Fixing "typos" in enums... Robert Klemme <shortcutter@googlemail.com> - 2013-11-18 20:20 +0100
        Re: Fixing "typos" in enums... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-11-18 20:09 +0000
          Re: Fixing "typos" in enums... Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-11-18 17:00 -0500
            Re: Fixing "typos" in enums... Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-11-19 15:39 +0000
  Re: Fixing "typos" in enums... Arivald <NOSPAMarivald@interia.pl> - 2013-11-19 00:29 +0100
    Re: Fixing "typos" in enums... lipska the kat <"lipskathekat at yahoo dot co dot uk"> - 2013-11-19 11:14 +0000

csiph-web