Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construction patterns #1

Open
erikc5000 opened this issue Oct 24, 2019 · 0 comments
Open

Construction patterns #1

erikc5000 opened this issue Oct 24, 2019 · 0 comments
Labels
design Design issue/question

Comments

@erikc5000
Copy link
Owner

erikc5000 commented Oct 24, 2019

The manner in which objects are constructed isn't entirely consistent at the moment. The most "Kotlin" approach is a bit of a question mark though and certainly worthy of discussion.

We have classes like Duration and Period, which do construction like so:

val duration = durationOf(5.seconds, 5.nanoseconds)
val period = periodOf(2.years, 3.days)

This reads nicely and feels natural enough with the "of", though such syntax tends to be used with list arguments.

Then we have classes like Date or DateTime that use regular constructors or constructor functions that start with capitals.

val date = Date(2019, Month.May, 5)
val dateTime = DateTime(2019, 5, 5, 13, 0)

Then we have Time, which uses invoke() on the companion object so that it can do some object pooling prior to actual construction, making it a bit weird. Companion invokes all need to go, but what is the right construction method? timeOf()? But then should all of the date-time representations use a similar style? What makes for the best syntax here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design issue/question
Projects
None yet
Development

No branches or pull requests

1 participant