
Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [tlug] Code Readability (was: perl?)
On 19 August 2016 at 15:24, Curt Sampson <cjs@example.com> wrote:
> A lot of people think about readability as a property of a language,
> but that's not right.
Really excellent explanation!
> def double(xs); xs.map { |x| x*2 }; end
Yes! Or better yet, any of these, depending on how Lispy or Clojurey
you want to get:
(defn double [xs] (map #(* % 2) xs))
(defn double [xs] (map (fn [x] (* x 2)) xs))
(defn double [xs] (map (partial * 2) xs))
(def double (partial map #(* % 2)))
> [M]y conventions:
>
> 1. If you have just a generic number in a small context, call it `x`.
> 2. A list of things is the name of the thing with an `s` on the end.
> 3. Put short stuff on a single line.
> 4. Don't use extra characters and extra lines for do/end when you
> can use the shorter braces {} that also let you do paren matching
YES to all four!
> The long and short of it is:
>
> First, write for your audience.
> Second, try to work with your group to optimize your style.
This was some of the best programming advice I've seen distilled into
such a short post. Thanks!
Cheers,
Josh
Home |
Main Index |
Thread Index