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

Allow an ARKLogMessage to be created with an arbitrary creationDate. … #34

Merged
merged 1 commit into from
Mar 22, 2016

Conversation

rhgills
Copy link
Collaborator

@rhgills rhgills commented Mar 18, 2016

…Use designated initializers.

@rhgills
Copy link
Collaborator Author

rhgills commented Mar 18, 2016

r @dfed

@rhgills
Copy link
Collaborator Author

rhgills commented Mar 18, 2016

This is useful for testing, where you might want to decouple ARKLogMessages' creation date from the current system time. Also theoretically useful if using ARK to later persist log messages that were actually recorded at a date in the past.

@rhgills rhgills force-pushed the rhg/ark-log-message-create-with-date branch from d244583 to f14b1e0 Compare March 18, 2016 01:51
@@ -27,15 +27,23 @@ NS_ASSUME_NONNULL_BEGIN

@interface ARKLogMessage : NSObject <NSCopying, NSSecureCoding>

/// @warning Do not use this initializer.
/// @raises NSInternalInconsistencyException This is not a valid initializer.
- (instancetype)init;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary? I'm pretty strongly opposed to giving people rope to hang themselves with.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I see why you did this now. Just mark init and new as NS_UNAVAILABLE to prevent the need for this grossness

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purposefully don't want to mark init and new as unavailable so that subclasses of ARKLogMessage can define init as their designated initializer, if they so wish.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before you were already hanging yourself by calling init on a log message, silently creating a useless, empty object. Now this makes your likely programming error more obvious.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, but before I didn't really know what I was doing, and now I do.

I'd say let's do the following: Create an ARKMessage protocol that ARKLogMessage implements. Mark new and init as unavailable, and make everything that currently takes an ARKLogMessage take an id <ARKMessage> instead. That way we don't need to rely on subclassing (which leads to epic grossness), but rather can rely instead on protocol implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is a better design, but this is a pretty substantial refactor. I'm just trying to make a targeted incremental change to make this a bit better. Could we have the protocol approach be our plan of record going forwards?

@dfed
Copy link
Collaborator

dfed commented Mar 18, 2016

Worth noting that for testing I created ARKFakeLogMessage which just had a date. Not sure I follow your point re persisting messages created earlier... you mean turning non-ARKLogMessages into ARKLogMessages at a later date?

Basically, I'm not entirely convinced about the necessity of this functionality in the main project. Please sell me on it :)

#pragma mark - Properties
- (instancetype)initWithDate:(NSDate *)date;
{
NSString *text = [[[self class] sharedDateFormatter] stringFromDate:date];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This initializer is truly weird. Why would you want an ARKLogMessage that just contained a date in both NSString and NSDate format?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know! This isn't new! I think this is for the rows in the ARKLogTableView that just display the time.

@rhgills
Copy link
Collaborator Author

rhgills commented Mar 18, 2016

I do mean turning non-ARKLogMessages into ARKLogMessages at a later date, or perhaps backdating a message explaining an event to the original date of occurrence, even if the event can only be identified later.

@rhgills
Copy link
Collaborator Author

rhgills commented Mar 18, 2016

ARKFakeLogMessage might work for my purpose, but given that ARKLogMessage declares the date property, it seems cleaner to use that ivar instead of subclassing to provide a setter, which can no longer reference the same (private) ivar

@@ -27,15 +27,23 @@ NS_ASSUME_NONNULL_BEGIN

@interface ARKLogMessage : NSObject <NSCopying, NSSecureCoding>

/// @warning Do not use this initializer.
/// @raises NSInternalInconsistencyException This is not a valid initializer.
- (instancetype)init NS_UNAVAILABLE;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also need to mark +new as unavailable

@rhgills rhgills force-pushed the rhg/ark-log-message-create-with-date branch from dc3d05c to eb19f4f Compare March 22, 2016 21:32
@dfed
Copy link
Collaborator

dfed commented Mar 22, 2016

Merge when green!

@rhgills rhgills force-pushed the rhg/ark-log-message-create-with-date branch from eb19f4f to 7962a0b Compare March 22, 2016 21:36
@rhgills rhgills force-pushed the rhg/ark-log-message-create-with-date branch from 7962a0b to f1e7dbc Compare March 22, 2016 23:00
@rhgills rhgills merged commit a92b3d8 into master Mar 22, 2016
@martinmroz martinmroz deleted the rhg/ark-log-message-create-with-date branch March 30, 2016 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants