If you touch various languages, the detailed specifications of the language will gradually become messed up, so this is a memo.
With or without increment decrement
Yes: Java, C, C ++, Go △, PHP, Perl, JavaScript None: Scala, Rust, Python, Ruby
By treating the Go language as a statement rather than an operator that composes an expression, it avoids the problem of an increment operator, and I personally feel that it is just the right specification.
I also checked the assignment operator, but it seems to be in most languages.
Scala
--No increment / decrement operator --There is an assignment operator
i += 1
i -= 1
ʻI + = 1 etc. is syntactic sugar such as ʻi = i + 1
.
reference
Assignment Operators - Expressions | Scala 2.13
Why can't I increment or decrement in Scala?
Java
--Increment / decrement operators have both prefixes and suffixes --Expression and returns a value --There is also an assignment operator
++i;
--i;
i++;
i--;
i += 1;
i -= 1;
reference
Prefix Increment Operator ++ - Java Language Specification
Rust
--No increment / decrement operator --There is an assignment operator
i += 1;
i -= 1;
reference
Compound assignment expressions - Operator expressions - The Rust Reference
Why is there no increment operator? Why doesn't Rust have increment and decrement operators?
--Increment / decrement operators have both prefixes and suffixes --Expression and returns a value --There is also an assignment operator
++i;
--i;
i++;
i--;
i += 1;
i -= 1;
--Increment / decrement operator in C language is only postfix --Since it is treated as a statement, not an expression, it cannot be embedded in an expression. --There is also an assignment operator
i++
i--
i += 1
i -= 1
reference
IncDec statements - The Go Programming Language Specification
The case where ++
and --
are not operators
Operators and Statements — Programming Language Go | text.Baldanders.info
PHP
--Increment / decrement operators have both prefixes and suffixes --Expression and returns a value --There is also an assignment operator
++$i;
--$i;
$i++;
$i--;
$i += 1;
$i -= 1;
reference
Adder / Subtractor | PHP Manual
Perl
--Increment / decrement operators have both prefixes and suffixes --Expression and returns a value --There is also an assignment operator
++$i;
--$i;
$i++;
$i--;
$i += 1;
$i -= 1;
reference
Increment and decrement --perlop --Perl operators and precedence --perldoc.jp
Python
--No increment / decrement operator --There is an assignment operator
i += 1
i -= 1
It seems to be a cumulative assignment statement.
reference
Augmented assignment statement-simple statement — Python 3.8.0 documentation
Ruby
--No increment / decrement operator --There is an assignment operator
i += 1
i -= 1
It seems to be self-assignment.
reference
Operator expression (Ruby 2.6.0)
Why there is no such thing as an increment operator in Ruby --fugafuga.write
Comparison of Ruby increment speed by version --Qiita
JavaScript
--Increment / decrement operators have both prefixes and suffixes --Expression and returns a value --There is also an assignment operator
++i;
--i;
i++;
i--;
i += 1;
i -= 1;
reference
Update Expressions - ECMAScript® 2019 Language Specification
Recommended Posts