I think it would be better if the fallback value was null instead of false. It doesn't change anything about the program, but semantically, null makes more sense because the variable domain expects a string value. If we were to stick with using false, then I don't think it makes sense that a domain name is a Boolean value. I think it would make more sense to say that it is null, or rather nonexistent.
But then again, I might just be nitpicking here. Nonetheless, it still is a hundred times more readable than the initial code.
Just a coder and a dad. I love my family and I love to code!!!! started coding at 11, so I have 25 years under my belt. Still love learning about it every day. Black lives matter!
Just a coder and a dad. I love my family and I love to code!!!! started coding at 11, so I have 25 years under my belt. Still love learning about it every day. Black lives matter!
Gotta admit, that does indeed look a hundred times more readable (assuming you're familiar with regular expressions).
I would just like to chime in on this line of code in the final example:
I think it would be better if the fallback value was
null
instead offalse
. It doesn't change anything about the program, but semantically,null
makes more sense because the variabledomain
expects a string value. If we were to stick with usingfalse
, then I don't think it makes sense that adomain
name is a Boolean value. I think it would make more sense to say that it isnull
, or rather nonexistent.But then again, I might just be nitpicking here. Nonetheless, it still is a hundred times more readable than the initial code.
I like your argument and I agree with you. Thank you for the feed back btw!
No problem, man! Great article. It made me think of how I could refactor my code in a similar way.
I’m glad to hear! I will add more to it tomorrow as I wasn’t able to list all my tricks. But this should be a good start. Thank you!