Giter Site home page Giter Site logo

Comments (8)

KiARC avatar KiARC commented on September 24, 2024 1

Ahhhh that makes sense. I might write a really simple Pair implementation that is mutable to make the fix more readable. Thanks for explaining that haha

from sobriety.

KiARC avatar KiARC commented on September 24, 2024 1

Closing now because a solution has been found, thanks so much ^^

from sobriety.

KiARC avatar KiARC commented on September 24, 2024

Honestly what even could cause this? A spontaneous bug affecting all versions that was definitely not there before just isn't possible.

from sobriety.

mvnowak avatar mvnowak commented on September 24, 2024

The problem seems to be in line 129 in Main.kt:

date = Instant.now()

This creates a new Instant with the correct current date. date then points to this new Instant, but the Instant in the HashMap is never updated. This date reference is also used to update the displayed text, which is why everything appears to be working as expected.

In the previous versions this could be fixed, by updating addictions[name] directly, instead of the local variable date. In the current version, where addiction is a HashMap of a String and a Pair, the equivalent would be updating it via

addictions[key].first = Instant.now()

however Pair is immutable, thats why my current workaround is constructing a new Pair using the updated date and the old Buffer like so:

 addictions[key] = Pair(Instant.now(), addictions[key]!!.second)

Im sure there is a cleaner way to do it but this seems to work

from sobriety.

mvnowak avatar mvnowak commented on September 24, 2024

I was confused about this as well at first๐Ÿ˜„ This stackoverflow answer explains it very nice in detail. Just like Java, Kotlin is pass-by-value, e.g. it passes a copy of a reference to a method, so reassigning this copy to a new object does not change the original.

from sobriety.

mvnowak avatar mvnowak commented on September 24, 2024

I might write a really simple Pair implementation that is mutable

Maybe its a better idea, to just create a serializable class "Addiction", with fields name, date, buffer etc. and save that as an ArrayList, then createNewCard could take an Addiction object as input, and simply modify the fields of this object.

This would also make it easier to add new fields later on, (e.g. total money / time saved?), because you wouldnt need to continue stacking Pairs into Pairs

from sobriety.

KiARC avatar KiARC commented on September 24, 2024

Ahaha I feel so stupid now. I wrote it the way I did at first because I thought Kotlin was PBR but thanks for explaining that.

from sobriety.

KiARC avatar KiARC commented on September 24, 2024

And yeah that's a good idea

from sobriety.

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.