Faith Club
Faith Club
- 2016.09.04, 12:13
- I am following some Scala lectures on Coursera right now, and I am growing annoyed how mathematically-academical it is. By that, I mean how the approach to problem solving is often "why don't we just explode the problem space exponentially, without regard for memory or running time, and see if it returns any result, don't care if it bombs out". It's often the exact opposite of real-world problem solving where you must carefully consider memory and CPU time constraints first, and the mathematical elegance of the solution as a distant second.
The other problem, naming. Somehow somebody decided that syntax like (_ + _)
or (_ * _)
makes sense. And you never see (_ - _)
or (_ / _)
ever discussed, because somehow only the + and * operands seem to come up, never - and / where position of operands actually would be important. I am growing annoyed of this handwaving and this "don't worry about it" sweep-it-under-the-rug" attitude of language designers.
(And constantly irritated how this makes code look like it's shitting on you.)
Then, something like list.foldRight(_ + _)
and list.foldLeft(_ + _)
makes appearance, and the method signature is foldRight(A, B) or foldLeft(A, B) without any thought given to providing a better name for the A and B arguments. Seriously, what does A stand for, and what does B act like? Are you absolutely, positively, unable to come up with a name that would make sense?
Why force me to recall whole application semantics for foldLeft and foldRight, can't you substitute some argument names giving me a hint of what is going to be happen. Say, foldRight( tailElement, elementBeforeIt ) and foldLeft( headElement, nextElement )?
(You will also see there is a bit of confusion if B is the single next element or the "rest" of the list, in Scala they define the result as placing the "op" between the elements of list - which is very, very easy to understand, and in other languages you would get some talk about "cons" or subtree or rest of list, any bullshit like that.)
-
0 rakstair doma