DEV Community

loading...

Discussion on: Clean up your code with these tips!

Collapse
somedood profile image
Basti Ortiz (Some Dood)

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:

const domain = hostnameAvailable ? window.location.hostname : false;

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.

Collapse
dechamp profile image
DeChamp Author

I like your argument and I agree with you. Thank you for the feed back btw!

Collapse
somedood profile image
Basti Ortiz (Some Dood)

No problem, man! Great article. It made me think of how I could refactor my code in a similar way.

Thread Thread
dechamp profile image
DeChamp Author

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!