-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
DateInRegion init() with multiple way to express a single concept #123
Comments
You are correct! :) I wanted to make it simple to use but you certainly have a point. On the other side it is just handy to be able to initialise with any mix of parameter types as long as it produces a consistent date. To stop confusion between calendars, time zones and locales, a purer version would be:
Better? |
The advantage of one big initialiser is that it can be used in various ways. E.g.:
If we split this up into dedicated initialisers, it is not possible to use default parameters on each as it would create ambiguity. I.e. the compiler would not be able to determine which initialiser Alternative 1:
Alternative 2:
Other ideas? |
Or maybe even better: |
@malcommac I created a branch. Check this one: 4dc8743. This keeps things simple and flexible. |
A best practice question is valid here too. Assume a class
|
I would tend to discourage the use of several init parameters to express the same concept because it increases the complexity of the library. public convenience init?(
fromString date: String,
format: DateFormat,
calendarType: CalendarType? = nil,
timeZoneRegion: TimeZoneConvertible? = nil,
locale aLocale: NSLocale? = nil,
region aRegion: DateRegion? = nil) And you can specify a
So we have a single passed object type without losing the flexibility of the lib. |
Hmmm, I can go with you on this one. My main concern with the TimeZones is that I want to be able to use an abbreviation in a quick way. Anyway I would tend to make it even more consistent and leave any duplication out of the parameters to get the required clarity. I.e. remove the calendar, time zone and locale references and do the same thing you mention above into the region and do the same trick there. Or the other way around: get rid of the region and make calendar, time zone and locale explicitly defined in all functions. I would be in favour of the former as in the real world we would want the date conversion to be from a specific location (date region) and deal with that level of abstraction as opposed to multiple objects like time zone, calendar and/or locale. The code would become: public convenience init?(
fromString date: String,
format: DateFormat,
region aRegion: DateRegion? = nil) In case of quick partial regions (e.g. just time zone conversion) the code would become:
Do you agree on this approach? |
I agree with your proposed init with |
DateRegion naming continued in #127 |
Ok let us proceed with this paradigm then 👍 |
@Hout I'm thinking about the new init in DateInRegion:
As you said rightly some time ago we should keep this library simple to use.
Here we have three different kind of parameters to express a single concept; for example we have
calendarType
,calendarID
andcalendar
to express the same thing in different modes.My idea is to use a single mode; just for example we could accept only
CalendarType
and create init methods to create a new CalendarType from ID string or an NSCalendar instance,keeping only one way to specify a calendar (the same thing is valid for timezone).What do you think?
The text was updated successfully, but these errors were encountered: