TimeSpan Improvements in .NET 9 (maybe even a bug fix)

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ธ.ค. 2024

ความคิดเห็น • 25

  • @holger_p
    @holger_p 4 วันที่ผ่านมา +4

    Adding new functions, not changing any existing function, I wouldn't call a breaking change. I thought the solution would go towards using decimal, to add precision, but this way is almost as good.

    • @IAmTimCorey
      @IAmTimCorey  4 วันที่ผ่านมา +2

      It is called a breaking change because it can affect some source code in F#. I believe it also requires your app to be recompiled (which you would do anyway).

    • @holger_p
      @holger_p 4 วันที่ผ่านมา +1

      @@IAmTimCorey OK, I'm only in C#, and since I have to manually edit from (7.5) to (7, 500), it's a manual change from one overload to the other, and recompile doesn't change anything, if I don't edit.
      From what I understand from your video.

    • @IAmTimCorey
      @IAmTimCorey  4 วันที่ผ่านมา

      Correct.

  • @guiorgy
    @guiorgy 4 วันที่ผ่านมา +2

    I had assumed double would've been enough to avoid those precision errors. Guess I was wrong :P

    • @IAmTimCorey
      @IAmTimCorey  4 วันที่ผ่านมา

      Any time you have a number with a decimal point, you will have some level of precision issues. Even the decimal type is only precise up to 28 places. Typically, the 14 places of a double is good enough, but there are edge cases.

  • @Anton-Os
    @Anton-Os 4 วันที่ผ่านมา

    Thanks Tim!

    • @IAmTimCorey
      @IAmTimCorey  4 วันที่ผ่านมา

      You are welcome.

  • @unknown.artist.track3
    @unknown.artist.track3 4 วันที่ผ่านมา

    looks like with this fix I catch the general idea of making alternative methods which have the same functionality as the old ones. maybe you have some other examples of updated implementation?

    • @IAmTimCorey
      @IAmTimCorey  4 วันที่ผ่านมา +1

      There are other fixes like this in .NET 9 even. I'll be covering them later, but you can look at how params works now to see another example like this.

    • @unknown.artist.track3
      @unknown.artist.track3 4 วันที่ผ่านมา

      @@IAmTimCorey got it. thanks.

  • @arvindhmani06
    @arvindhmani06 4 วันที่ผ่านมา

    Pardon me if I missed it, but I didn't quite understand why this precision issue exists with only certain values.

    • @Songfugel
      @Songfugel 4 วันที่ผ่านมา +5

      Because of the way computers store and manipulate numbers as binaries instead of decimals they are shown to us. At certain fractals, the other number base system is more accurate/suitable than the other
      These are some of the things formal software engineering education teaches, but self-taught programmers usually skip/have no clue about. Most common version of this is that you should never evaluate floats or doules for equivalency, only as being inside a specific sigma margin of error from each other (so many game bugs and inconsistent behaviour is due to this beginner mistake)

    • @SanderEvers
      @SanderEvers 4 วันที่ผ่านมา

      It's the difference between double and decimal. Decimal stores the value different from double. However, decimal uses more memory.

    • @IAmTimCorey
      @IAmTimCorey  4 วันที่ผ่านมา +1

      The precision "issue" always exists. It is just that it doesn't really show up at the level we notice it at for most numbers. That's the difference. Most of the time we don't care about numbers that small. But sometimes, the precision issues add up to something visible to us. As others have said, this is why it is important to actually understand the tradeoffs with various numeric types.

  • @paulmartins5521
    @paulmartins5521 4 วันที่ผ่านมา

    Why didn't they use decimal?

    • @IAmTimCorey
      @IAmTimCorey  4 วันที่ผ่านมา +1

      Good question. My guess is because of two reasons. First, decimal is expensive. You don't get that additional precision for free. Also, remember that even with additional precision, you don't get absolute precision. Second, double is the commonly used decimal-type number in C# because it is precise enough for most situations. If you had a double and you tried to pass it in as a decimal, it would not work. You cannot pass a less-precise number into a more-precise type. Therefore, you would need to do conversions on every value being passed in that was not already a decimal. That would add a lot more overhead and expense to the already more expensive process.

  • @krccmsitp2884
    @krccmsitp2884 4 วันที่ผ่านมา

    Interesting and occasionally helpful. I wouldn't, however, consider the previous behavior as a bug, it does as intended.

    • @IAmTimCorey
      @IAmTimCorey  4 วันที่ผ่านมา +3

      It can be considered a bug because it leads to unexpected behavior. If you put in 101.832, you expect 1 minute 41 seconds and 832 milliseconds. That's not what you get. It can also NOT be considered a bug if you aren't expecting exact precision with your conversions. That's why I said "maybe even a bug fix", because it depends on your expectations and your point of view.

    • @krccmsitp2884
      @krccmsitp2884 4 วันที่ผ่านมา

      @IAmTimCorey fair enough

  • @sirus49
    @sirus49 4 วันที่ผ่านมา

    Tims getting busy these days.. not too long ago we had longer videos, more than a few a week and the free content was better but either way cheers

    • @IAmTimCorey
      @IAmTimCorey  2 วันที่ผ่านมา

      For years now, I have been putting out two videos per week. I put out a "coding" video on Mondays at 8am EST and I put out a DevQuestions video on Thursday at 8am EST. That pattern hasn't changed in years. More recently, people have asked me for shorter, 10-minute training videos rather than just long videos. I've accommodated that request and people have said that they appreciate this type of video.
      I have also mixed in the occasional full course on TH-cam. For example, just recently I released a full course on Binary in C# on TH-cam. In that case, because I wanted people to get the content more quickly than once a week, I released three per week. That was a special occasion.
      More recently, I've also started releasing TH-cam shorts in addition to the normal two videos per week. I'm still working on the pattern that makes sense for them.
      By the way, I keep these patterns consistently in almost all cases, including when I am on a vacation or traveling to speak at conferences. For example, I spoke at a conference last week. I was away from the office from Wednesday to Friday, yet a video came out on Thursday and this video came out on the following Monday.
      Bottom line is that I feel like you are unfairly judging what I do based upon a misinterpretation or a misunderstanding.

  • @000Graffy000
    @000Graffy000 4 วันที่ผ่านมา +1

    Can't fight bug? Bandage it!😁

    • @IAmTimCorey
      @IAmTimCorey  4 วันที่ผ่านมา

      I know you are joking, but this is a really good way to protect existing code while allowing good code going forward. Breaking changes are to be avoided whenever possible. This is a great solution.

    • @000Graffy000
      @000Graffy000 4 วันที่ผ่านมา

      @IAmTimCorey I think, underground, it's using usual if-else. 😅