6 ms·
Sorry in advance for bikeshedding. This is a cool project and the name is clearly derived from js_of_ocaml, but does anyone know why js_of_ocaml ended up with
by Athas 3y ago
Sorry in advance for bikeshedding. This is a cool project and the name is clearly derived from js_of_ocaml, but does anyone know why js_of_ocaml ended up with such an awkward name in the first place? I am vaguely familiar with the "x_of_y" naming scheme in OCaml (which I also find awkward, but perhaps it sounds better in French) - is that the only reason? I can't find any discussion online, so maybe I'm really the only one who finds the name awkward.
- frou_dh 3y agoIt's just a dodgy French to English translation which then became a convention. Instead of e.g. to_string's buddy being called from_string, it was called of_string. Here's a thread of reddit about it: https://www.reddit.com/r/ocaml/comments/6es88t/what_does_the_of_mean_in_js_of_ocaml/ https://www.reddit.com/r/ocaml/comments/6es88t/what_does_the...
- nequo 3y agoI assume it also has a connection to how algebraic data types are written in OCaml. For example, the equivalent of Haskell's `Maybe` and Rust's `Option` is type 'a option = None | Some of 'a So calling this project "WASM of OCaml" is one way of saying that it "wraps" OCaml code in WASM.
- giraffe_lady 3y agoRight but why do they use "of" in that way for type declarations? Ends up being the same answer: it's a reasonable translation from french for a non-native english speaker.
- wk_end 3y ago...except that the original ML uses the same syntax, and it's Scottish.
- giraffe_lady 3y agoOh interesting, nevermind then. This makes me question the french explanation for the other thing too.
- c54 3y agoIt's fairly colloquial english to say you have "some of something", I think this matches the ocaml language convention pretty nicely
- dan-robertson 3y agoIt’s somewhat hard for me to decide how unnatural a translation this is as I’m used to seeing it in ocaml. My concise dictionary doesn’t have a definition that fits this use well. My non-concise dictionary describes the history of the senses of the word as “exceedingly complex”. It has been used as a translation of the French de since the 11th century and I think it gets some senses (eg derivation) from that. With a verb meaning create, this ocaml construction is fine in modern English (eg ‘make a string of an int’) and dates back a long way (OED offers a source from 893; this is sense I. [VII.] 20. a. in the second edition). So I think partly the question is whether omitting make in make_string_of_int (or String.make_of_int) is an acceptable abbreviation in programming.
- baruchel 3y agoIt doesn't sound better in french. Any reasonable french version should be translated as "from".
- arthurcolle 3y agoString: ficelle Rope (advanced string): corde Thread: fil So string from object would like ficelle d'objet which is yeah, string from object. But the "of" thing in Ocaml is well documented. I vaguely remember them when I had an Ocaml project in my coursework.
- brmgb 3y agoNo, “de” in French has the same meaning as “of” and sounds exactly as weird here. That’s clearly not where this comes from. Also the translation of string with this meaning is “chaîne de caractères”.
- dan-robertson 3y agoIs «chaîne de caractères» what French programmers call strings? (That would surprise me much as English-speaking programmers calling them ‘strings of characters’ would)
- dawnofdusk 3y agoYeah it's the French word. You can always say just "chaîne" when it's unambiguous. Or you can just use the English word
- tome 3y agoI think it's a great convention. It means you write i = int_of_string s where the "i" is next to the "int" and the "s" is next to the "string". i = string_to_int s just looks backwards to me.
- esrauch 3y agoThe topic here isn't so much the order but whether "of" in int_of_string matches a common/typical usage of the word. From the other comments sounds like its local style for OCaml maybe because of some French lineage, but that "int_of_string" is a function that converts a string into an int was definitely not something that I would have assumed (as opposed to 'int_from_string' or something).
- IshKebab 3y agoIt doesn't sound especially weird to me and I'm not French. It's just "[create an] int [out] of [a] string" "from" would have made more sense.
- esrauch 3y agoThe words in brackets are doing all of the heavy lifting in your example though: "Of" without "out of" means "constituted by". If in isolation I saw "array_of_string" I'd definitely parse that as somehow being about str[], not "f(str) -> char[]"
- tome 3y agoWell, if the word order is the most important aspect (as it is to me) then you have to think of another word you can use instead of "of". I know that in my early Haskell programming I was writing `intOfString` where other Haskellers wrote `stringToInt`. I'm a native English speaker so it certainly had nothing to do with French! "Of" just seemed to fit naturally there. Do you think "From" or some other English word would be more natural?
- marcosdumay 3y ago
- brennvin 3y agoI assumed it was meant to evoke William of Occam.
- progval 3y agoI am French, but I feel this matches definitions 2a and 3 on https://www.merriam-webster.com/dictionary/of https://www.merriam-webster.com/dictionary/of : * "used as a function word to indicate origin or derivation, eg. a man of noble birth" (js code comes from ocaml code) * "used as a function word to indicate the component material, parts, or elements or the contents, eg. throne of gold / cup of water" (js application made of ocaml code)
- hajile 3y ago"Cup of water" isn't a great example because it would imply then cup was made from water. This makes more sense when you realize "cup of water" is lazy speech for "cup full of water". "of" usually implies a state of being while "from" implies a transformation. "JS of Ocaml" implies that the JS is Ocaml, but that's not true as it is transformed. "JS from Ocaml" would be more accurate.
- afiori 3y agoThe of in Cup of water act as a normal genitive. It communicates that the cup relates to water and the only reasonable relation between a cup and an edible liquid is that the cup contains the liquid
- l_dopa 3y agoI always assumed this convention was just using "of" in the same sense as function composition. From wikipedia: > The notation g ∘ f is read as "g of f "...
- Foobar8568 3y agoConsidering how math heavy is OCaml and how formal is/were French mathematics, especially post high school, this is most likely the reason.
- baby 3y agoI believe this is because in French you tend to say "x of y".
- Tommah 3y agoIt is named like the <x>_of_<y> functions, yes. "Of" and "from" are both "de" in French. A native English speaker would use "from" there, but whoever named those functions used "of."
- devmunchies 3y agoYeah most likely just french translation. A more accurate translation would have been "from" in this context. `js_from_ocaml`, `string_from_int`, etc would have been clearer in english. If i didn't speak Spanish it would bother me a lot more.
- dgan 3y agoEven the standard library isn't consistent on that. There are plenty of "Something.to_string" But "standard library" never was a strong point of OCaml anyway so I guess meh shrugs