-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Report Full: fix delimiter line bug #154
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like lines 67–70 just above could go in an
else
block to thisif
, since when thisif
is true we ignore the results of that code.Or we could just always do the block being added here. It'll do the right thing even if there are no newlines, it'll just do a bit more work to do it. Depends how much we value speed over code complexity here, most messages shouldn't need the extra work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anomiex Thanks for taking a look!
The
else
would still need to be anelse if
with the($showSources === true)
condition, so I don't see much advantage in that as it raises the cognitive load.As messages with new lines in them are very much the exception, not the rule, I'd favour performance in this case.
On that note, I do see another little tweak which can be made to remove a duplicate function call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wouldn't just be an
else if
, it would be like(I switched around the condition there because I find it reads better with the common one-line case first)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, even if I did have any veto power here to demand changes (which I don't), I wouldn't use it on this anyway if you still feel strongly about it. I'd just approve and go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, for me it would be the other way round, if the code had been submitted like that (well, without the unnecessary duplicate
$srcLength
definition), I'd approve & merge it. 😁When writing code myself though, I am very mindful or both performance and cognitive load/nesting levels in code.
The "how much time would it take me to grok this code if I have to look at it again in two years time ?" question.
As the single line code only contain 1 function call and 1 simple calculation which is specific to the single line code (the second function call result is used by both), the performance impact of the way the code is written now is negligible and the nesting levels and the cognitive load is lower (at least for me) 😉.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we both think either version of the code is good enough and we'd both defer to the author's preference in this situation. 🙂
Personally I don't mind the separate setting of
$srcLength
in both code paths, since only one will run and moving it out without potentially setting it unnecessarily would mean having to duplicate theif ($showSources === true) {
check. Then again, if I were writing it entirely myself I'd probably not have$srcLength
at all as I'd find inlining thestrlen
call into the expressions easier to follow.Getting further off topic: I've always found judging cognitive load tricky, I've had plenty of experience both with code I find easy to understand that others tell me they find hard and code I find hard to follow that others tell me they find easier. I've never been able to get a grasp on to what extent that's because I personally think differently from most people and to what extent it's that everyone thinks differently from others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hear you. Let's just say that for now, this patch has had enough love & attention and the code can go in. A future iteration (maybe when I work on the tests), can sort out other tweaks and optimizations.
Thanks for reviewing!