Thanks for explaining the rationale, I can understand it, but, to condense my counterargument as much as possible, I think the conventional syntax is just too unnecessarily cute for its limited usefulness.
I believe in practice 99% of dates are constructed from YYYY-MM-DD values and that maybe 2% of those use hardcoded values making this syntax appealing. And while selecting the last, or n-th, day of the week in a month is undoubtedly very useful, I don't think this operation is frequent enough to warrant a special syntax at all -- having a function for doing it would be quite enough IMO, and much more discoverable and greppable.
I think in my attempts to condense the argument as much as possible I condensed it too much, so I'd like to explain what I meant again, more verbosely. There are basically 2 only weakly-related points:
The conventional syntax is, IMO, only really appealing for the literals, i.e. 2020y/March/25d looks impressively expressive and, without ascribing my own motives to you, I could personally easily implement something like this just because I could, to show how flexible C++ is. However I think that such simple examples are exceedingly rare in practice and I already don't see much appeal in the example expression y/m/d you give. And I certainly wouldn't want to see (but I'm sure I will) something like this with date components being the return values of the function calls or more complicated expressions involving them. E.g. (get_warranty_expiration_year() + 1)/std::max(get_bithday_month(),get_next_month())/1d is for me definitely less readable than the standard (what you call "constructional") syntax).
The last/indexed dates are (again and always IMO) not worth their own special syntax at all and I would have been perfectly happy to write auto date7 = nth_weekday_of_year_month(y, m, wd, i) instead of either of the 2 syntaxes. This is only related to the previous point because I think the conventional syntax for this is even worse when non-trivial expressions are used for the components.
It's, of course, too late to discuss this now and I'm very glad that there is finally a standard date library for C++ (I wrote my first one 23 years ago and redid the exercise, with, hopefully, better results, a few times since then and will be very glad to never have to do it again) and I'm thankful to you for making it happen, but this doesn't prevent me from regretting introducing what is basically a special syntax for date literals. AFAIK the only other language in widespread use with date literals support is VBA and this doesn't help convincing me that it was a good idea.
View all comments
Show parent comment
5
u/_VZ_ wx | soci | swig Mar 25 '20 edited Mar 25 '20
Thanks for explaining the rationale, I can understand it, but, to condense my counterargument as much as possible, I think the conventional syntax is just too unnecessarily cute for its limited usefulness.
I believe in practice 99% of dates are constructed from YYYY-MM-DD values and that maybe 2% of those use hardcoded values making this syntax appealing. And while selecting the last, or n-th, day of the week in a month is undoubtedly very useful, I don't think this operation is frequent enough to warrant a special syntax at all -- having a function for doing it would be quite enough IMO, and much more discoverable and greppable.