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


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

Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA")

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA")
Date 2015-08-10 11:50 -0400
Organization A noiseless patient Spider
Message-ID <mqah4p$fhp$1@dont-email.me> (permalink)
References <ebc4e4ca-b5e1-4da2-8583-1a668606cb2d@googlegroups.com> <mq70q5$20v$1@dont-email.me> <5b08503d-429d-429a-b1af-852563619faa@googlegroups.com> <mqa870$9gi$1@dont-email.me> <da95e9b6-58c1-4cf9-afd3-593f8ee38409@googlegroups.com>

Show all headers | View raw


On 8/10/2015 10:56 AM, e.d.programmer@gmail.com wrote:
> On Monday, August 10, 2015 at 9:18:08 AM UTC-4, Eric Sosman wrote:
>>
>> String-switching is a convenience, sometimes, but it's a costly one.
>
> String switch may be ugly behind the scenes but makes the most readable code where the value you're checking is already a String.
>  [...]

     As I said, "a convenience, sometimes."  FWIW, I've just taken a
quick scan through my own Java projects and have found exactly one
use of String-switch.

     For that matter, switch itself seems less useful in Java than in
other languages.  It's often -- not always, mind you -- preferable to
take advantage of polymorphism: Instead of enumerating all possible
behaviors at compile time as a switch construct must, encapsulate the
behavior in an interface and provide implementations thereof.  Then
you can "switch" on anything you want, as for example:

	Map<Thing,Behavior> behaviors = ...;
	...
	Behavior behavior = behaviors.get(anyThing);
	behavior.behave();

... and future code can easily add new, un-premeditated behaviors.
Aren't you glad Swing fires event notifications instead of hard-
wiring all possible responses in internal switch blocks?

     The switch statement has its uses, when you Really Really Know the
possible set of behaviors is firmly fixed for all time. Still, whenever
I write a switch statement I take it as a hint that my design might be
deficient, and that a better design might make the switch go away.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

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


Thread

PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA") srcommunicationsvja@gmail.com - 2015-08-08 06:53 -0700
  Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA") Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-08-08 10:39 -0400
  Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA") Eternal Hope <laughingspam99@gmail.com> - 2015-08-09 08:53 +0100
    Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA") e.d.programmer@gmail.com - 2015-08-10 05:36 -0700
      Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA") Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-08-10 09:17 -0400
        Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA") e.d.programmer@gmail.com - 2015-08-10 07:56 -0700
          Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA") Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-08-10 11:50 -0400
        Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA") Arne Vajhøj <arne@vajhoej.dk> - 2015-08-12 20:51 -0400
          Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA") Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-08-13 08:25 -0400
            Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA") leif.roar@dimnakorr.com - 2015-08-13 08:43 -0500
      Re: PLEASE SOLVE THIS ERROR (case 1:from=="VIJAYAWADA") Eternal Hope <laughingspam99@gmail.com> - 2015-08-10 15:39 +0100

csiph-web