kvesteri / intervals

Python tools for handling intervals (ranges of comparable objects).
BSD 3-Clause "New" or "Revised" License
107 stars 17 forks source link

Support for easier initialization of intervals #7

Closed adarshk7 closed 8 years ago

adarshk7 commented 10 years ago

For example,

IntInterval(3, 5) == IntInterval((3, 5)) and, IntInterval[3, 5] == IntInterval([3, 5])

homeworkprod commented 10 years ago

I, personally, don't like the (nicely put) "repurposing" of tuple and list literals for the definition of open or closed intervals. While this is the usual mathematical syntax, it means something different in Python. This is not operator overloading.

Especially the fact that the creation of an open/closed or closed/open interval requires a different syntax (i.e. a string including parentheses or square brackets) just feels wrong and error-prone to me.

I'd like to compare this to Google Guava's Range class (API docs) which uses clearly named, uniform, auto-completable factory methods ("open", "closed", "openClosed" etc.) for that purpose.

In summary, I propose to go the opposite direction and make the API more explicit, self-explanatory and, thus, Pythonic.

kvesteri commented 8 years ago

Guava-like factory methods have been added, closing this for now.

homeworkprod commented 8 years ago

Guava-like factory methods have been added […]

@kvesteri, can you please point me to the commit that added this?

kvesteri commented 8 years ago

https://github.com/kvesteri/intervals/commit/6cf3218ea73ba46ad69fd9cab85d9642e07bad32

homeworkprod commented 8 years ago

Ah, thanks!