Code Monkey home page Code Monkey logo

Comments (4)

n1k0m0 avatar n1k0m0 commented on May 25, 2024 1

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.

KarolS avatar KarolS commented on May 25, 2024 1

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 --:

  1. Millfork does not have unary operators other than -. This is by design, and even - was only added later.
  2. ++ and -- introduce parsing ambiguity. --a currently means -(-a) and introducing a new -- operator would break that. Similarly with things like a--b, which is currently parsed as a-(-b)
  3. 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.
  4. Most instances of ++ are found in C-style loops, but Millfork has range-based loops.
  5. Some languages use ++ and -- for other things.

Further reading:

from millfork.

agg23 avatar agg23 commented on May 25, 2024

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.

n1k0m0 avatar n1k0m0 commented on May 25, 2024

Thanks, makes 100% sense to me :-)

from millfork.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.