Re: Naming factory functions

2010-04-29 Thread Timothy Pratley
On 23 April 2010 12:21, joshua-choi rbysam...@gmail.com wrote:

 When it comes to naming factory functions—functions that create things—
 clojure.core gives four precedents:

 1. Name it exactly what the new object is called. vector, hash-map,
 set.
 2. Name it a shortened version of #1. vec.
 3. Prefix #1 with make-. make-hierarchy, make-array.
 4. Prefix #1 with create-. create-ns, create-struct.

 Are there any guidelines for naming a library's own factory functions?

 (I find #1 and #2 pretty annoying, since they interfere with my
 binding of symbols in let forms, but between #3 and #4 I'm not sure.)


I tend to prefer #1 and then either qualify the binding name or use a single
character depending on the depth of the let:
eg: If button makes a JButton
(let [ok-button (button Are you sure this is ok?)]
  ...
  (something ok-button)
  ...)
(let [b (button This is a small scope)
  (.add foo b))

;; just my 2cents... interested to hear what others prefer.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Naming factory functions

2010-04-29 Thread ataggart
I think names such as vector and hash-map are ok precisely because
they are such fundamental types, and bindings typically use one-char
names; brevity matters.  (And vec is just a special case of vector)

I'm not sure if there's some deeper nuance in the naming between the
make-* and create-* functions (perhaps Rich knows), but for what it's
worth the doc for the make-* functions all start with Creates 
Being a fan of brevity and having a java background, I've been
inclined to use new-*.

Then temper all this with the deftype/defrecord stuff in which new
instances are created using host-constructor syntax, e.g.:
user= (defrecord foo [bar baz])
user.foo
user= (foo. 1 2)
#:user.foo{:bar 1, :baz 2}

Which for me further reinforces the use of new-*, at least for those
cases where I'm not using dot-suffixed constructor names.



On Apr 22, 7:21 pm, joshua-choi rbysam...@gmail.com wrote:
 When it comes to naming factory functions—functions that create things—
 clojure.core gives four precedents:

 1. Name it exactly what the new object is called. vector, hash-map,
 set.
 2. Name it a shortened version of #1. vec.
 3. Prefix #1 with make-. make-hierarchy, make-array.
 4. Prefix #1 with create-. create-ns, create-struct.

 Are there any guidelines for naming a library's own factory functions?

 (I find #1 and #2 pretty annoying, since they interfere with my
 binding of symbols in let forms, but between #3 and #4 I'm not sure.)

 --
 You received this message because you are subscribed to the Google
 Groups Clojure group.
 To post to this group, send email to clojure@googlegroups.com
 Note that posts from new members are moderated - please be patient with your 
 first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group 
 athttp://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Naming factory functions

2010-04-22 Thread joshua-choi
When it comes to naming factory functions—functions that create things—
clojure.core gives four precedents:

1. Name it exactly what the new object is called. vector, hash-map,
set.
2. Name it a shortened version of #1. vec.
3. Prefix #1 with make-. make-hierarchy, make-array.
4. Prefix #1 with create-. create-ns, create-struct.

Are there any guidelines for naming a library's own factory functions?

(I find #1 and #2 pretty annoying, since they interfere with my
binding of symbols in let forms, but between #3 and #4 I'm not sure.)

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en