Names and clojure.core

120 views
Skip to first unread message

Mark

unread,
Mar 28, 2013, 9:51:15 AM3/28/13
to clo...@googlegroups.com
I'm still just a Clojure hobbyist, but I have a question for folks who are using Clojure professionally or for larger scale projects. Recently, I've been finding that it's difficult to come up with names for variables and functions that aren't already in the clojure.core namespace.

For instance, I have a little toy project that digs through DNA sequence data to extract some simple metrics. I obviously can't call a variable or function "seq" because that's meaningful in clojure.core already. It turns out, I also can't call it "bases", because that's a function in clojure.core also. I could call it dna, but that's sort of undescriptive (it's important to me that the name indicate the sequential nature of what the binding refers to). 

In the course of writing about 30 lines of code last night, I accidentally caused name collisions with two or three other existing functions in clojure.core. Do other people have this problem? Am I just too uncreative? Am I being too terse?

Mark

Michael Klishin

unread,
Mar 28, 2013, 9:53:19 AM3/28/13
to clo...@googlegroups.com

2013/3/28 Mark <mjt...@gmail.com>

Do other people have this problem? Am I just too uncreative? Am I being too terse?

Simply exclude some clojure.core functions in your namespace declaration and use them as clojure.core/... 
if you need them. It's perfectly fine to use names such as find,get and so on in your own namespaces.

http://clojure-doc.org/articles/language/namespaces.html#the_referclojure_helper_form

--
MK

http://github.com/michaelklishin
http://twitter.com/michaelklishin

Timothy Baldridge

unread,
Mar 28, 2013, 9:59:39 AM3/28/13
to clo...@googlegroups.com
Also notice that local scope overrides the global scope (unlike other languages). So something like this is perfectly legal:

(defn foo [x]
 (let [seq (next x)]
  seq))

Now, if you need to use the function known as "seq" later on in your function, you may run into issues. But I often use clojure.core names as variables if it makes a given function cleaner. 

Timothy


--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
“One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.”
(Robert Firth)

vemv

unread,
Mar 28, 2013, 10:04:12 AM3/28/13
to clo...@googlegroups.com
Yeah being able to reuse names is part of the point of namespaces :) it makes me sad when libraries use ugly names like megaref (for ref) or alter!! (for alter) instead of exploiting this fact.

Mark

unread,
Mar 28, 2013, 10:06:10 AM3/28/13
to clo...@googlegroups.com
I thought about that, but I wasn't sure if it was a good idea. I suppose as long as my function definitions are short enough that anyone reading them can see both the name binding and all of its usages, then there's not so much confusion.

Thanks.

Mark

unread,
Mar 28, 2013, 10:07:52 AM3/28/13
to clo...@googlegroups.com
Nice. I think in a couple of places I can safely do this. Thanks!

Cedric Greevey

unread,
Mar 28, 2013, 11:18:02 AM3/28/13
to clo...@googlegroups.com
If there's a still-short, non-colliding, more descriptive name, why not use that? In the example given in the original post, for instance, how about "dna-seq" as the variable name? That makes it clear both that it's sequential and what it's a sequence of, and shouldn't collide with any other names you're likely to import.


--

Gregg Reynolds

unread,
Mar 28, 2013, 11:21:18 AM3/28/13
to clo...@googlegroups.com
On Thursday, March 28, 2013 8:51:15 AM UTC-5, Mark wrote:
I'm still just a Clojure hobbyist, but I have a question for folks who are using Clojure professionally or for larger scale projects. Recently, I've been finding that it's difficult to come up with names for variables and functions that aren't already in the clojure.core namespace.

If it's any consolation, I find that coming up with good names is one of the hardest (and least appreciated) aspects of programming.
 
For instance, I have a little toy project that digs through DNA sequence data to extract some simple metrics. I obviously can't call a variable or function "seq" because that's meaningful in clojure.core already. It turns out, I also can't call it "bases", because that's a function in clojure.core also. I could call it dna, but that's sort of undescriptive (it's important to me that the name indicate the sequential nature of what the binding refers to).

Think metaphorically - dozens of possibilities.  String, slab, run, flow, clip (of film = seq of frames), chain, train, parade, etc.  I find that sometimes digging through etymologies (www.etymonline.com) turns up new ideas.

-Gregg

Mark

unread,
Mar 28, 2013, 11:28:58 AM3/28/13
to clo...@googlegroups.com
I definitely agree that nomenclature is often one of the hardest things to handle well. I'm actually a professional software engineer in real life, but I don't get to use Clojure at work. I suppose the names I suggested were uninspired partially because I only get a few minutes at a time to work on my hobby projects outside of work.

Thanks!

Mark Tomko

unread,
Mar 28, 2013, 11:29:09 AM3/28/13
to clo...@googlegroups.com
I definitely agree that nomenclature is often one of the hardest things to handle well. I'm actually a professional software engineer in real life, but I don't get to use Clojure at work. I suppose the names I suggested were uninspired partially because I only get a few minutes at a time to work on my hobby projects outside of work.

Thanks!

--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/LIUAgA4GSB8/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.

Brian Marick

unread,
Mar 28, 2013, 12:06:21 PM3/28/13
to clo...@googlegroups.com

On Mar 28, 2013, at 8:51 AM, Mark <mjt...@gmail.com> wrote:

> In the course of writing about 30 lines of code last night, I accidentally caused name collisions with two or three other existing functions in clojure.core. Do other people have this problem? Am I just too uncreative? Am I being too terse?

Old Smalltalk style was to use names like `a-string`, which would avoid collisions. I was never very fond of it.

--------
Looking for employment as a Clojure programmer
Latest book: /Functional Programming for the Object-Oriented Programmer/
https://leanpub.com/fp-oo

John Gabriele

unread,
Mar 30, 2013, 12:03:04 PM3/30/13
to clo...@googlegroups.com
On Thursday, March 28, 2013 9:53:19 AM UTC-4, Michael Klishin wrote:

2013/3/28 Mark <mjt...@gmail.com>
Do other people have this problem? Am I just too uncreative? Am I being too terse?

Simply exclude some clojure.core functions in your namespace declaration and use them as clojure.core/... 
if you need them. It's perfectly fine to use names such as find,get and so on in your own namespaces.

http://clojure-doc.org/articles/language/namespaces.html#the_referclojure_helper_form


My only complaint about doing this is that it would cause me to do a double-take every time I saw the clojure.core name (ex. "Wait --- is that the clojure.core foo or the local foo? Lemme just glance around...").

I'd suspect that using slightly longer and hyphenated names would be easier to read and more descriptive, and it only require typing a few extra characters (`dna-seq`, `base-pairs`, etc.).

---John

Reply all
Reply to author
Forward
0 new messages