DEV Community

Discussion on: Let's optimize JavaScript - password generator (2.15x faster)

Collapse
nombrekeff profile image
Keff Author

I usually take DX quite seriously on more important things, this was me just having a bit of fun.

The only thing I'm not sure about your code is, the use of constants instead of the static fields on the class. My reasoning behind this was to be able to change them in case the user wanted to use cyrillic or some other alphabet. Although thinking about it now, it would've made more sense to pass them in the options. Any reason why using constants would be considered better DX in this scenario?

Cheers and thanks for the additions!

Collapse
lukeshiru profile image
LUKESHIRU • Edited on

My main reason is mainly usage:

import { Something } from "./Something";

console.log(Something.aValue);

// vs

import { aValue } from "./Something";

console.log(aValue);
Enter fullscreen mode Exit fullscreen mode

Super niche, I know, but the kind of encapsulation that used to be useful from classes now I get from modules :D

Thread Thread
nombrekeff profile image
Keff Author

Ahh okay, makes sense