TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why I love Common Lisp and hate Java, part II – code examples

16 pointsby mck-over 13 years ago

5 comments

arthurbrownover 13 years ago
This doesn't feel like the author is trying to actually help Java programmers, but rather is just an excuse for him to patronizingly describe a language to those he considers less fortunate.<p>I also don't understand the reason for writing the code in an intentionally non idiomatic style. If you want to convince someone why something is better; show them how it would be done properly. The way it has been presented instead insults the audiences intelligence by presupposing that they would be unable to understand this material, that the author has admittedly only recently picked up himself.<p>I don't think (reduce min list) is going to blow anyone's mind, and writing a function to iterate through the indexes of a list will do more to confuse than to enlighten.<p>not to mention; we've been here before haven't we - <a href="http://c2.com/cgi/wiki?SmugLispWeenie" rel="nofollow">http://c2.com/cgi/wiki?SmugLispWeenie</a>
评论 #3545544 未加载
spacemanakiover 13 years ago
This is an bad example of macros; they're completely unnecessary here. The only thing you're stepping around is the already reader-macro shortened (function &#60;). If you want to show off macros I think you should do it with something that simply cannot be done without them. Otherwise you end up with these pissing matches in the comments and the discussion diverges entirely away from metaprogramming to talking about characters or lines of code saved, which is kind of not that interesting. And Java vs Lisp is already kind of a tired topic. (Lisper and card carrying Java-hater here)
评论 #3545480 未加载
jsankeyover 13 years ago
Sigh. A good Java coder will also "get itchy" when writing two such similar functions. In fact, they'll probably already have a library that provides predicates that make the same level of abstraction trivial. Sure, the code in the predicate, being a whole class, will be a bit verbose, but that's a separate issue.
评论 #3545321 未加载
itover 13 years ago
It can be written more concisely with fold.<p><pre><code> $ ghci Prelude&#62; let getFromList ls pred = foldl (\x y -&#62; if x `pred` y then x else y) (head ls) (tail ls) Prelude&#62; getFromList [1..10] (&#60;) 1 Prelude&#62; getFromList [1..10] (&#62;) 10</code></pre>
评论 #3545337 未加载
ElliotShover 13 years ago
That's funny... I posted a few alternate java examples to his blog but it looks like the comment was rejected.<p>(Perhaps because I said the lisp looked like vomit? but it does!)<p>int getMax(int... list) { int max = list[0]; for (int i : list) max = Math.max(max, i); return max; }<p>or if you have a collection Collections.min(list);
评论 #3545414 未加载