4 ms·
What a waste of an article. 8 lines of code for haskell, 19 lines for clojure. The problem is easily solved in one line. I seriously don't care that's he comp
by segmondy 13y ago
What a waste of an article. 8 lines of code for haskell, 19 lines for clojure. The problem is easily solved in one line. I seriously don't care that's he comparing core.type, when you start trying to write langauges the same way, you lose the advantage that they provide.
1 line of python.
print sum(filter(lambda x: (x % 3 == 0) or (x % 5 == 0), range(1, 1000)))
clojure
(apply + (filter #(or (= 0(mod % 3)) (= 0(mod % 5))) (range 1 1000)))
- tieTYT 13y agoIMHO, your code is much harder to read than his. It looks like its been run through a minifier. I'd rather maintain his code.
- adestefan 13y agoThe clojure code is pretty idiomatic and clear to anyone that's done work in lisp-like languages.
- awj 13y agoAs someone who has done work in lisp-like languages, I would call the clojure code legible but not "clear". It's perfectly fine for a one-off solution, but I wouldn't consider it acceptable for anything I planned on coming back to in a few months.
- tieTYT 13y agoI don't know when I cross that line of someone who's done work in lisp-like languages, but I've made two or three small hobby projects in clojure and contributed a bug fix to http-clj and am well versed in the source code of seesaw. I don't usually see code like that in those projects.
- Fishkins 13y agoIn Haskell it could be sum $ filter (\x -> mod x 3 == 0 || mod x 5 == 0) [1..1000] but I don't think that detracts from the article. He said up front his solution was over-engineered. That's nice in this case, because it lets us see how the type annotations look for very small, simple functions so we can get an idea what they looked like. I know some Haskell and Clojure, but I'd never actually looked at core.typed. This was a nice, basic intro to it.
- awj 13y ago> I seriously don't care that's he comparing core.type ...so you object to his solutions because you don't care about the point of the article, which is what forces him into those specific solutions.
- adambard 13y ago> I seriously don't care that's he comparing core.type [sic] Well then I'm afraid the article has nothing to offer for you.
- Sheepshow 13y agoMore idiomatic Python, and quite clear IMHO print sum(x if x % 3 == 0 or x % 5 == 0 else 0 for x in range(1, 1000))
- Fishkins 13y agoYeah, a list comprehension is the easiest way to write it in any of the languages. I think it's a little clearer/shorter to do print sum(x for x in range(1, 1000) if x % 3 == 0 or x % 5 == 0)