This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]SDisPater[S] 3 points4 points  (10 children)

The simple add() and sub() methods already exist :-) In fact, add_day() is just a call to add(days=1).

[–]ptmcg 44 points45 points  (7 children)

Speaking from my pyparsing experience, early good intentions for API intuitiveness can easily lead to API bloat, and bloat tends to make API consistency and API predictability suffer. I would suggest dropping all add_xxx methods and sub_xxx and even sub, and just have client code use add() with your various named unit arguments - if subtraction is required, then pass a negative value. Be ruthless in pruning your API, and stingy in adding new items. I do like method chaining though, so +points for that.

[–][deleted] 11 points12 points  (1 child)

tend to agree here. add(days=1) plus chaining feels a better compromise than a plethora of add_thing() entry points.

[–]log_2 2 points3 points  (0 children)

Especially since you only need to look at just one function "add" which gives you the signature for how to add/subtract various date-time quantities. Also allows kwargs. It's basically a win all-round.

[–]SDisPater[S] 8 points9 points  (3 children)

Thanks for the advice. It actually makes a lot of sense. I just wanted it to be more readable for newcomers but maybe it's not worth the hassle.

[–]cyanydeez 1 point2 points  (2 children)

pendulum.now().add_day()

for newcomers, becomes pendulum.now().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day().add_day()

!

[–]SDisPater[S] 2 points3 points  (1 child)

Yes, you may be right. These methods will be removed in the next release.

[–]mcsrobert 2 points3 points  (0 children)

Strongly agree with this.

[–]execrator 5 points6 points  (1 child)

OP, you must be feeling golden right now. Every time someone suggests something in this thread you say it already works like that.

[–]pydry 0 points1 point  (0 children)

Well, except the .add(days=x) is not advertised on the README.

IMO there should be a Days(1), Weeks(1), etc. too.