Good Design is Imperfect Design, Part 1: Honest Names
domainlanguage.com
domainlanguage.com
It's the `month` unit that is misleading, since `1 month` looks like a constant value but really isn't, as the behaviour depends on the other operand, breaking associativity – or any expectation on how addition between two constants work really.
It would be less confusing if the API removed `month` as a period, and as a programmer you would have to write:
periodLength = t.advanceMonths(1)
t' = t.plus(periodLength days)
This way you can only `plus` in constant units (days), and `advanceMonths` is free to follow any heuristic and return anything depending on the value of `t` without breaking the expectations of `plus`, or you can have any number of functions with different definitions for "advance N months".I've recommended that clients specify time periods in days or weeks and avoid "months" entirely (ie, 90 days or 26 weeks, but not 3 months) or to specify an end date explicitly.
An absolute delta type is good to have, but it's also useful to have a "relative delta" type (how my language calls it). Each has their use cases.
† ±1–2h on DST enter/exits
‡ ±1s during leap seconds
Ever wondered why the variable-length month is second in the year, instead of a last? English names of months offer a hint: "September", "October", "November", "December" - sound similar to "hept-", "oct-", "non-", "dec-", i.e. 7th, 8th, 9th and 10th. So as it turns out, February used to come last, as reason would demand, but then the calendar got rotated right by two months.
If we imagine the calendar as it was, with February being the last, then at least the mapping between "day of year" and "month, day of that month" would be a function of just "day of year", instead of being a function of both "day of year" and "what year is it".
I don't like if `advanceMonths` returns an interval though, since this indicate that the interval is a meaningful unit separately from the initial date. It should return the new date, not an interval.
Absolutely anyone who works with dates needs to understand this. There's no point in calling the method `plusWeird`, that's redundant.
The good news is that most people actually have an intuitive understanding of dates (because we have spent our lifetimes looking at calendars) and when you are doing exotic date math ("move this to the same date next month") the default behavior of `plus` is what you want.
I spent a lot of time working with Joda Time (and now java.time). I use date math functions on the regular, professionally. I found this API intuitive and ergonomic from the get-go, and well matched to the problem domain. What I see in this thread is a bunch of people with a relatively poor grasp of the problem domain trying to rethink the API.
One way to look at the issue is that the confusion stems from giving the same name to operators of different types, namely the "Instant plus Period" operator and the "Period plus Period" operator.
Period could be implemented as a vector with independent components for days, months, and so on. (I don't know if that's how JodaTime does it, but that's what I would do if I wanted it to have a "plus" operation.) Then it could have a well-defined operator appropriately named "plus", which is both commutative and associative as one would expect.
"Instant plus Period", however, is asymmetric, and cannot satisfy the identities we associate with "plus". So let's give it a name that is also asymmetric. How about "advanceBy"?
2021-01-30.advanceBy(1 month) = 2021-02-28
2021-01-30.advanceBy(1 month).advanceBy(1 month) = 2021-03-28
2021-01-30.advanceBy(1 month plus 1 month) = 2021-03-30
2021-01-30.advanceBy(2 months) = 2021-03-30
That seems much less mysterious to me. Sure, a casual reader wouldn't be immediately confident about what advanceBy returns in all cases, but giving it a name that conveys its asymmetry helps a lot.
I actually separated it into a separate part because it undermines my primary point. Sure, we all love it when we have a better decomposition, better names, and everything falls into place. But it doesn't always. Not in the time we have. So then we need ways to deal with the flaws. I decided that if I had ended with this it would have communicated: Aw, just keep trying and you'll get something nice! That can be very risky.
None of the proposed names in the post actually clarify anything - they merely make the behavior seem more confusing.
[0] https://github.com/DennisMitchell/jellylanguage/wiki/Quicks
Changing PI to PI_ISH because numbers in a language is limited does make code more readable.
Almost everything in a computer is an imperfect model.
i++
is not improved as
incrementUnlessItOverflows(i)
You are not going to change how increment works so avoid making it awkward.
You cant change the fact that number of days in a month varies.
I find this as annoying as "mistakes programmers make about time" articles. The reality is programmers understand that all time in all computers is just a model to be played with.
Recently I saw the people are fretting because there may _have to be_ a negative leap second. Leap seconds are a man-made concept. You don't _have to_ have a negative leap second, you just have to accept the earth's spin is not constant, utc is a model, the model is not worse if its out by >1, it was never perfect, it exists to be convenient. utc ignores being out by >1 millisecond, why is there a problem if the denomination is a 1000ms?
The world keeps turning and the model is simpler if _all_ leap seconds were ignored, it will take a while until midday over Greenwich is affected and it will not matter when it is. It was an arbitry location in the first place.
It seems to me JodaTime is correct, if you want to add 30 days plus(30 days), if you want to accept that the month model is imperfect plus(1 month) and see what you get.
++ is concise and precise, the domain is a programming language.
Not all months last the same number of days, and while we are at it not all days have 24 hours!
I'd rather move the explicit (and complicated) choice of what kind of month are you talking about (and thus also the relevant discussion about naming) into the operator that constructs a time interval.
- Same calendar day plus 3 calendar month, round down if < end of month
- Just plus 3 calendar month plus remaining days if > end of month
- 90 days from now
Looking forward to read about your explorations on that front.
The lack of associativity is still a problem. If 2021-02-28 + 1 month = 2021-03-28,then (2021-02-28 + 1 month) + 1 month = 2021-03-28 + 1 month = 2021-04-28. While if I ask what is 2021-02-28 + 2 months (given 2021-02-28 + 1 month = 2021-03-31), most people would say 2021-04-30.
While I am not entirely sold on using awkward/"honest" names by default, the author does raise a good point: sometimes concepts are inherently messy or full of important edge cases, and we shouldn't just brush that aside.
I recently ran into a similar problem. I am implementing a distributed lock (https://www.joyfulbikeshedding.com/blog/2021-05-19-robust-di...) -- like a mutex, but works across processes and machines. I try to mimic the language's standard Mutex API as much as possible.
A normal Mutex has a query method named "owned?" to check whether the calling thread owns the mutex. When I tried implementing this method for my distributed lock, it raised a question: owned according to who? Owned according to the local state that represents the lock, or according to the state that lives in the server? Because they can differ (e.g. due to bugs in other clients or because an admin manually messed with the state). So I opted for "honest names" here too and implemented two methods: "owned_according_to_local_state?" and "owned_according_to_server_state?"
If it is important in the domain you are working in, take extra care to understand the maths that you are built on. And don't be surprised to find special cases everywhere.
Programmers exist in a world where things such as leap seconds matter. Normally if you have a timestamp that is just before a leap second, then add exactly a day's worth of seconds, you'd slide back a little in time. This might matter in another context, such as defining the limits of neighboring ranges properly. Also, who's to say the underlying precision is a second?
The intent of the library in question is to behave the way most people would. With imperfect buckets and idealized answers; yet also precision where someone makes the attempt to be specific.
None of the examples in the article use a more vague syntax, such as "0 days before the end of the month". They start with what a human might, a rounded but full date; then apply an interval. So a more clear contrived example might be.
Jan 31 .plus(1 months) => Feb 28
Jan 31 .plus(2 months) => Mar 31
Jan 31 .plus(3 months) => Apr 30
Jan 31 .plus(4 months) => May 31
Jan 1 .plus(1 months) => Feb 1
Jan 1 .plus(2 months) => Mar 1
Jan 1 .plus(3 months) => Apr 1
Jan 1 .plus(4 months) => May 1
Note how in the second half there are still variably sized months, but the result is what a human would want.So I’ll repeat:
What’s Feb 28th + 1 month?
Does the human expect the last day of March? Or the 28th day of March?
The API doesn’t make that clear - I think you could reasonably argue for either.
I think plus() is a name that is good enough. I can't think of a better name that will help the user understand what will happen in the 2/28 + 1 month case. That's asking too much of a method name. That's what docs are for.
When you increment the month, the result would be 2021-03-28.
The only time you'd modify the day, is if the day became invalid due to an overflow, during that increment. If, when, you overflow the days you'd set the value of days to the maximum in that month.
If I tell someone, I'll get to that in a month, they expect by this day in the next month, the next calendar page, not 30/31 days.
""" None of the examples in the article use a more vague syntax, such as "0 days before the end of the month". """
As another reply points out, it's incrementing the Month set of buckets. I'll also extend with other results I expect:
2020-12-31 .plus(1 months) => 2021-01-31
2020-12-31 .plus(2 months) => 2021-02-28
2020-12-31 .plus(3 months) => 2021-03-31
2020-12-31 .plus(4 months) => 2021-04-30
A normal human has several options, and truncating to stay within the month makes the most sense to the most people most of the time. It's perfectly reasonable to take that step when resolving the indicated date to a representable value.I'll go further: JodaTime probably isn't focused on Precision Date Calculations; it behaves very much the way I expect someone working with forms and fields, general CRUD enterprisy software stuff, would want auto-filled dates to work.
""" None of the examples in the article use a more vague syntax, such as "0 days before the end of the month". """
---
They asked:
""" What’s Feb 28th + 1 month?
Does the human expect the last day of March? Or the 28th day of March? """
---
It's implicit, the human only expects the month to change, because the input isn't a descriptive phrase "the end of the month" adjusted or not, it's a literal date. That's why my other test cases show the same behavior for the end of the month.
At any rate, these problems have been solved in finance, with proper date and schedule libraries.
.plus .plus .plus isn't correct because "x months" doesn't have a fixed size. You are NOT saying Base .plus(30 days), NOR are you saying Base .plus(4 weeks) ((which BTW, I'd expect to stay on the same weekday)). You're incrementing by an unstable value.
I don’t think so, no—more likely, it should be Pattern(Month)… like how would you express “second Tuesday” as a series of additions?
6÷2(1+2) = ?
We could argue about what the _right_ answer is to that equation, but I call it a trap because it's intentionally confusing and devoid of any context (or the ability to ask a follow up question). There isn't really a situation where you would see that equation and not know the intended way to interpret it... just like your question.
There are a couple of ways that context _could_ be provided though:
I'm writing an automated task that should run once per month, I don't necessarily care what day of the month it runs though since it just cleans up some temp files. If today happens to be Feb 28th, and I say run today, then every month after, I would expect it to run Feb 28th, March 28th, April 28th...
I'm writing an 'end of month' task that needs to run at the end of every month for some bookkeeping reason. If today happens to be Feb 28th, and I say run today, then every month after, I would expect it to run Feb 28th, March 31th, April 30th...
In both of these situations I would program accordingly. Computers don't understand context, that's the job of the human programming it.
The one thing nobody wants, is to add a month and land in the month one over.
So even if the semantic differs between libraries for adding a month, it actually doesn't mather that much. Because for all the other cases one could imagine, most people will add days or weeks, if staying on the same day matters.
It could mean 30 days in the future. Or the same day of the week 4 weeks in the future (i.e., 28 days in the future). Or the day of the same cardinality in next month. Or any date in the next month. And those are all equally correct.
It's simply not a precise measure of time when spoken from one human to another human in plain language. Indeed, I think we inherently understand it to be an imprecise measure of time just as much as "tomorrow" doesn't mean "exactly 86,400 seconds from this moment". "Next week" doesn't necessarily mean "7 days from now", either. That's why computers don't typically use imprecise terms. They provide feedback and say "this will occur at this time and date".
You always have to check what the operators actually do and what the requirements actually mean when you're working with times and dates.
"2021-01-31".plus(unit="Month", size=1) => "2021-02-31"
But nobody really wants that, because it's not a valid date. So implicitly the library is deciding to return a valid date.
A library could be written to just provide invalid dates, and let the end user handle any errors. That library could also include an explicit validation method that takes a date and returns a valid one.
"2021-02-31".coerceToValid() => "2021-02-28" // Overflow == Max
"2021-02-31".coerceToValid(asDays=True) => "2021-03-03" // Overflow Carries (to the right)
In fact the library, that provides an ignorant response and no contract on validity would hold to the associative property, it just wouldn't be as ergonomic.
But if the reason people are wanting to use the library, is they want something to handle the complexity for them, coercing the data is good for simplication.
There is actually another option, that provides idempotent/associative consistency and implicit coercion to valid values.
This option, which discards some use cases (days beyond 28, when manipulating months), you coerce all values 29..31 to 28. This isn't even as technically correct, as the original option, but it removes the inconsistency and holds to the simplification contract to users.
No, it doesn't.
You walk in to the doctor's office on February 28. At the desk, you see another patient about to leave. They turn to the desk attendant and say, "I'll see you in a month for my follow-up."
What date is the other patient's next appointment? What if the date you walked in had been January 31?
Also, for what it's worth, in C#:
DateTime x = new DateTime(2021, 1, 31);
x.AddMonths(1); // Feb 28
x.AddMonths(2); // March 31
x.AddMonths(1).AddMonths(1); // March 28A month is a discrete unit of measure. It is not decomposable into any number of days.
When you increment a month, you get YYYY - (MM+1). Any higher significance is maintained, but irrelevant to the operation. (This applies to the hypothetical statement in the doctor's office, the specific day is indeterminant, but can be assumed the same as current day next month.)
The fact that not all possible days exist is orthogonal to the singular meaning of the operation. It's obviously not greatly valuable to an end-user, but the method of addressing the ambiguity involves a second operation that ensures validity.
End-users want an method that does both the addition and coercion, but you can create consistency if you follow the simple path I laid out in GP.
I'll use your syntax but with the strictly correct definition of the operation.
Datetime x = new DateTime(2021, 1, 31);
x.AddMonths(1); // DateTime(2021, 2, 31)
x.AddMonths(2); // DateTime(2021, 3, 31)
x.AddMonths(1).AddMonths(1); //DateTime(2021, 3, 31)
// Ensure Valid, using a coerce to clamp overflows
DateTime(2021, 2, 31).EnsureValid(); // Feb 28
DateTime(2021, 3, 31).EnsureValid(); // Mar 31
DateTime(2021, 4, 31).EnsureValid(); // Apr 30Thank you. That's exactly it. Crazy to see how many developers don't seem to grasp it here. I guess it's the "trap" that we are used to datetimes before the time when we became developers and we have to actually relearn this stuff to get the idea.
(It is almost like a quantum state. It can be between 28 and 31 days, depending on what it's being applied to. But as soon as it's applied to an absolute date the ambiguity disappears).
If you expand out the short hand 2000-02-02 + (1 month forward from February) + (1 month forward from March), then we can see associativing is nonsensical.
In contrast if on January 31st I told them “call me two months from today” I’d expect them to call on March 31st.
It’s very intuitive.
Also, FYI, this is not how GNU date works:
$ date -d "Jan 28 next month"
Sun Feb 28 00:00:00 CST 2021
$ date -d "Jan 29 next month"
Mon Mar 1 00:00:00 CST 2021
I could see confusion from this, depending on what libraries you are used to. $ date -d "jan 31 next month"
Wed Mar 3 00:00:00 PST 2021
$ date -d "jan 30 next month"
Tue Mar 2 00:00:00 PST 2021
$ date -d "jan 1 next month"
Mon Feb 1 00:00:00 PST 2021
$ date -d "feb 28 next month"
Sun Mar 28 00:00:00 PDT 2021
Edit: This was on my unconscious mind for a bit and I came up with an additional test case to confirm a suspicion I realized. $ date -d "2016-1-31 next month"
Wed Mar 2 00:00:00 PST 2016
date -d "2016-2-1 next month"
Tue Mar 1 00:00:00 PST 2016
date -d "2016-2-1 next year"
Wed Feb 1 00:00:00 PST 2017
$ date -d "2016-3-1 next year"
Wed Mar 1 00:00:00 PST 2017
GNU date will add the duration of the CURRENT interval (ignoring already occurred deviations, like leap years) relative to the specified base date.The oddity in behavior I observed above is adding the length of the month of Jan to dates in Jan. I suspect only a programmer would find that inference remotely correct.
Jan + 1 month = February, sure.
But, as soon as you add the day, it falls apart for me.
For most dates, if I add a month, in my mental model, the answer is the next month with the same date.
Jan 15 + 1 month = Feb 15, etc
But, at the edges, it gets odd quickly.
Jan 31 + 1 month = ??? Not sure, maybe Feb 28, maybe Feb 29, maybe Mar 2, maybe Mar 3. Depends on the year and who's asking me to solve the problem.
I would expect any reasonable software to fail gracefully when asked to solve this problem. And by fail gracefully, I mean ask for clarification. Or prevent me from asking silly questions in the first place.
Consider the API:
data Date = Date { getYear :: Int, getMonth :: Int, getDay :: Int }
deriving (Eq, Ord, Show)
addDays :: Date -> Int -> Date
addMonthsRounded :: Date -> Int -> Date
Someone who does d `addMonthsRounded` 3
immediately has a contextual clue that there might be something fishy going on, and has a string they can google to get to the docs to find out that this "Rounded" business is all about "hey, the code let y = (x `addMonthsRounded` 1) `addMonthsRounded` (-1)
in y == x
might sometimes return False because it truncates if your day doesn't fit in the given month."Because humans intentionally reduce the precision of their computations to make them easier.
Today = 2021-08-04
Next year = 2022
The exact month, day, hour are all unknown.
Next month = 2021-09
The exact day and hour are unknown.
Tomorrow = 2021-08-05
The hours and minutes are unknown.
If humans used the same level of precision as computers, they'd run into the same problems. Probable date of birth calculation is an example.The correct solution in my opinion would be to have distinct types for this sort of thing to help clear up the ambiguity. Date and time are really tricky concepts to model though and it is a difficult balance between honesty/precision and intuitiveness for such APIs. One such clunkiness I've seen with KeepassXC is that it stores password expirations exclusively as timestamps. This is actually not correct for the common use case of passwords expiring on a particular day (since you don't know the time) because what if you are in a different timezone? This I think shows that you can't just convert dates into datetimes without problems.
julia> (1e16 + 1) + 1 1.0e16
julia> 1e16 + (1 + 1) 1.0000000000000002e16
I think the fundamental issue with dates, however, is deeper than "addition is non-associative". It is that "1 month" is a context-sensitive duration (so is a "1 day", due to leap seconds).
I am curious about using intervals. If "{Year} January (no day)" had a representation as "Jan. 1 - Jan. 31", then "Jan. 1 -- Jan. 31" + "1 month" = "{Year} Feb. 1 -- Feb. 28" (or 29 if the {Year} is a leap year".
Seems to me best practice of renewing accounts is to always apply padding (TODO: renew Foo today because it expires in roughly n days); if you make as a minimum n >= 2 (or how about >=3 as a safety factor) then you don't have to consider how the account provider administers their cut-off (expires at 00:00 vs 23:59, is timezone a factor?, etc).
With this approach the difference between 'instantaneous time' and 'calendar time' are, for practical purposes, a moot point.
So the date I enter into the KeepassXC field has the padding included. The expiry date as described by the provider I can put in the note field for additional reference.
Around 2.5 years ago I sent the following feedback to the Wolfram|Alpha Feedback Team, never heard back from them.
Message: When I compute
"2019-01-31 to 2016-04-04" I get "2 years 9 months 26 days"
and when I compute the reversed input
"2016-04-04 to 2019-01-31" I get "2 years 9 months 27 days"
But when I compute
"2019-01-31 to 2015-10-21" I get "3 years 3 months 10 days"
and when I compute the reversed input
"2015-10-21 to 2019-01-31" I get "3 years 3 months 10 days"
Shouldn't the very first one ( "2019-01-31 to 2016-04-04" ) also return "2 years 9 months 27 days"? -- leap year 2012:
2019-01-31 to 2012-01-30 --> 7 years 1 day
2012-01-30 to 2019-01-31 --> 7 years 1 day
2019-01-31 to 2012-02-29 --> 6 years 11 months <---- Weird stuff
2012-02-29 to 2019-01-31 --> 6 years 11 months 3 days <---- Weird stuff
2019-01-31 to 2012-02-30 --> 6 years 10 months 30 days (2012-02-30 does not exist)
2012-02-30 to 2019-01-31 --> 6 years 10 months 30 days (2012-02-30 does not exist)
2019-01-31 to 2012-03-30 --> 6 years 10 months 1 day
2012-03-30 to 2019-01-31 --> 6 years 10 months 1 day
2019-01-31 to 2012-04-30 --> 6 years 9 months <---- April (any day in April)
2012-04-30 to 2019-01-31 --> 6 years 9 months 1 day
2019-01-31 to 2012-05-01 --> 6 years 8 months 30 days
2012-05-01 to 2019-01-31 --> 6 years 8 months 30 days
-- non-leap year 2013:
2019-01-31 to 2013-04-30 --> 5 years 9 months <---- April (any day in April)
2013-04-30 to 2019-01-31 --> 5 years 9 months 1 day
I stumbled upon it while testing some JavaScript time and date frameworks and wanted to use Wolfram|Alpha because I was somewhat confused with the correct interval between two dates.The result, which reminds me of one of the other reasons I avoid python for trivial projects, is the duration / interval answer of days=2528.
Part of the bug is surely in Wolfram|Alpha returning the interval broken out in human durations; but importantly those durations __don't use fixed time values__. The precise length of a //year// and of a //month// are variable.
I still suspect there's double or single counting of leap-days in those durations as the reverse ones clash with converting a duration back to a whole number.
Certain problem domains require baseline familiarity with the subject. Far more people can recite the old "30 days has September, April, June, and November" rhyme than can explain what the words commutative and associative mean. Date math may annoy pure mathematicians but normal humans are used to working with calendars.
In the problem domain of dates, 'plus' is analogous to (but not exactly) its mathematical counterpart, and Joda's month math is almost always exactly what you want. Furthermore, plusIshRoundCeiling doesn't really explain anything; ceiling of what? The OP suggests that the cognitive dissonance is beneficial to the user. In which case it might as well be plusAsterisk or plusDontForgetToReadTheDocumentation.
The problem with plusGoReadTheDocs et al is that all problem domains have little edge cases like this. Excepting pure math, every single plus method is going to have notes. It'll be worse than those useless Prop 65 warnings in California.
Joda did this one right. Date math is simply not associative or commutative. Thankfully, most people are familiar with calendars and have some intuitive sense of this already. Littering the API with special hints doesn't help.
Although I think your comment here rather underestimates mathematicians :) Regular people are the ones who are only used to thinking in real numbers or integers. While some may be familiar in a practical way with how dates and times work, they would probably struggle to rigorously define the algebra of time math where associativity and commutativity don't hold. Mathematicians will be familiar with areas like abstract algebra and group theory and very capable of understanding the concept that date math is not normal integer arithmetic.
Either way though, I agree the plus operator works great here given the inherent weirdness of how we have structured human time, and everything the author is proposing is worse. Joda handles the trickiness of dealing with time far better and in a much less error-prone way than any other library I've seen.
One thing though: I think I was clear that I like Joda Time. It does handle these things better than most libraries. That is what makes it interesting to discuss. I could write a fun article picking apart some awful library, such as the old Java default library, but what would be the point.
It comes close to the “system should be a complex as they need to” (some quote I am completely butchering) idea. There’s a point where trying to hide messiness isn’t helpful.
As a side point to the “plus” argument, I think having a name that covers 99% of the use cases but will fail unpredictively on edge cases should be fine for something that is central to the library.
People for whom exact behavior matters will have looked at the doc or tried these use cases by themselves, or there will be enough blog posts like this one to motivate them into checking what their lib does beforehand. Well, anyone working with times and dates will have learned to not trust clean abstractions at this point.
For people who are just writing convenience applications and want a lib that make them feel they can use it without hassle, “plus” is a very good, memorable and easy to use name.
(some date + 1 month) + 1 month ≠ some date + 2 months
has always been true for floating numbers.
This is exactly why you never trust
fast matrix multiplications---they rely on cancelations
of the form (a + b) - b = a + (b - b) = a.I would argue that 1 month is just having too few significant digits. You can even implement it as returning 30 with probability 60% and returning 31 with probability 40%. Then on average you would have
1 year ≈ sum([1 month] * 12)This is the snappily named intnx function. I guess that’s an honest name in the sense that it is very suggestive of needing to read the documentation before using it.
I'm sure there could have been a lot better options to drive that point home, but the author picked one that I'm sure everyone has an opinion about. That seems like an effective way to get people talking about it, but it could be divisive in bad ways.
I'm a little put off by the other saying "a clean name shuts down our thinking", so maybe I'm just responding in disgust.
I do have thoughts on better names. I'll write a follow up about that. But I didn't want to include it in this article because my most important point was that we need ways to curb our perfectionist tendencies, and not by hiding the rough spots. And if I had ended on that up note, it would have been the usual cheesy ending: Look! I'm so good that I always end up with a beautiful design. Which, as you say, was the opposite of the takeaway I wanted.
I've seen people argue that one side should be called "sieved" while others say it should be named "selected"... to add to this , let's add even more complexity, since "selected" implies agency.. while filter performs a passive _selection_, in which case it should not be considered a selection at all.
It seems easy, but in reality some concepts (If not all) are inherently messy, specially on the English language since it seems the most abstract of all languages.
But general point holds: honesty in API is important
``` .plus(1 month) ```
The unknown behavior of 1-30 + 1 month is a red flag that maybe you shouldn't be using "month" as a unit of time because it isn't.
Months suck. Bill for services every 10 days or every 25 days or every 50 days instead of every month.
The best solution for that may be something like establishing it as a frequency rather than accumulative addition. But that won't work in every situation. Dates are complex and require lots of thinking to do correctly in some circumstances.
I don't want to pay rent that way. It's a good way to get scammed because they're charging you a higher per-day rate in February than January.
I'd much rather pay rent per day, if possible. If Amazon can take over my property manager I'm sure it'll be possible to bill it with the same flawless consistency of AWS billing, and have a concept of discounted "reversed instances" and "spot instances" for real estate.
“They are scamming you because you have to pay an extra months rent every year”
Rent is listed per week prices but you'll see some landlords calculate it out by the day rate if you want to pay monthly. Others use the 52 week rate divided by 12.
edit: Also this may not be typical in every lease, but all of my leases have established the rate as both a yearly and monthly amount. I'm sure my landlord wouldn't complain if I paid all 12 months up front. That's the only truly "fair" way.
Are you serious? They're not scamming you. They're giving you a discount 11 months out of the year. Feb is the only month They're charging you full rate for!
Isn't that just prioritizing one's laziness as a developer over what makes sense to the user? My guess is most users would rather see the bill come out on the same day every month.
As a user, I would not. I hate months. They're inconsistent. I hate them.
I can set up an ap, and it is done. No tweaking needed.
Programming is the art of turning messy, real world, human problems into tools that work in the best way possible.
If you abdicate that responsibility, quite frankly, what use are you?
To be clear it's still a tradeoff. But I think JodaTime did the right call by settling for the simpler name in this situation.
Maybe move() might work better here or moveToCalendarNearest() or something to flag up that in certain cases you need to be extra careful as mentioned in the article.
It is really hard to get this right and personally I would be flagging it up in javadocs.
How do you expect to address it when there isn't a single obvious "right" that everyone will have the same intuition on?
Long term, you might deprecate it and solve the problem with more intuitive abstraction.
But remember that this functionality exist ms is a library for operating on dates. It is clear to the user that values like "2 days" or "1 month" are intermediate values that cannot or should not be used as output. They need to be applied to an absolute date to become resolved and be useful.
The context, and real world experience with dates, makes this distinction obvious.
Side note: I created a similar library in the past. I struggled more with deciding if the clipping behaviour was even desirable than worrying about the naming, but that was merely due to the API I used. My function signature was `addMonths(v, 2)`, which eliminated ambiguity.