# Namespaces, names, operations and entities in software design

**URL:** https://clojureverse.org/t/namespaces-names-operations-and-entities-in-software-design/10538
**Category:** Watercooler
**Created:** [January 21, 2024, 1:43pm UTC](https://clojureverse.org/t/namespaces-names-operations-and-entities-in-software-design/10538 "2024-01-21T13:43:39Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![teodorlu](https://clojureverse.org/user_avatar/clojureverse.org/teodorlu/32/2896_2.png) [@teodorlu](https://clojureverse.org/u/teodorlu)
#### Post date: [January 21, 2024, 1:43pm UTC](https://clojureverse.org/t/namespaces-names-operations-and-entities-in-software-design/10538/1 "2024-01-21T13:43:40Z")

</div>

## Namespaces and names in javascript

`document.getElementById` has been bothering me for a while, and I believe I’m finally able to say why. It’s the naming.

In practice, I have to type lots of letters. That has a big, practical reason: `document.getElementById` lives in the _global namespace_! It has to have a long name that says all the things it does because it doesn’t live in a namespace with a tight purpose.

With namespaces, it could easily have been named _query_, or just _q_ if you will. Yeah, I know we have `document.querySelector` and `document.querySelectorAll`, but they suffer from the same problem! Multiple solutions for different aspects of the same problem, and each has to have a _super long_ name because the name isn’t namespace qualified.

With namespaces _and a module system_ we could even work on improving those namespaces over time. Imagine how nice that would be! For instance, `datascript.core` will not delete its names. And if some revolutionary new knowledge that changes what we know about how EAV querying should be done, `datascript.core2` or `datascript.advancedquery` could be introduced!

This is probably old news to lots of you. I’ve just had this _itch_ for such a long time, and now I’m finally able to say what I didn’t like.

## Namespaces, names, operations and entities in software design

I’ve come to approach software design as the creation of a cohesive set of operations and entities, _named_ in a namespace. This is how I approach all code I write now. Though in certain languages, I feel like this is made harder.

I don’t think I would have come to learn this lesson if I hadn’t started digging into the Clojure rabbit hole. I’ve learned a lot from how Clojure is designed, from Zach Tellman’s _[Elements of Clojure](https://elementsofclojure.com/)_, and more recently reading [Clerk](https://github.com/nextjournal/clerk) source code.

Having a well-designed language with well-designed namespaces and good names at the bottom is such a superpower. Both for using the provided names, and for learning to design new namespaces, names, operations and entities.

For a while, I put way too many “loose ends” into namespaces. Because everything is data, my “entities” weren’t clear from the code. Slowing down helped.

## Does this make sense? Do you agree?

I’ve been pondering about this for a while. I’m posting here on Clojureverse because I’d love to discuss this, and I’ve reallly appreciated previous discussions on Clojureverse. I was half-way through writing this on the Clojurians slack in `#off-topic` when I realized that Clojureverse, with better support for long-form discussion and and searching would probably be a better place.

Let me know what you all think,

—Teodor

---

<div class="post-metadata">

### Author: ![teodorlu](https://clojureverse.org/user_avatar/clojureverse.org/teodorlu/32/2896_2.png) [@teodorlu](https://clojureverse.org/u/teodorlu)
#### Post date: [January 21, 2024, 5:29pm UTC](https://clojureverse.org/t/namespaces-names-operations-and-entities-in-software-design/10538/2 "2024-01-21T17:29:47Z")

</div>

A friend kindly pointed me towards the web browser API for tabs to be used by web browser extensions. It has a less wordy way to query for tabs:

```javascript
let querying = browser.tabs.query(queryObj)

```

(source: [tabs.query() - Mozilla | MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/query))

So it’s definitely possible to create a nice API to query for things in Javascript.

Though I’m still hesitant about the assumption that the object is the namespace. The browser object has a tabs object with has a query function. I can’t easily pass in a “a different browser” (which for instance could be nice for writing unit tests). Though this may just be my preference for Clojure APIs with explicit arguments over object-oriented APIs.

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [January 21, 2024, 6:49pm UTC](https://clojureverse.org/t/namespaces-names-operations-and-entities-in-software-design/10538/3 "2024-01-21T18:49:44Z")

</div>

I disagree with the premise that long names are bad. Quite the opposite. I think `.getElementById` is close to a perfect name, `get-element-by-id` would of course be better. 😉

> [@teodorlu](#):
>
> In practice, I have to type lots of letters.

That is what autocomplete is for. I often use long names, even in Clojure. They are in a way self documenting that way.

Namespaces are a fine thing, but I think you are mostly conflating them with OOP vs FP. In OOP (and your mentioned examples) there is an interface/contract that defines which methods an object supports. This is polymorphic, so somehwat similar to what a protocol would be in Clojure, just less “open”.

`.querySelector` for example is not limited to `document`, it can also be called on a `div` and other elements, to only query that subtree. So, `document.getElementById("app").querySelector("h1.title")` or whatever is perfectly valid useful code. This is something else entirely than namespaces.

---

<div class="post-metadata">

### Author: ![teodorlu](https://clojureverse.org/user_avatar/clojureverse.org/teodorlu/32/2896_2.png) [@teodorlu](https://clojureverse.org/u/teodorlu)
#### Post date: [January 21, 2024, 7:52pm UTC](https://clojureverse.org/t/namespaces-names-operations-and-entities-in-software-design/10538/4 "2024-01-21T19:52:25Z")

</div>

> [@thheller](#):
>
> Namespaces are a fine thing, but I think you are mostly conflating them with OOP vs FP. In OOP (and your mentioned examples) there is an interface/contract that defines which methods an object supports. This is polymorphic, so somehwat similar to what a protocol would be in Clojure, just less “open”.

Point taken—OO APIs are different from FP APIs. If we assume everyone will be using editors with strong intellisense support, longer names can even be _more helpful_ for a programmer with a long list of possible functions, deciding what to use.

If you were to redesign the javascript DOM API now (and a module system / namespaces were available), would you re-introduce same `document.getElementById`, `document.querySelector` and `document.querySelectorAll` as we have today?

---

<div class="post-metadata">

### Author: ![thheller](https://clojureverse.org/user_avatar/clojureverse.org/thheller/32/534_2.png) [@thheller](https://clojureverse.org/u/thheller)
#### Post date: [January 22, 2024, 9:31am UTC](https://clojureverse.org/t/namespaces-names-operations-and-entities-in-software-design/10538/5 "2024-01-22T09:31:02Z")

</div>

Naming things properly is one of the hardest things to do.

If you look at things from a Clojure Perspective a DOM API would likely look very different. I’d still use similar names though. Making names descriptive is more important to me than making them short. Sure, you could use `query` instead of `querySelector`, but I’d argue the second is more descriptive and that is pretty much the only thing that counts. I don’t want to look at code and have to guess what it is querying. Gets worse if you `:refer` a lot and say you `:refer (query)` in multiple places, but in some it is `[some.db :refer (query)]` and some it is `[some.dom :refer (query)]`. Code is read a lot more often than it is written, so do everything to make readable code and avoid confusion.

I have a personal rule against using too many generic names as well. Instead of `:product/name` and `:user/name` I’d have `:my.project/product-name` and `:my.project/user-name` and the like. Especially for things that may clash with `clojure.core` names, since accidental [name shadowing](https://github.com/thheller/shadow-grove/commit/7e17db982f6de79176a8917d1cb7a5ea42328614) has given me so many gray hairs already.

---

<div class="post-metadata">

### Author: ![teodorlu](https://clojureverse.org/user_avatar/clojureverse.org/teodorlu/32/2896_2.png) [@teodorlu](https://clojureverse.org/u/teodorlu)
#### Post date: [April 4, 2024, 10:42am UTC](https://clojureverse.org/t/namespaces-names-operations-and-entities-in-software-design/10538/6 "2024-04-04T10:42:28Z")

</div>

@thheller just wanted to say thanks.

I think your points kind of stuck with me — I think I may have changed my preferences into preferring slightly longer (more verbose) names because longer names can be less ambiguous.

(also, the shadow-cljs documentation might be the best documentation I know of, thanks for that one too)

---

<div class="post-metadata">

### Author: ![alexmiller](https://clojureverse.org/user_avatar/clojureverse.org/alexmiller/32/4805_2.png) [@alexmiller](https://clojureverse.org/u/alexmiller)
#### Post date: [April 4, 2024, 8:41pm UTC](https://clojureverse.org/t/namespaces-names-operations-and-entities-in-software-design/10538/7 "2024-04-04T20:41:37Z")

</div>

Rich Hickey’s [Spec-ulation talk](https://www.youtube.com/watch?v=oyLBGkS5ICk) is all about this concept of disambiguation and turning change into accretion (by making new modules).

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [October 4, 2024, 8:41am UTC](https://clojureverse.org/t/namespaces-names-operations-and-entities-in-software-design/10538/8 "2024-10-04T08:41:48Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
