Re: [OT] programming style or mental process ?

2021-04-04 Thread tomcat/perl

On 05.04.2021 00:21, Zala Pierre GOUPIL wrote:


In your case, with a function call, this wouldn't make a difference
"if(request.getCharacterEncoding() = null)" would be illegal syntax as
well, but "if(someObject = null)" is perfectly legal, but doesn't
express the author's intent clearly: Is it a smart person who's taking a
shortcut, or a newbie using the wrong operator?



Let the seasoned programmer who's never made that same mistake throw the
first stone.




I think I never did that mistake. Or at least, I didn't realize it.



J'ai jamais tué d'chats
Ou alors y'a longtemps
Ou bien j'ai oublié
Ou ils sentaient pas bon
(Jacques Brel - Ces gens-là)

Couldn't resist.


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



Re: [OT] programming style or mental process ?

2021-04-04 Thread Zala Pierre GOUPIL
> >
> > In your case, with a function call, this wouldn't make a difference
> > "if(request.getCharacterEncoding() = null)" would be illegal syntax as
> > well, but "if(someObject = null)" is perfectly legal, but doesn't
> > express the author's intent clearly: Is it a smart person who's taking a
> > shortcut, or a newbie using the wrong operator?
> >
>
> Let the seasoned programmer who's never made that same mistake throw the
> first stone.
>


I think I never did that mistake. Or at least, I didn't realize it.


Re: [OT] programming style or mental process ?

2021-04-04 Thread tomcat/perl

On 04.04.2021 12:57, Olaf Kock wrote:

Hi André

On 04.04.21 12:23, André Warnier (tomcat/perl) wrote:


   if (null == request.getCharacterEncoding()) {

as opposed to

   if (request.getCharacterEncoding() == null) {


So why do (some) people write it the other way ?
Is it purely a question of individual programming style ?
Is there some (temporary ?) fashion aspect involved ?
Do the people who write this either way really think in a different way ?
Or is there really something "technical" behind this, which makes one
or the other way be slightly more efficient (whether to compile, or
optimise, or run) ?

(*) excepting Yoda of course


I can't say I'm always writing Yoda style, but if I stretch my memory,
then the rationale behind this style of comparisons is to have a
constant on the left side, so that you get a compiler error in case
you're using = instead of ==.


I like that explanation, in the sense that it provides a programming rationale for using 
the first form (and not only in Java), even if it feels intuitively un-natural.

So it's apparently not only fashion or Yoda fandom.
Thanks.



In your case, with a function call, this wouldn't make a difference
"if(request.getCharacterEncoding() = null)" would be illegal syntax as
well, but "if(someObject = null)" is perfectly legal, but doesn't
express the author's intent clearly: Is it a smart person who's taking a
shortcut, or a newbie using the wrong operator?



Let the seasoned programmer who's never made that same mistake throw the first 
stone.


Of course, the style doesn't really help people new to the language, as
they first need to understand that this is something that they might
want to apply to their code. And today, with so many IDE warnings being
flagged while typing, it might be outdated, though it still clearly
expresses the intent to have a real comparison and not an assignment here.

And I agree with the other answer posted already: It makes a lot more
sense in C++ with all the implicit boolean conversions and habits of
outsmarting the code's maintainers with clever expressions.



+1 to that too.


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



Re: [OT] programming style or mental process ?

2021-04-04 Thread Olaf Kock
Hi André

On 04.04.21 12:23, André Warnier (tomcat/perl) wrote:
>
>   if (null == request.getCharacterEncoding()) {
>
> as opposed to
>
>   if (request.getCharacterEncoding() == null) {
>
>
> So why do (some) people write it the other way ?
> Is it purely a question of individual programming style ?
> Is there some (temporary ?) fashion aspect involved ?
> Do the people who write this either way really think in a different way ?
> Or is there really something "technical" behind this, which makes one
> or the other way be slightly more efficient (whether to compile, or
> optimise, or run) ?
>
> (*) excepting Yoda of course
>
I can't say I'm always writing Yoda style, but if I stretch my memory,
then the rationale behind this style of comparisons is to have a
constant on the left side, so that you get a compiler error in case
you're using = instead of ==.

In your case, with a function call, this wouldn't make a difference
"if(request.getCharacterEncoding() = null)" would be illegal syntax as
well, but "if(someObject = null)" is perfectly legal, but doesn't
express the author's intent clearly: Is it a smart person who's taking a
shortcut, or a newbie using the wrong operator?

Of course, the style doesn't really help people new to the language, as
they first need to understand that this is something that they might
want to apply to their code. And today, with so many IDE warnings being
flagged while typing, it might be outdated, though it still clearly
expresses the intent to have a real comparison and not an assignment here.

And I agree with the other answer posted already: It makes a lot more
sense in C++ with all the implicit boolean conversions and habits of
outsmarting the code's maintainers with clever expressions.

Olaf



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



Re: [OT] programming style or mental process ?

2021-04-04 Thread Zero

On 4/4/21 12:23 PM, André Warnier (tomcat/perl) wrote:

Hi.
I have a question which may be totally off-topic for this list, but 
this has been puzzling me for a while and I figure that someone here 
may be able to provide some clue as to the answer, or at least some 
interesting ponts of view.


In various places (including on this list), I have seen multiple 
occurrences of a certain way to write a test, namely :


 if (null == request.getCharacterEncoding()) {

as opposed to

 if (request.getCharacterEncoding() == null) {

Granted, the two are equivalent in the end.
But it would seem to me, maybe naively, that the second form better 
corresponds to some "semantic logic", by which one wants to know if a 
certain a-priori unknown piece of data (here the value obtained by 
retrieving the character encoding of the current request) is defined 
(not null) or not (null).


Said another way : we don't want to know if "null" is equal to 
anything; we want to know if request.getCharacterEncoding() is null or 
not.


Or in yet another way : the focus (or the "subject" of the test) here 
is on "request.getCharacterEncoding()" (which we don't know), and not 
on "null" (which we know already).


Or, more literarily, given that the syntax of most (all?) programming 
languages is based on English (if, then, else, new, for, while, until, 
exit, continue, etc.), we (*) do normally ask "is your coffee cold ?" 
and not "is cold your coffee ?".



So why do (some) people write it the other way ?
Is it purely a question of individual programming style ?
Is there some (temporary ?) fashion aspect involved ?
Do the people who write this either way really think in a different way ?
Or is there really something "technical" behind this, which makes one 
or the other way be slightly more efficient (whether to compile, or 
optimise, or run) ?




Cannot find it back right now.

But I seem to remember that it came from Scott Meyers in C++ programming.

Maybe there it forces the compiler to use the right method when there is 
overloading.



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



[OT] programming style or mental process ?

2021-04-04 Thread tomcat/perl

Hi.
I have a question which may be totally off-topic for this list, but this has been puzzling 
me for a while and I figure that someone here may be able to provide some clue as to the 
answer, or at least some interesting ponts of view.


In various places (including on this list), I have seen multiple occurrences of a certain 
way to write a test, namely :


  if (null == request.getCharacterEncoding()) {

as opposed to

  if (request.getCharacterEncoding() == null) {

Granted, the two are equivalent in the end.
But it would seem to me, maybe naively, that the second form better corresponds to some 
"semantic logic", by which one wants to know if a certain a-priori unknown piece of data 
(here the value obtained by retrieving the character encoding of the current request) is 
defined (not null) or not (null).


Said another way : we don't want to know if "null" is equal to anything; we want to know 
if request.getCharacterEncoding() is null or not.


Or in yet another way : the focus (or the "subject" of the test) here is on 
"request.getCharacterEncoding()" (which we don't know), and not on "null" (which we know 
already).


Or, more literarily, given that the syntax of most (all?) programming languages is based 
on English (if, then, else, new, for, while, until, exit, continue, etc.), we (*) do 
normally ask "is your coffee cold ?" and not "is cold your coffee ?".



So why do (some) people write it the other way ?
Is it purely a question of individual programming style ?
Is there some (temporary ?) fashion aspect involved ?
Do the people who write this either way really think in a different way ?
Or is there really something "technical" behind this, which makes one or the other way be 
slightly more efficient (whether to compile, or optimise, or run) ?


(*) excepting Yoda of course


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