39

++years_old;
--days_to_live;

Comments
  • 7
    Happy day of birth 🎉
  • 9
    So a mistake was made today a few years ago, eh?

    I'm just kidding lol

    Happy birthday 🤜🏻🤛🏻
  • 5
    You mean, years_to_live--;
    Because days to live is in days, and -- only subtracts 1.

    Happy birthday, in any case.
  • 2
    @RememberMe if we're going to be "that guy", --days_to_live; wouldn't work anyway unless you know the exact date you are going to die. Age is known, days to live is *usually* unknown (even if we're talking about years).

    Since we aren't computers we understand anyway, though.

    Happy Birthday, @Toshib-htr.
  • 2
    Level++
  • 3
    ++ for using pre-increment instead of post-increment. 😏
  • 2
    @duckWit days_to_live could be write-only, as in allow modification but not reading the actual value, e.g. only implementing operator--()
  • 2
    A little bit late, but happy birthday for both of us! :P
  • 3
    @fdgram I love this technical and nerdy conversation.

    Allowing modification of what number, though? Even write-only, that write accessor is modifying a value, which is unknown. It's kind of like an attempt at decrementing a null value.
  • 2
    Happy birthday! :D
  • 2
    @duckWit the "write accessor" can be part of the class hence having private access to its member variables, meaning the public interface is only able to mutate the value indirectly. You can also imagine some hardware that decreases a number upon receiving a signal, but with no way to read the number back out.
    Both of these would have to be initially seeded with values of course.
  • 2
    @duckWit as a more practical example you can imagine sending me money, in an envelope, by wire transfer, or otherwise. By doing this you're mutating my amount_of_money without being able to read its actual value.
  • 1
    @fdgram I completely understand a write-only property or method that mutates a private variable. No need to explain that.

    What is the initial value of that private member variable? If you are decrementing time to live, it means that it is decrementing from a variable with a set value.

    Usually, humans don't know how much time they have left, which is why I made the comparison to the null value.

    My code decrements my time to live. Great. What was the old value? What's the new value? I told it to decrement by 1 (the --), but from what to what?

    Do you know when you're going to die?
  • 3
    @duckWit "What was the old value? What's the new value? I told it to decrement by 1 (the --), but from what to what?"

    This makes it obvious that you don't actually understand how a write-only property works.

    As I said, the variable would have to be seeded with a value when the object is created or before you try modifying it. There's no need for me to know the value when calling operator-- since it's all contained within the object.
  • 0
    @fdgram lol omg

    Class A calls ClassB's DecrementDaysToLive();

    Let's look at the implementation of ClassB (this is in C# syntax)

    public ClassB
    {
    private int daysToLive;
    public ClassB()
    {
    daysToLive = ??; // 0? 100? 10000? 50000?
    }

    public void DecrementDaysToLive()
    {
    --daysToLive;
    }
    }

    ....so.

    What value does ClassB initialize the variable daysToLive to? Does it know when you are going to die? Programs are literal. My point above is that in order for a program like that to work, it would LITERALLY have to know when you are going to die, otherwise the value of daysToLive only shows how many times you called it, not how many days left you have to live.
  • 1
    @duckWit knowing the actual value is out of scope of the "how to mutate a variable without knowing its value" topic. The value could be set by your favourite God; we don't know how the object was created. We just invoke operator-- on it.
  • 0
    @fdgram and there we have it. It's not a literal program (my point the entire time). I was responding, originally, to @RememberMe being "that guy" on somebody's birthday announcement saying that his code doesn't really work/isn't consistent.

    To that, I said, well, if we're going to be "that guy", then we might as well say that the code wouldn't work because quite literally the code would have to know when you are going to die, regardless of whether or not it's decrementing days or years.

    Enter you, and your educational explanations on encapsulation.
  • 1
    Anyway, Happy Birthday again, @Toshib-htr! I hope this has been at least somewhat entertaining for you, haha.
  • 1
    If anybody reading this thread is a writer, I would LOVE to see this conversation show up in a TV Show like Silicon Valley or something. Somebody says "Hey it's my birthday!" and it spawns off an argument between two software devs about how that birthday code would be non-functional.
  • 2
    Simple answer: TTL is a private property of the object, with no getter function. Any attempts to retrieve it either return NULL or call an estimate_ttl() method that checks all factors known to affect TTL except the TTL itself and provides a (likely inaccurate) guess.
  • 1
    Wow, that went off on a tangent. Thanks for the entertaining/educational thread!
  • 1
    @duckWit our code doesn't have to know what the actual value is. That's the beauty of programming. A proprietary library can provide the value; it doesn't matter at all where the value is coming from when we only care about mutating it. I don't grasp what your problem with this abstraction is.
  • 2
    @fdgram I don't have a problem with the abstraction.

    Please read the following to understand my point and not to just craft a reply:

    I was originally responding to someone above who took figurative birthday code and turned it literal by making corrections to it. I was pointing out that if we're going to make corrections to figurative birthday code then the whole thing falls apart anyway because the literal, abstracted implementation would have to know when you die to support --daysToLive.

    If it's literal, then something has to implement the code that handles the receiving end of the call. Someone has to have written it. What did they initialize that value to? It's write only--got it--but the literal implementation acts on a known value of something that can't be known.

    We can keep it figurative like you did and say "God wrote it" and in that case the answer is "God knows how much time you have left", sure.

    TL;DR I'm speaking literally, you're speaking figuratively.

    Conclusion: let's not get nitpicky about figurative code. Let's keep it figurative.

    And Happy Birthdays all around, we've all earned it by now!
  • 1
    Actually your time to live is not correlated with your age but instead there is an odd correlation with the number od breaths you take. Apparently we all have a maximum amount of breaths before we die of old age.
  • 0
    @Santaclauze

    /* Assumes average of 672,768,000 breaths by age 80 */

    function every_breath_you_take() {

    static $breath_count = rand(0, 900000000);

    return $breath_count--;

    }
  • 2
    @Santaclauze maximum amount of breaths?

    So people who exercise regularly with elevated heart rates (and thus, elevated breathing rates) will deplete their breath allotment before someone who spends their whole life in a sedentary state?
  • 2
    @Santaclauze I must have been in a bad mood earlier because reading your maximum-amout-of-breaths comment now is hilarious. I completely missed the joke, haha.
  • 1
    @duckWit well. Its actually been obsrrved scientifically that sporty people may use more breaths while exercising, their body uses enery more efficiently and they breath less frequently at rest than unhealthy people.

    All good for you rage moment ;)
Add Comment