While working with a dynamically typed lang, I came across this:
hash(password, algorithm, algorithmOptions)
Where algorithm
is a constant signaling which hashing algorithm to use, and algorithmOptions
is a dict whose keys depend on algorithm
.
So I thought, can we dictate that if a previous parameter has this value, then this parameter has to have this other value?
E.g.
enum HashAlgo {
Bcrypt,
Argon2,
}
type BcryptOptions = {
Int optionA,
Int optionB,
}
type Argon2Options = {
String optionC,
String optionD,
}
// Here I make this type "depend" on an argument of type HashAlgo
type HashOptions = [HashAlgo] => {
HashAlgo::Bcrypt => BcryptOptions,
HashAlgo::Argon2 => Argon2Options,
}
fun hash(
String password,
HashAlgo algorithm,
// Here I use HashOptions, passing the prev. argument
HashOptions[algorithm] options,
)
This way the compiler can ensure the correct dict is used, based on the value of algorithm
Does something like this exist? I now realize that it would be impossible to type check in compile time based on a runtime value, but if it was allowed only for constants? What do you think?
Huh, I thought most keybindings where tied to the position of the keys, being vim "motions", as in how you move your fingers or something like that.
Maybe there are vim layouts for dvorak that I can use? Because I think I'd prefer to have the keybindings in the same place.
I use a dvorak-based layout personally, but spanish QWERTY at work. Some time ago I learned EMACS with qwerty, so when I switched to dvorak my muscle memory was ruined, even if I knew the keybindings. I wonder if it's worth it learning 2 keybindings to be able to switch layouts