GithubHelp home page GithubHelp logo

Operations not working about ts-money HOT 3 OPEN

bitbreakr avatar bitbreakr commented on July 28, 2024
Operations not working

from ts-money.

Comments (3)

macor161 avatar macor161 commented on July 28, 2024 1

Hi @bitbreakr, thanks for creating this issue. Functions on Money objects always return a new Money instance. This is why the third line of the example (fiveEur.subtract(new Money(470, Currencies.EUR));) returns 0.30 EUR (5.00 - 4.70) and not 2.80 EUR (7.50 - 4.70). Though I agree it could perhaps be a bit clearer. I will add some clarifications in the example this weekend.

from ts-money.

virtuoushub avatar virtuoushub commented on July 28, 2024 1

@49e94b8f256530dc0d41f740dfe8a4c1, I can not speak to the authors reasoning; however here are some thoughts about immutable and mutable objects, and why a library might use immutable objects (especially one dealing with money where getting the value wrong can be very costly).

From my research, immutable objects

are especially applicable for value types, where objects don't have an identity so they can be easily replaced. And they can make concurrent programming way safer and cleaner (most of the notoriously hard to find concurrency bugs are ultimately caused by mutable state shared between threads).

from ts-money.

49e94b8f256530dc0d41f740dfe8a4c1 avatar 49e94b8f256530dc0d41f740dfe8a4c1 commented on July 28, 2024

@macor161
Any specific reason you went with immutable objects? Is there a disadvantage to allowing the modification of Money objects?

from ts-money.

Related Issues (5)

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.