AND and OR in if statement

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

AND and OR in if statement

Francis Clavette
Hi, 
I’d like to be able to use AND for && and OR for || in conditional statements in a future version of ECMAScript. It’s a feature I’ve always been wanting since transitioning from PHP. It’s also much cleaner : 

if ($scope.newSourceModal.isShown() && $scope.newsource.type == "book" && (!$scope.insertingFromScan || $scope.ok))

==============

if ($scope.newSourceModal.isShown() AND $scope.newsource.type == "book" AND (!$scope.insertingFromScan OR $scope.ok))


Francis

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: AND and OR in if statement

Jonathan Barronville
No, please don't do this. While I understand why you want this, I feel like this is unnecessary and will just introduce yet another way to write inconsistent and confusing JavaScript code 😕.

- Jonathan



Life is a game and we’re all just high density pixels.
On May 24 2016, at 9:15 pm, Francis Clavette <[hidden email]> wrote:
Hi, 
I’d like to be able to use AND for && and OR for || in conditional statements in a future version of ECMAScript. It’s a feature I’ve always been wanting since transitioning from PHP. It’s also much cleaner : 

if ($scope.newSourceModal.isShown() && $scope.newsource.type == "book" && (!$scope.insertingFromScan || $scope.ok))

==============

if ($scope.newSourceModal.isShown() AND $scope.newsource.type == "book" AND (!$scope.insertingFromScan OR $scope.ok))


Francis

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: AND and OR in if statement

kdex
In reply to this post by Francis Clavette
Could you explain how your second example is cleaner? All I see is that it's longer; the rest is merely a matter of taste.
JavaScript's syntax was, amongst others, heavily influenced by C-family languages (which went for `&&` and `||` as well as `&` and `|`).

Next, I think it's confusing that, although we're calling it "bitwise and" and "bitwise or", we would only be able to write `and` or `or` in a logical context; this choice is entirely arbitrary. Bitwise operators would still need to be `&` and `|` since there's no way to tell what your intent is just from the syntax.

IMHO, the current operators `&&`, `&`, `||` ,`|` are the cleanest implementation of `and` and `or` that I could think of.

On Dienstag, 24. Mai 2016 21:14:59 CEST Francis Clavette wrote:

> Hi,
> I’d like to be able to use AND for && and OR for || in conditional statements in a future version of ECMAScript. It’s a feature I’ve always been wanting since transitioning from PHP. It’s also much cleaner :
>
> if ($scope.newSourceModal.isShown() && $scope.newsource.type == "book" && (!$scope.insertingFromScan || $scope.ok))
>
> ==============
>
> if ($scope.newSourceModal.isShown() AND $scope.newsource.type == "book" AND (!$scope.insertingFromScan OR $scope.ok))
>
>
> Francis
>
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: AND and OR in if statement

Andy Earnshaw-2
It's not feasible anyway because AND and OR are already valid identifiers:

a = foo()
  &&(bar)

is equivalent to `a = foo() && bar`, but

a = foo()
  AND(bar)

is equivalent to

a = foo();
AND(bar);

On Wed, 25 May 2016 at 02:29 kdex <[hidden email]> wrote:
Could you explain how your second example is cleaner? All I see is that it's longer; the rest is merely a matter of taste.
JavaScript's syntax was, amongst others, heavily influenced by C-family languages (which went for `&&` and `||` as well as `&` and `|`).

Next, I think it's confusing that, although we're calling it "bitwise and" and "bitwise or", we would only be able to write `and` or `or` in a logical context; this choice is entirely arbitrary. Bitwise operators would still need to be `&` and `|` since there's no way to tell what your intent is just from the syntax.

IMHO, the current operators `&&`, `&`, `||` ,`|` are the cleanest implementation of `and` and `or` that I could think of.

On Dienstag, 24. Mai 2016 21:14:59 CEST Francis Clavette wrote:
> Hi,
> I’d like to be able to use AND for && and OR for || in conditional statements in a future version of ECMAScript. It’s a feature I’ve always been wanting since transitioning from PHP. It’s also much cleaner :
>
> if ($scope.newSourceModal.isShown() && $scope.newsource.type == "book" && (!$scope.insertingFromScan || $scope.ok))
>
> ==============
>
> if ($scope.newSourceModal.isShown() AND $scope.newsource.type == "book" AND (!$scope.insertingFromScan OR $scope.ok))
>
>
> Francis
>
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: AND and OR in if statement

Claude Pache
In reply to this post by kdex

> Le 25 mai 2016 à 03:29, kdex <[hidden email]> a écrit :
>
> IMHO, the current operators `&&`, `&`, `||` ,`|` are the cleanest implementation of `and` and `or` that I could think of.

I don’t think so: It is not ideal that the longest forms, `&&` and `||`, are by far the most current ones. But this is history that we cannot change.

Having to sets of logical operators, `&&`/`||` versus `and`/`or`, **with different precedence**, is very useful in idiomatic Perl, where they are typically used to express control-flow. But much less so in idiomatic JS.

—Claude

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: AND and OR in if statement

Rick Waldron
In reply to this post by Francis Clavette
This is a non-starter, as AND and OR are already valid identifiers. 

On Tue, May 24, 2016 at 9:15 PM Francis Clavette <[hidden email]> wrote:
Hi, 
I’d like to be able to use AND for && and OR for || in conditional statements in a future version of ECMAScript. It’s a feature I’ve always been wanting since transitioning from PHP. It’s also much cleaner : 

if ($scope.newSourceModal.isShown() && $scope.newsource.type == "book" && (!$scope.insertingFromScan || $scope.ok))

==============

if ($scope.newSourceModal.isShown() AND $scope.newsource.type == "book" AND (!$scope.insertingFromScan OR $scope.ok))


Francis
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: AND and OR in if statement

Caitlin Potter
Devils advocate: if you were to measure usage of identifiers named “and” or “or”, on the web, how substantial do you think their use would be? And even if they were used a fair bit, that hasn’t really stopped the introduction of other contextual keywords in the past.

If you really wanted to, you could find a way to make this work. But I’m not saying we need to turn JS into Python or Perl.

On May 25, 2016, at 7:20 PM, Rick Waldron <[hidden email]> wrote:

This is a non-starter, as AND and OR are already valid identifiers. 

On Tue, May 24, 2016 at 9:15 PM Francis Clavette <[hidden email]> wrote:
Hi, 
I’d like to be able to use AND for && and OR for || in conditional statements in a future version of ECMAScript. It’s a feature I’ve always been wanting since transitioning from PHP. It’s also much cleaner : 

if ($scope.newSourceModal.isShown() && $scope.newsource.type == "book" && (!$scope.insertingFromScan || $scope.ok))

==============

if ($scope.newSourceModal.isShown() AND $scope.newsource.type == "book" AND (!$scope.insertingFromScan OR $scope.ok))


Francis
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

signature.asc (859 bytes) Download Attachment