-
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
base: main
Are you sure you want to change the base?
Conversation
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.
Please put the target?: string
back, or give a very good reason not to.
function addToLog(message: string, source: string = "Issuer", target?: string = "Wallet") { | ||
function addToLog(message: string, source: string = "Issuer", target: string | undefined = "Wallet") { |
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 already string | undefined
, and you don't need to give the target
argument to the method. So you can write:
addToLog('Creating connection QRCode', 'Verifier')
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 put undefined
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
uses wallet
as the target by default. It will only get clear once you read the definition of addToLog
.
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 will only get clear once you read the definition of addToLog.
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..
addToLog('message', 'Verifier') // [Verifier -> Wallet]
addToLog('message', 'Verifier', null) // [Verifier]
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
, and wallet
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:
- understanding what a method does by its name
- include the context, comments
- look at the signature, method comments
- look at the implementation
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 named addToLogDefaultToWalletDestination
, 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.
Anyway, as I wrote above, don't worry about this for the moment.
Does this equal a PR approval then?
Two commits: