4 ms·
I'm not sure print(firstname, lastname) for example is more readable than print((firstname, lastname)) especially since I would then have to write
by Znafon 3y ago
I'm not sure
print(firstname, lastname)
for example is more readable than
print((firstname, lastname))
especially since I would then have to write
print((surname,))
to just print a single string.
Variadic functions are rather classic, I think Go, Rust, C and JavaScript also have them.
- esafak 3y agoYour example has a fixed number of names. What if you wanted to accept any number of names, like Pablo Diego José Francisco de Paula Juan Nepomuceno María de los Remedios Cipriano de la Santísima Trinidad Ruiz y Picasso? Really, though, Iterables make more sense for monadic types.
- sdenton4 3y agoWe would force broad changes in human society to conform to the assumptions of our database scheme, same as we always have.
- thaumasiotes 3y agoI knew a Chinese girl whose parents, surnamed 吕 and 郎, wanted to give her the combined surname 吕郎. This was not allowed, so formally she was surnamed 吕 and given a three-syllable personal name starting with 郎. There are a couple funny things about this: 1. A personal name of three syllables is stranger than a surname of two. 2. Double-syllable surnames are unusual, but definitely not unheard of. This girl told me that she hadn't been allowed to receive the double surname 吕郎, because it was too long. I asked what would have happened if her double surname had been 司马 instead. "That's different!" (If the government of China tried to pick a legitimacy fight with the name 司马, it would lose, and everyone knows this.) So this almost looks like an example of the kind of thing you're referring to, except that the database scheme has nothing to do with it. A surname that was nontraditional but within the technical norms was rejected in favor of a personal name that was both nontraditional and well outside the technical norms.
- insanitybit 3y agoFWIW Rust does not have variadic functions. The closest thing would be either macros, which are variadic, or trait methods, which are not variadic but can look like they are.
- Znafon 3y agoOh yeah, that’s right! Thanks for the correction
- uxp8u61q 3y agoHow is it more "readable"? The two are just as readable. What do you do with your first example if you have a list (generated at runtime, not a static one) to pass to the function? This wouldn't work (imagine the first line is more complicated): l = (1,2,3) print(l)
- BurningFrog 3y agoIt's more readable, for my brain at least, because there is less distracting syntax cruft lying around.
- uxp8u61q 3y agoYou're distracted by the parentheses? Really?
- BurningFrog 3y agoAbsolutely! Something I keep relearning is that people are different, sometimes in ways hard for me to comprehend :)
- zem 3y agothat's what the splat operator is for - it unpacks a list into separate arguments. in this case e.g. xs = (1, 2, 3) f(*xs) is equivalent to f(1, 2, 3), not f((1, 2, 3))
- uxp8u61q 3y agoAnd that's readable?