-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix: adds missing log and improves typing #9
Open
lanterno
wants to merge
2
commits into
main
Choose a base branch
from
fix/adds-missing-log
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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.
Why this? When writing
target?: string
, it is alreadystring | undefined
, and you don't need to give thetarget
argument to the method. So you can write:That simplifies the code a bit.
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 wanted to have "Wallet" as a default "target" but can be optionally set to null/undefined.
Using
target?: string = "wallet"
was what I wanted initially, but it turned out to syntactically incorrect. It's not possible to use?
with a default value.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.
The alternative is to use
target? : string
without a default. But in that case, I'll have to put "wallet" everywhere, and I will not need to putundefined
only in one place.My solution above looked better for me, since I won't need to put "Wallet" everywhere, except for one place where I will need to put
undefined
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 wouldn't accept your solution in production code, because somebody skimming over your code will not realize that
addToLog
useswallet
as the target by default. It will only get clear once you read the definition ofaddToLog
.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.
Reading a function's signature is a requirement to understanding what it does. It only becomes bad if you need to read the implementation of the function to understand what it does.
Since the default value "wallet" is written in the signature, it's not bad.
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.
However, looking at it..
looks "counter-intuitive" to me.
This is why I felt uncomfortable as well. But since you strongly see it's not clean, I'll switch to the other approach, with the default being
null
, andwallet
to be added where it's needed.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.
When reading code, my preference is:
When reading lots of code, even having to look at the context, or, worse, looking at the signature of a method, slows down a lot.
Of course this doesn't apply to important methods, where often it is needed to actually look at the method comments, or even the implementation.
But something trivial as
addToLog
should not need further investigation.Now,
addToLog
could've been namedaddToLogDefaultToWalletDestination
, but that's also slowing down reading a lot.Anyway, as I wrote above, don't worry about this for the moment.
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.
That's a bit different from how I think about it. I would be happy to discuss that a bit further in person.
Does this equal a PR approval then?