Re: Page 76 of OCaml by John Whitington ???
"'Mr. Herr' [email protected] [ocaml_beginners]" <[email protected]> Tue, 29 Mar 2016 17:53:39 +0200
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <[email protected]> |
On 29.03.2016 17:37, Douglas Lewit [email protected] [ocaml_beginners] wrote: > > Hi Ken, > > Yes, I understand head :: tail :: remaining..... that makes sense to me. What > bothers me about some Ocaml code is the use of too many abbreviations and very > short variable names. For example, on the web I have noticed a lot of Ocaml code > where you have something like > > |[ ] -> some code > | h :: t -> some more code > > I know what h :: t is, but I think the program is more readable when people use > more meaningful variable names, such as head :: tail -> or headOfList :: > tailOfList, etc, etc. It just makes the program more readable so that another > programmer can look at it and say, "Oh yes, I think I understand what this person > was trying to do". But these days everybody wants to abbreviate everything! I > remember my confusion when someone sent me an email with the abbreviation, LOL. I > thought, "What on earth is LOL?" Someone had to tell me, "Doug, LOL is short for > /laughing out loud/!" But I think it's important to choose meaningful variable > names rather than just x, y, z, h, t, etc. The compiler won't care of course, but > my brain is not an Ocaml compiler! That's why I get a little annoyed when > programmers use just one-letter variable names. Personally, I like to spell things > out in greater detail for the sake of clarity. I think it really makes a difference. > I would rather say "h :: t" is a lot more readable than "firstPartOfList :: secondPartOfListPossiblyEmpty" because the most important thing is the operator :: and all excessive letters to the right or left of it tend to hide it. You could also talk "cognitive load". OCaml is designed to leave off all unnecessary clutter, such as the dreaded { } other languages have. /Str.