Re: OT if/else or not if/else

2016-04-22 Thread Baran Topal
if else i prefer. Multiple ifs sounds like a political programming and you
are not sure what you are doing.

22 Nisan 2016 Cuma tarihinde, Leon Rosenberg 
yazdı:

> Hi guys,
>
> this is completely off-topic ;-)
>
> I was wondering if using if/else is not actually slowing down your code.
> Lets say I have three possible conditions, A, B and C, which are exclusive.
> My native approach would be:
> if (A){...}
> if (B){...}
> if (C){...}
>
> now some people would 'optimize' it as
> if (A){ ...} else if (B) {} else if (C) { }
> and I think in the world of single-cpu computers this optimization could
> work.
>
> But what is now, given that compilers can optimize stuff like this and tell
> the processor to calculate all 3 branches simultaneously, which is not
> possible for ifelse.
>
> Which one would you choose?
> Equally important, which one do you think is more readable? I would say if
> else is hard to read, but this can be just personal impression.
>
> regards
> Leon
>


Tomcat 9.0.0-M4 seems not to start digest algorithm on JDBC Realm as did tomcat 8.0.25

2016-04-22 Thread Fabio Ricci
Dear tomcat Community

I am using cross context (which seems to be easy to configure but in in tomcat 
8 hard to run) … so today I downloaded tomcat 9 and I migrated my apps to it.
In tomcat 9 cross context is running smoothly (thank you!)

To authenticate my config is using JDBCRealm with a mysql database. The config 
below ran very well with tomcat 8 but on tomcat 9 accepted only the password 
digests (which are stored in the table tomcat_users) directly instead of the 
usual passwords. It seems that the digest algorithm MD5 be here not executed.

The config in server.xml is

  

The authentication method is FORM for an application and DIGEST for the 
corresponding API. Both apps sees each other in a cross context.
web.xml of the application contains:


FORM
NAME

/WEB-INF/security/protected/login.jsp
/WEB-INF/security/protected/error.jsp



What shell I do in order to have with the FORM authentication again a digest 
password input? Do I have any possibility to debug it (although I should not…) ?

Thank you in advance
Regards
Fabio


signature.asc
Description: Message signed with OpenPGP using GPGMail


Re: OT if/else or not if/else

2016-04-22 Thread Olaf Kock


Am 22.04.2016 um 18:24 schrieb Leon Rosenberg:
> Hi guys,
>
> this is completely off-topic ;-)
>
> I was wondering if using if/else is not actually slowing down your code.
> Lets say I have three possible conditions, A, B and C, which are exclusive.
> My native approach would be:
> if (A){...}
> if (B){...}
> if (C){...}
>
> now some people would 'optimize' it as
> if (A){ ...} else if (B) {} else if (C) { }
> and I think in the world of single-cpu computers this optimization could
> work.
That would be me - as you say they're mutually exclusive.

>
> But what is now, given that compilers can optimize stuff like this and tell
> the processor to calculate all 3 branches simultaneously, which is not
> possible for ifelse.
>
> Which one would you choose?
> Equally important, which one do you think is more readable? I would say if
> else is hard to read, but this can be just personal impression.
>
> regards
> Leon
I find that the if/else communicates the mutual exclusiveness better
than individual if blocks - thus be implicitly better readable.

Without proper measurements I'd be optimizing purely for readability of
the maintaining developer (which might be me - yes, I'm quite selfish).

*Only* in cases where a proper load test has demonstrated that a
different way to write this code makes a *significant* difference, I'd
shy away from this default. Which includes that this piece of code must
be in a highly frequented section, executed extremely often (otherwise
it wouldn't make a difference).

Yes, compilers can optimize, but developers and maintainers need to
understand the original intent, and they need every clue they can get.
Measure both options under realistic circumstances, then check the
difference. If the difference is significant, you might be up to
something. If it isn't: Make it as readable as possible.

Optimize for the maintainer, not for the compiler. The maintainer might
buy you a beer, the compiler for sure will not.

My 2ct (Euro, of course)
Olaf




-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: OT if/else or not if/else

2016-04-22 Thread Tim Watts
On Fri, 2016-04-22 at 17:34 +0100, Mark Thomas wrote:
> On 22/04/2016 17:24, Leon Rosenberg wrote:
> > Lets say I have three possible conditions, A, B and C, which are exclusive.
> > My native approach would be:
> > if (A){...}
> > if (B){...}
> > if (C){...}
> > 
> > now some people would 'optimize' it as
> > if (A){ ...} else if (B) {} else if (C) { }
> > and I think in the world of single-cpu computers this optimization could
> > work.
> > 

> As an aside, why can't the compile optimize to test the three conditions
> in parallel with the "else if"?

Actually, I would think the compiler could do a parallel optimization
for "if else" but more likely could NOT for a series of "if"s as often
only the programmer knows whether the "if" series is mutually exclusive.

> 
> Mark
> 
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: OT if/else or not if/else

2016-04-22 Thread Caldarale, Charles R
> From: Leon Rosenberg [mailto:rosenberg.l...@gmail.com] 
> Subject: OT if/else or not if/else

> I was wondering if using if/else is not actually slowing down your code.
> Lets say I have three possible conditions, A, B and C, which are exclusive.
> My native approach would be:
> if (A){...}
> if (B){...}
> if (C){...}

> now some people would 'optimize' it as
> if (A){ ...} else if (B) {} else if (C) { }
> and I think in the world of single-cpu computers this optimization could
> work.

This doesn't really have anything to do with the number of CPUs, but rather 
whether or not a single core can execute instructions in parallel 
(vectorization or multiple execution ports).

> But what is now, given that compilers can optimize stuff like this and tell
> the processor to calculate all 3 branches simultaneously, which is not
> possible for ifelse.

These two sets of code are semantically different.  Unless the compiler (not 
the programmer) can prove that A, B, and C are mutually exclusive, the first 
example requires checking all three.  Also, unless the block of code executed 
for a prior true condition can be proven to not affect a later predicate (e.g., 
cannot alias, no side effects), the compiler must issue the three statement 
blocks in order.  Depending on the memory ordering model in play for the 
statements, the compiler may be able to issue speculative reads for each block 
of code, but that's very, very language specific.

A modern CPU core can also speculatively execute instructions, and will likely 
do so with either sequence (assuming typical memory ordering constraints).

> Which one would you choose?

Definitely the if ... else if ... sequence, or the corresponding switch 
statement, if feasible.  Give the compiler as much help as you can to figure 
out the programming intent.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL and is thus for use only by the intended recipient. If you received 
this in error, please contact the sender and delete the e-mail and its 
attachments from all computers.


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: OT if/else or not if/else

2016-04-22 Thread Caldarale, Charles R
> From: David kerber [mailto:dcker...@verizon.net] 
> Subject: Re: OT if/else or not if/else

> But I would add that if the conditions can be reduced to enumerations, a 
> Switch would be even faster.

Actually, a good compiler should generate the same code for switch and if ... 
else if, assuming the boolean expressions used with the ifs are compatible with 
a switch operand.

 - Chuck
 

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL and is thus for use only by the intended recipient. If you received 
this in error, please contact the sender and delete the e-mail and its 
attachments from all computers.


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: OT if/else or not if/else

2016-04-22 Thread David kerber

On 4/22/2016 12:34 PM, Mark Thomas wrote:

On 22/04/2016 17:24, Leon Rosenberg wrote:

Hi guys,

this is completely off-topic ;-)


Excellent. An almost perfect Friday afternoon distraction. You just
needed some decent troll bait to make it perfect. ;)


I was wondering if using if/else is not actually slowing down your code.
Lets say I have three possible conditions, A, B and C, which are exclusive.
My native approach would be:
if (A){...}
if (B){...}
if (C){...}

now some people would 'optimize' it as
if (A){ ...} else if (B) {} else if (C) { }
and I think in the world of single-cpu computers this optimization could
work.

But what is now, given that compilers can optimize stuff like this and tell
the processor to calculate all 3 branches simultaneously, which is not
possible for ifelse.

Which one would you choose?


If (A){ ...} else if (B) {} else if (C) { }


Equally important, which one do you think is more readable? I would say if
else is hard to read, but this can be just personal impression.


Same one.

Regarding performance it depends on exactly what you are measuring and
how. Testing the conditions in parallel will be quicker if B or C is the
true condition. But, you will be doing more work as a result so in
theory throughput will fall.

Personally, I'd stick if "else if" and order the conditions from most
likely to least likely.

As an aside, why can't the compile optimize to test the three conditions
in parallel with the "else if"?


+1.  I prefer the if ... else if ... construct for readability as long 
as the are mutually exclusive.


But I would add that if the conditions can be reduced to enumerations, a 
Switch would be even faster.




-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: OT if/else or not if/else

2016-04-22 Thread James H. H. Lampert

But what is now, given that compilers can optimize stuff like this and tell
the processor to calculate all 3 branches simultaneously, which is not
possible for ifelse.

Which one would you choose?
Equally important, which one do you think is more readable? I would say if
else is hard to read, but this can be just personal impression.


1. Simultaneous execution of sequential IF blocks is not necessarily a 
good idea, as it could change the meaning of the code.


2. If you're using more than two mutually exclusive alternatives, then 
why are you using IF at all, unless you're working in a language that 
doesn't have any form of CASE construct? (Nearly everything based on C 
or ALGOL syntax has some form of it, and even primitive BASIC has 
ON...GOTO, or occasionally GOTO...ON, and even the most primitive 
versions of RPG I've worked with -- hardly a modern language -- have 
SELECT...WHEN...OTHER blocks).


--
JHHL

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: OT if/else or not if/else

2016-04-22 Thread Mark Thomas
On 22/04/2016 17:24, Leon Rosenberg wrote:
> Hi guys,
> 
> this is completely off-topic ;-)

Excellent. An almost perfect Friday afternoon distraction. You just
needed some decent troll bait to make it perfect. ;)

> I was wondering if using if/else is not actually slowing down your code.
> Lets say I have three possible conditions, A, B and C, which are exclusive.
> My native approach would be:
> if (A){...}
> if (B){...}
> if (C){...}
> 
> now some people would 'optimize' it as
> if (A){ ...} else if (B) {} else if (C) { }
> and I think in the world of single-cpu computers this optimization could
> work.
> 
> But what is now, given that compilers can optimize stuff like this and tell
> the processor to calculate all 3 branches simultaneously, which is not
> possible for ifelse.
> 
> Which one would you choose?

If (A){ ...} else if (B) {} else if (C) { }

> Equally important, which one do you think is more readable? I would say if
> else is hard to read, but this can be just personal impression.

Same one.

Regarding performance it depends on exactly what you are measuring and
how. Testing the conditions in parallel will be quicker if B or C is the
true condition. But, you will be doing more work as a result so in
theory throughput will fall.

Personally, I'd stick if "else if" and order the conditions from most
likely to least likely.

As an aside, why can't the compile optimize to test the three conditions
in parallel with the "else if"?

Mark


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



OT if/else or not if/else

2016-04-22 Thread Leon Rosenberg
Hi guys,

this is completely off-topic ;-)

I was wondering if using if/else is not actually slowing down your code.
Lets say I have three possible conditions, A, B and C, which are exclusive.
My native approach would be:
if (A){...}
if (B){...}
if (C){...}

now some people would 'optimize' it as
if (A){ ...} else if (B) {} else if (C) { }
and I think in the world of single-cpu computers this optimization could
work.

But what is now, given that compilers can optimize stuff like this and tell
the processor to calculate all 3 branches simultaneously, which is not
possible for ifelse.

Which one would you choose?
Equally important, which one do you think is more readable? I would say if
else is hard to read, but this can be just personal impression.

regards
Leon


Tomcat 8.0.28 and above

2016-04-22 Thread bhanu lakkala
Tomcat Team:
I have been working on an issue for the past few days and wanted to check
with you guys if you have any suggestions on fixing this issue.
My current technology stack is: windows 7, java 7/8, tomcat 8, axis2 1.6.3.
I have an axis2 based web service that is very basic and it just connects
to a database and reads some info and spits out the info it read.
I have setup a JNDI resource for the datasource.  In the service's init
class's startup method, I am attempting to load the spring's
ApplicationContext and thereby load the JNDI resource.
All of this used to work well with the combination of java 7, tomcat 7.x
axis2 1.6.3.
Recently due to a need to upgrade to newer version of tomcat, I upgraded to
tomcat 8. this resulted in "Name not found" exception.  I ditched the
spring's usage of finding jndi resource and used the initContext to lookup
the JNDI resource and it worked fine. I have to use spring to find the JNDI
context since most of our applications are already using spring and if i
need to change every single one of them it is a tedious process.
We also have a unix environment that I tested this with and I didn't find
any issues there. i.e., I used spring to load the jndi resource, tomcat
8.x, java 7, axis2 1.6.3.
Since this is a windows only issue, I tried to upgrade to Tomcat 9.x and
that resulted in the same error.
I have also posted this issue on the stackoverflow site but haven't had
much luck finding a solution to the issue.
http://stackoverflow.com/questions/36207119/tomcat-8-axis2-webservices-aar-spring-jndi-not-bound-in-context

Any help is greatly appreciated.

Thank you,
Bhanu Lakkala