Comments (4)
As I just learned, the behavior that I described can be achieved by
i += 1 and i -=1
This gets compiled to inc and dec
I, nevertheless, think that implementing i++ and i-- would also help developers, since, coming from the C++, C# and Java world, the i++ first came into my mind. Also the += and -= operators are mainly used for more complex expressions I think.
from millfork.
Sorry, Millfork will never have those operators. Millfork explicitly rejects bad parts of syntax of B (I guess it's cool that you can take code from late 60s and compile it as C#, but Millfork is not for that), and these operators are only the tip of the iceberg. In fact, the only reason B had ++
and --
was because the compiler was too dumb to optimize +=1
and -=1
, and that incapability trickled down to too many modern languages. Millfork is an optimizing compiler, and +=1
and -=1
are explicitly special-cased to compile to a single INC/DEC when possible.
There are several reasons for not including ++
and --
:
- Millfork does not have unary operators other than
-
. This is by design, and even-
was only added later. ++
and--
introduce parsing ambiguity.--a
currently means-(-a)
and introducing a new--
operator would break that. Similarly with things likea--b
, which is currently parsed asa-(-b)
- Most languages that have those operators, treat them as expressions, which can cause confusion between preincrement and postincrement variants as @agg23 mentioned in the previous comment. In Millfork, assignments are not expressions, and since they are not,
+= 1
is fine and readable. - Most instances of
++
are found in C-style loops, but Millfork has range-based loops. - Some languages use
++
and--
for other things.
Further reading:
- list of some more important differences between Millfork and C: https://github.com/KarolS/millfork/blob/master/docs/various/cdiff.md
- this article was hugely influential on Millfork's syntax: https://eev.ee/blog/2016/12/01/lets-stop-copying-c/
- why Swift removed those operators: https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md
- why Ruby doesn't have them: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/2710
- why Rust doesn't have them: https://github.com/dtolnay/rust-faq#why-doesnt-rust-have-increment-and-decrement-operators
from millfork.
I would argue that +=
is much clearer than ++
due to the expression nature of x++
. You could do something like y = x++
or y = ++x
and get different results, and often developers don't properly understand what the expression means.
from millfork.
Thanks, makes 100% sense to me :-)
from millfork.
Related Issues (20)
- Structs can't have volitile members HOT 1
- file array initiliser can't handle maths
- Address of sid_v1_sr in file c64_sid.mfk is incorrect HOT 1
- 65CE02 JSR incorrect Assmbly HOT 1
- Multiline comments HOT 5
- possible to pass a function to a macro? or find the identifier for the current function? HOT 3
- Maths doesn't promote to destination type HOT 6
- compiler accepts 'array(type)' but not 'array (type)'
- switch_hirom in c64_easyflash.mfk should write to $DE00 not $DE01
- clear_carry return doesn't work ?
- for x : array strange behavior
- Unnamed Structure and Union Fields
- Other label format support? HOT 3
- Support identity table usage HOT 2
- Assigning struct word member from another struct word member HOT 1
- Compiler assuming C clear when it isn't?
- Hello World example from documentation doesn't work HOT 1
- IX index is broken in the Z80 assembler.
- Strange invalid 16-bit optimization HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from millfork.