tag:blogger.com,1999:blog-4110180.post5336318002760111319..comments2023-06-20T05:31:24.545-07:00Comments on Tapestry Central: Crafting Code in ClojureAnonymoushttp://www.blogger.com/profile/04486596490758986709noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-4110180.post-82205955825194013462013-02-11T02:31:16.435-08:002013-02-11T02:31:16.435-08:00That Java code is so poor it's difficult not t...That Java code is so poor it's difficult not to see it as a straw man.<br /><br />Nobody should be writing String joining code inline - at the very least, this would be in a util class (if for some reason you don't want to use one of the many libs that provide this).<br /><br />And using TreeSet instead of HashSet would give you the sorting for free without the need for a temporary ArrayList.Michael Snellhttps://www.blogger.com/profile/02964712142212222175noreply@blogger.comtag:blogger.com,1999:blog-4110180.post-12727985915773233182013-02-02T20:00:43.622-08:002013-02-02T20:00:43.622-08:00@Mithaldu: By "long time" you mean "...@Mithaldu: By "long time" you mean "about thirteen years," since the term "code golf" entered the lexicon in 1999.<br /><br />I prefer the idea of craftsmanship. It's not about the fewest keystrokes: it's about an expression that's both concise and clear. I think Howard's done that here.Elf Sternberghttps://www.blogger.com/profile/16692304291612435287noreply@blogger.comtag:blogger.com,1999:blog-4110180.post-92077088195394464612013-02-02T17:53:15.686-08:002013-02-02T17:53:15.686-08:00Wow! This is so Monadic, I really missed that from...Wow! This is so Monadic, I really missed that from Haskell that in fact you opened my eyes with this blog post. Thank you for taking the time to share something so important as the function sequencer (->> a.k.a. >>=) n_nAnonymoushttps://www.blogger.com/profile/04403168609000686843noreply@blogger.comtag:blogger.com,1999:blog-4110180.post-52399101367364733432013-02-02T10:07:11.065-08:002013-02-02T10:07:11.065-08:00F# https://gist.github.com/4697027F# https://gist.github.com/4697027Vasilyhttps://www.blogger.com/profile/08538100460991899296noreply@blogger.comtag:blogger.com,1999:blog-4110180.post-22711458245433549322013-02-02T06:18:48.597-08:002013-02-02T06:18:48.597-08:00If you use
List sortableKeys = new ArrayList...If you use <br /><br /> List sortableKeys = new ArrayList(allKeys);<br /><br />and<br /><br /> return StringUtils.join(sortableKeys, ",").toString();<br /><br />you can halve the size of the Java code. :|Joshhttps://www.blogger.com/profile/14644106735814794239noreply@blogger.comtag:blogger.com,1999:blog-4110180.post-81528687960530283022013-02-01T20:55:47.968-08:002013-02-01T20:55:47.968-08:00Hey Howard,
This was a great read. Thanks for pos...Hey Howard,<br /><br />This was a great read. Thanks for posting it!<br /><br />Once I read the brief, I fired up IRB and implemented this with Ruby as I was curious to see how my result would compare to Clojure's. This isn't necessarily idomatic, but was fun nonetheless: https://gist.github.com/4696154<br /><br />The Clojure solution is very elegant. Definitely going to spend some more time with Clojure over the next year or so.<br />Unknownhttps://www.blogger.com/profile/09762265034586820724noreply@blogger.comtag:blogger.com,1999:blog-4110180.post-85347131466092062612013-02-01T16:32:59.055-08:002013-02-01T16:32:59.055-08:00I implemented a version in Factor, to show how sim...I implemented a <a href="http://re-factor.blogspot.com/2013/02/crafting-code-in-factor.html" rel="nofollow">version in Factor</a>, to show how similar and a little different it is.mrjbq7https://www.blogger.com/profile/06842721076008035602noreply@blogger.comtag:blogger.com,1999:blog-4110180.post-89531023293109230672013-02-01T16:02:09.759-08:002013-02-01T16:02:09.759-08:00Once upon a time, I would have been impressed by t...Once upon a time, I would have been impressed by that - but the same thing in something like Python looks like this:<br /><br />def DictKeysToString(x, y):<br /> keys = sorted(set(x).union(y))<br /> return ', '.join(keys) or 'none'<br /><br /># e.g.<br />x = {'a': 1}<br />y = {'a': 2, 'b': 3}<br />DictKeysToString(x, y)<br /># returns 'a, b'<br /><br />Extending this to take an iterable of dicts is pretty easy as well.<br /><br />I really miss that clean, obvious terseness in other languages I use.d.a.https://www.blogger.com/profile/11762683484947204364noreply@blogger.comtag:blogger.com,1999:blog-4110180.post-18406946471455157822013-02-01T15:45:58.259-08:002013-02-01T15:45:58.259-08:00When you say "craft" you mean another wo...When you say "craft" you mean another word that's been around a long time: Golf. What you did is golf your code. Cheers on discovering the usefulness and fun of this old pastime. :)Mithalduhttps://www.blogger.com/profile/17588249794659757763noreply@blogger.comtag:blogger.com,1999:blog-4110180.post-43769731213627922682013-02-01T15:44:45.817-08:002013-02-01T15:44:45.817-08:00@Dmiitri,
That's a nice solution as well (pro...@Dmiitri,<br /><br />That's a nice solution as well (probably better than mine). That being said, I like how my article stands because it does demonstrate how easy it is to add your own logic into a flow, largely by following the last parameter convention.<br /><br />This scenario does happen a bit: a piece you need is already present in core, but easy to miss. Everyone who'se done http://www.4clojure.com/ exercises has seen this when their carefully crafted, super-concise solution ends up twice as large as Chouser's.Anonymoushttps://www.blogger.com/profile/04486596490758986709noreply@blogger.comtag:blogger.com,1999:blog-4110180.post-74350483700939352832013-02-01T15:33:49.346-08:002013-02-01T15:33:49.346-08:00you could use not-empty to get rid of the replace-...you could use not-empty to get rid of the replace-empty all together as well<br /><br />https://gist.github.com/4694924Anonymoushttps://www.blogger.com/profile/10723755439640978260noreply@blogger.comtag:blogger.com,1999:blog-4110180.post-7101701995081256942013-02-01T15:29:39.147-08:002013-02-01T15:29:39.147-08:00This comment has been removed by a blog administrator.Anonymoushttps://www.blogger.com/profile/10723755439640978260noreply@blogger.com