2 ms·
To my mind, besides all the import guff, the core of that code is more readable than many of the other language implementations and just as concise.
by nevster 14y ago
To my mind, besides all the import guff, the core of that code is more readable than many of the other language implementations and just as concise.
- irahul 14y agoWhat are you considering the core? The nurble method? Ruby: configure do @@nouns = Set.new File.open('nouns.txt').map {|noun| noun.strip.downcase } end def nurble(text) words = Set.new text.downcase.split # Replace words which are not nouns with nurble. (words - @@nouns).each do |word| text.gsub! /(\b)#{word}(\b)/i, '\1<span class="nurble">nurble</span>\2' end text.gsub(/\n/, '<br />') end Python is similar. Personally, I find it far more readable that the JSP sample.
- nevster 14y agoYeah - the nurble method. It's really the Clojure that looks the worst. Taking just the boolean query to figure out whether the word is in the noun list, I'd place them in this order from simplest to understand through to most obfuscated Python: if word not in NOUNS Java: if (!nouns.contains(word)) PHP: if(!in_array($word, $nouns)) Ruby: if not @@nouns.include? word Clojure: if (not (some (partial = word) nouns)) The Python is pretty much just english The Java is almost english except for the ! PHP is starting to get more obtuse - ! and $ and you have to know the order of the parameters Ruby (from the article) has @@ and ? but isn't too bad - might go above the php Clojure is just weird - looking at the others, I reckon a person could easily modify and write a similar program without knowing much of the language. With Clojure I think it requires deeper understanding. I haven't included your Ruby in that list because it's doing a different (much neater :) ) thing.