<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged reexport</title>
<link>https://ask.clojure.org/index.php/tag/reexport</link>
<description></description>
<item>
<title>How to define namespace interface boundaries (like with index.js files in JS)</title>
<link>https://ask.clojure.org/index.php/14315/define-namespace-interface-boundaries-like-with-index-files</link>
<description>&lt;h2&gt;tl;dr&lt;/h2&gt;
&lt;p&gt;One of the things I actually like about JS is that I can declaratively define the interfaces/boundaries of folder-level modules through defining a public interface by re-exporting what's supposed to be accessible to other modules and I'm wondering if there's something similar in Clojure (and if not - what's the best way to request a feature).&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;EDIT: Don't know why the formatting isn't working, the question's preview looks fine...&lt;/p&gt;
&lt;p&gt;Let's say there's the following folder structure:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;| my-project/
|-- src/
|---- product/
|------ product_related_module/
|------ other_product_related_module/
|---- catalog/
|------ catalog_related_module/
|---- checkout/&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I don't want the catalog and checkout modules to know anything about internal things of the product module. Instead I want the product module (all modules actually) to declare its interface, which to me means that there's a file that explains what's being exposed and supposed to be used.&lt;/p&gt;
&lt;p&gt;In JS, I can define whatever is supposed to be publicly by using index.js files that do only one thing: re-exporting what's supposed to be public. Everything else is considered internal (can be enforced with eslint).&lt;/p&gt;
&lt;p&gt;This helps tremendously to maintain a loosely coupled and strongly cohesive project. With this, the internal structure of the &lt;code&gt;src/product&lt;/code&gt; module can be re-organized in any way, as long as the interface does not change, the rest of the application doesn't need to care.&lt;/p&gt;
&lt;p&gt;I've seen many clojure examples like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;`&lt;/code&gt;clj&lt;br&gt;
(ns my-project.catalog.catalog-related-module.get-catalog-page&lt;br&gt;
  (:require [my-project.product.product-related-module.foo :as foo]))&lt;br&gt;
&lt;code&gt;`&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;So I'm wondering if there's a way to add re-exporting files, so I could do this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;`&lt;/code&gt;clj&lt;br&gt;
(ns my-project.catalog.catalog-related-module.get-catalog-page&lt;br&gt;
  (:require [my-project.product :refer [foo]]))&lt;br&gt;
&lt;code&gt;`&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;In javascript I could achieve this by using &lt;code&gt;index.js&lt;/code&gt; files:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;`&lt;/code&gt;js&lt;br&gt;
// src/product/product-related-module/index.js&lt;br&gt;
export { foo } from './foo.js'&lt;/p&gt;
&lt;p&gt;// src/product/index.js&lt;br&gt;
export { foo } from './product-related-module/index.js'&lt;br&gt;
&lt;code&gt;`&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Ideally I could even restrict from requiring anything from a namespace inside the product-namepsace when accessing from outside.&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14315/define-namespace-interface-boundaries-like-with-index-files</guid>
<pubDate>Thu, 26 Dec 2024 09:26:55 +0000</pubDate>
</item>
</channel>
</rss>