You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can't look at this and say num->digits should be preferred in any way:
Readability speaking IMO the latter is simpler thus more readable, I know the use of ->> is probably more idiomatic in Clojure, but if that means writing more compliated code, does it worth it?
Operationally the former takes more step, one has to think about stream manipulations rather than just break that apart with str and work on each individual pieces.
In addition, the backbone data structure is lazy sequence vs. String - to be fair I don't know the details about lazy sequence but my Haskell mental model is telling me to expect little to none allocation (assuming this sequence is then immediately followed by exponentiation and consumed by summation) vs. String-based char buffer allocation. But on the other hand the lazy sequence impose a data dependency as to produce a digit will require knowing all previous results but there's nothing preventing String-based to have some parallelism after str is done - plus toString() attempts to breakdown by 100 (see getChars()) rather than 10 - I'd say using str rather than breaking the number down by 10 manually is a performance gain.
In fact I believe in the opposite - the conciseness of string-based approach in comparison to ->> just proved string-based works better for this particular case.
The text was updated successfully, but these errors were encountered:
Yeah this could come across as useful advice or utter snobbery depending on the situation.
I personally remember being rather blown away the day that someone showed me you could split a number arithmetically, without entering the world of strings. This is often people's first encounter with Clojure, and the intention is to encourage them to think more functionally.
As a mentor there is an implicit expectation to offer something of value, so it is useful to have some talking points, so I've used this one many times but only after approving the solution already so as not to block their progress. I sure hope that people are not being told that their string-based solution is wrong.
It might be good to make this more clear in the mentoring note. I appreciate the feedback.
The mentoring note says:
But compare this:
I can't look at this and say
num->digits
should be preferred in any way:->>
is probably more idiomatic in Clojure, but if that means writing more compliated code, does it worth it?str
and work on each individual pieces.str
is done - plustoString()
attempts to breakdown by100
(see getChars()) rather than10
- I'd say usingstr
rather than breaking the number down by10
manually is a performance gain.In fact I believe in the opposite - the conciseness of string-based approach in comparison to
->>
just proved string-based works better for this particular case.The text was updated successfully, but these errors were encountered: