code-reviews

Ben Sless 2020-12-04T12:33:02.076300Z

I have a question regarding naming conventions: I have functions which take a function as argument, (defn foo [f] ,,,), and I want to provide a macro which wraps a body as a function for this call, i.e.

(defmacro bar [& body] `(foo (fn* [] ~@body)))
I want to expose both foo and bar and give them names which are semantically close, i.e. foo-call, do-foo, foo, something like that. Any suggestions? I started with an asterisk suffix but it seems ugly in a public api.

2020-12-08T22:47:52.079200Z

Isn't this the same thing that future does? future is a macro that internally calls the func future-call, in core.clj

Ben Sless 2020-12-09T04:40:00.079400Z

It is, same for core.async/thread. They inspired some of the design

walterl 2020-12-04T15:18:53.076400Z

Metabase uses foo for the macro and do-foo for the function that does the heavy lifting.

Ben Sless 2020-12-04T16:00:21.076600Z

Thanks @clojurians-slack100, just to clarify my situation a bit, the functions in this case don't do code transformations (as in core.async/do-alt), but they do perform the work. Why do-foo for the function and not the macro? What do you think about foo-call for the function (as in core/future-call)?

2020-12-04T19:29:42.076800Z

“Asterisk suffix for the version that takes a function” seems to be a common convention when it’s expected that the macro version will be the usual invocation method, and the asterisk version rarely used directly

2020-12-04T19:30:05.077Z

I personally don’t mind the aesthetics FWIW

walterl 2020-12-04T19:32:31.077200Z

> Why do-foo for the function and not the macro? It's because foo is public interface, so it gets the "prettier" (more idiomatic) name. The do- prefix is just a convention. I don't know if it has other history (maybe it's a lisp thing?), but consistency is good 🙂

Ben Sless 2020-12-04T22:19:28.077400Z

I'm also trying to be consistent with core.async semantics. I'll elaborate a bit Currently, what I have is https://github.com/bsless/more.async/blob/master/src/main/clojure/clojure/more/async.clj#L24: a process which repeatedly invokes a function and puts its results on a channel. I also have the equivalent consumer process. I want to mimic core.async semantics of async! and blocking!! suffixes, and I also want to support a macro version which packs an expression into a function so my options are things like (function/macro) • produce!* / produce! • do-produce! / produce! • produce! / do-produce! I really can't figure out which is more idiomatic. I also want both macro and function version to be public. Naming things is hard

walterl 2020-12-04T22:34:34.077700Z

> Naming things is hard ☝️ This. If you want to make both function and macro public, I usually try and think about what would make sense when I read it being used. To that end, what about produce-with!/`produce!`?

walterl 2020-12-04T22:35:44.077900Z

And for public vars I'd avoid suffixes like *. Rather add a descriptive/distinguishing word.

Ben Sless 2020-12-04T22:43:59.078100Z

That's why I thought about do-produce for the macro version, because it takes a body, which is a very do-y kind of thing