Jump to page: 1 2
Thread overview
[Feature Request] Keywords for symbol operators
Feb 25, 2024
Danilo
Feb 25, 2024
Danilo
Feb 25, 2024
Andrea Fontana
Feb 26, 2024
cc
Feb 26, 2024
Jonathan M Davis
Feb 25, 2024
Elias Batek
Feb 26, 2024
bachmeier
Feb 25, 2024
Guillaume Piolat
Feb 25, 2024
Danilo
Feb 26, 2024
Dom DiSc
Feb 25, 2024
monkyyy
Feb 25, 2024
H. S. Teoh
Feb 26, 2024
Timon Gehr
Feb 26, 2024
Danilo
Feb 26, 2024
user1234
Feb 26, 2024
Danilo
Feb 26, 2024
user1234
February 25, 2024

What about adding keyword forms for some operator symbols, like in C++ ?

Symbol | Keyword
----------------
  !    |   not
  !=   |  noteq
       |
  &&   |   and
  ||   |   or
       |
  &    | bitand
  |    | bitor
February 25, 2024

Programming languages are evolving, like evolution is evolving.

In 2024 it‘s probably better to support alternative keywords
like ‚or‘, ‚and‘, ‚not‘ additionally to plain symbols like ˋ||ˋ, ˋ&&‘, ˋ!ˋ.

Writing clear code using the english language is better
than using cryptic symbols, in modern times.

February 25, 2024

On Sunday, 25 February 2024 at 07:42:16 UTC, Danilo wrote:

>

Programming languages are evolving, like evolution is evolving.

In 2024 it‘s probably better to support alternative keywords
like ‚or‘, ‚and‘, ‚not‘ additionally to plain symbols like ˋ||ˋ, ˋ&&‘, ˋ!ˋ.

Writing clear code using the english language is better
than using cryptic symbols, in modern times.

Quite easy to break existing code in this way. And we're going to add more keywords and "noise".

Andrea

February 25, 2024

On Sunday, 25 February 2024 at 04:55:08 UTC, Danilo wrote:

>

What about adding keyword forms for some operator symbols, like in C++ ?

Symbol | Keyword
----------------
  !    |   not
  !=   |  noteq
       |
  &&   |   and
  ||   |   or
       |
  &    | bitand
  |    | bitor

Would love to have that. C++ has not, and, and or for a while as keywords.
Makes negations more readable!

February 25, 2024
On Sunday, 25 February 2024 at 07:42:16 UTC, Danilo wrote:
> Writing clear code using the english language is better
> than using cryptic symbols, in modern times.

PHP has `and` and `or` (and `xor`) keyword operators and I don’t think anyone is really using them.
People usually go with the symbols instead.

Regarding the “cryptic symbols” claim:
Propositional calculus in math uses symbols, too.
February 25, 2024

On Sunday, 25 February 2024 at 04:55:08 UTC, Danilo wrote:

>

What about adding keyword forms for some operator symbols, like in C++ ?

Symbol | Keyword
----------------
  !    |   not
  !=   |  noteq
       |
  &&   |   and
  ||   |   or
       |
  &    | bitand
  |    | bitor

whats the name of foo["bar",1..5]*=Seq!(13.37,'a');

February 25, 2024
On Sun, Feb 25, 2024 at 08:13:40PM +0000, monkyyy via Digitalmars-d wrote:
> On Sunday, 25 February 2024 at 04:55:08 UTC, Danilo wrote:
> > What about adding [keyword
> > forms](https://en.cppreference.com/w/cpp/language/operator_alternative)
> > for some operator symbols, like in
> > [C++](https://en.cppreference.com/w/cpp/language/operator_logical) ?
> > 
> > ```
> > Symbol | Keyword
> > ----------------
> >   !    |   not
> >   !=   |  noteq
> >        |
> >   &&   |   and
> >   ||   |   or
> >        |
> >   &    | bitand
> >   |    | bitor
> > ```
> 
> whats the name of `foo["bar",1..5]*=Seq!(13.37,'a');`

```d
foo openSquareBracket openDoubleQuote bar closeDoubleQuote comma 1
	doubleDot 5 closeSquareBracket multiplyAssign Seq
	templateArguments openParenthesis 13.37 comma openSingleQuote a
	closeSingleQuote closeParenthesis semicolon
```

See?  Way more readable than the current cryptic syntax. ;-)


T

-- 
I am not young enough to know everything. -- Oscar Wilde
February 25, 2024

On Sunday, 25 February 2024 at 15:24:40 UTC, Guillaume Piolat wrote:

>

Would love to have that. C++ has not, and, and or for a while as keywords.
Makes negations more readable!

Exactly!

Just discovered C++ has keywords 'and'/'or'/'not' etc.
from comments:

>

I've been using and, or and not for years because I feel that it makes the code more readable.

>

Hundred percent. It’s so much more readable to write “not” before a variable in an if statement... I think it’s annoyingly easy to read over the ! in (!longvariablename).

Modern C++ : and, or and not as Boolean Operators

Personally I read about it in C++20/23 books round about 2 years ago for updating my C++98 knowledge, and then just started using it. Takes 1-2 days for getting used to it. ;)

February 26, 2024

On Sunday, 25 February 2024 at 23:40:19 UTC, Danilo wrote:

>

Personally I read about it in C++20/23 books round about 2 years ago for updating my C++98 knowledge, and then just started using it. Takes 1-2 days for getting used to it. ;)

Adding new ways to do the same is a bad idea.
The problem is not the time to get used to it, this can be negligible small.
The problem is that not everybody is going to use the new way.
So you need to get used to both ways - which creates mental load.
And even worse: you can mix them and so generating differences in the code where there are none. By this way you hide were the important differences are. And that will happen, even if you don't intend to do it.

If you want to create a new language (in this case: using english instead of math symbols), stick to it and don't mix it with the old language.

This of course doesn't apply if you have a new concept not available in a language. Then using a term from another language that better describe it is ok - that's the way languages evolve. But simply adding a new word for the same thing is only useful if you explicitly don't want everybody to understand you. E.g. every new generation invents new words for the same concepts, just to be not understood by their parents. Or some "experts" invent a lot of special terms to not be understood by "ordinary" people.

So if you want to create some elite kind of D, do it on your own fork and don't call it D anymore.

February 26, 2024

On Sunday, 25 February 2024 at 07:42:16 UTC, Danilo wrote:

>

Programming languages are evolving, like evolution is evolving.

In 2024 it‘s probably better to support alternative keywords
like ‚or‘, ‚and‘, ‚not‘ additionally to plain symbols like ˋ||ˋ, ˋ&&‘, ˋ!ˋ.

Writing clear code using the english language is better
than using cryptic symbols, in modern times.

I don't consider this an evolution of programming languages. FORTRAN 66 was the first language to have an ANSI standard, and it included these operators, so it's more a recognition that the old guys did it right. COBOL also had them back at least to COBOL 68, (its first standard). Later languages like Lua and Perl have them too.

I'd say at best it's a minor improvement, but it wouldn't have many downsides either.

« First   ‹ Prev
1 2