I've just noticed that the namespace alias recommendations in
https://github.com/bbatsov/clojure-style-guide#use-idiomatic-namespace-aliases
are inconsistent with babashka's choices:
https://book.babashka.org/#built-in-namespaces
for example pp
is pprint
in bb, which would result in pprint/pprint
(which is a bit unnecessarily long)
and sh
is shell
in bb, which results in shell/sh
. same issue; unnecessarily long for such a core operation. the other convention leads to sh/sh
though, which is short, but weird because of the repetition.
i wonder how has this divergence happened?
were there any discussions anywhere about these choices with @bozhidar?
would it be possible still to achieve a higher degree of consistency, now that babashka is already pretty mature?
would it make sense to amend the clojure style guide somehow?
> were there any discussions anywhere about these choices withΒ @bozhidar? I don't think we have to discuss all of our choices with bozhidar, that would take the poor man his entire week. The choices of aliases here are intented to be used on the command line and I like them to be more explicit for this reason, also not to conflict with shorter ones if you are introducing them yourself.
Initially babashka was used as a command line tool only (for a few weeks probably). Later on scripts were introduced. If this was there from the start, I perhaps woudln't have introduced built-in aliases at all.
thanks for the background! i was just asking, because this kind of differences cause tension within teams, where certain members are trying to look for some authoritative source for answers (usually outside of the team). now they can find even 2 conventions π currently we only have 1 file, which runs under both clojure and babashka, so it's not a big issue yet. im starting to realize that i might have OCD and that's why such things bug me π
when creating scripts it might be better to create your own namespace so you can decide on your own aliases and not rely on the user
namespace so much
which is also written here: https://book.babashka.org/#style
it's a fair criticism but not something we can change at this point
Btw, pprint
isn't aliased at all, I see now
> i was just asking, because this kind of differences cause tension within teams, where certain members are trying to look for some authoritative source for answers (usually outside of the team). now they can find even 2 conventions Slightly OT, but just as a datapoint @onetom - we internally use Nikita's "long namespace convention" in our team (and his other Readable Clojure recommendations) even though they deviate from the linked Clojure Style Guide. The longer (and consistent and codebase unique) namespace is something I have particularly learned to appreciate when reading code. Just wanted to point out that there may already be more than one source of convention. :) https://tonsky.me/blog/readable-clojure/#use-long-namespace-aliases
thanks @pithyless, i was not aware of this article. I watched this presentation from tonsky, where he talks about related things: https://youtu.be/l1b7Da2DnPo and tried his alabaster theme too π
i don't have any good ideas in this regard, but i've just seen recently that some another project is following babashka's conventions. https://youtu.be/-MC0P4rj3e8?t=1002
it's a question of convenience mostly of course, since it's possible to have 2 aliases to the same namespace:
user=> (require '[clojure.java.shell :as sh])
nil
user=> sh/sh
#object[babashka.impl.clojure.java.shell$sh 0x11d24ea2 "babashka.impl.clojure.java.shell$sh@11d24ea2"]
user=> shell/sh
#object[babashka.impl.clojure.java.shell$sh 0x11d24ea2 "babashka.impl.clojure.java.shell$sh@11d24ea2"]
Anyone running babashka from Emacs Orgmode? I was trying to find some ob-babashka
, but I haven't found one.
What do I want: to be able to use #+BEGIN_SRC babashka
, rather than #+BEGIN_SRC clojure
. It would simply use CJ syntax, but would work with the bb
executable, rather than with clojure
. The use-case is direct code execution (`C-c C-c`) from literate programming documents, rather than tangling.
Has anyone done it already? If not, I'll probably tweak one of the existing packages, like ob-clojure.el
.
I think @adam.james uses something like this, you can maybe watch one of his streams
or search his github profile to see if he has some public dotfiles
Cheers @borkdude, I will check search on his GH then!
Found the Emacs config https://gist.github.com/adam-james-v/7a61612ce0649afc78513f54b337d8c9, but it doesn't deal with babashka as far as I see.
I'm not sure if he does bb specific stuff but he does use literate programming in org mode and clojure / babashka. He shows this on his stream. You could try to approach him on Twitter for more info.
I think he's just connected to a babashka nREPL server and from that perspective it doesn't matter which version of clojure you use
you need ob_babashka
. Just use ob_clojure
as a starting-point
itβs not that much work
@borkdude yeah I'd guess that's what he's probably doing. Still, given the nature of babashka, I'm more interested in running one-off things, glue code, not really something that I'd bother with REPL for (unlike in a larger project of course).
@hkjels yeah I think so. I already checked the code for other languages, looks pretty straighforward.
Haha, everyone called my shots π I don't often do code eval inline and basically send s-exprs to the REPL. but, I did try this just now:
https://gist.github.com/adam-james-v/f4d2b75a70b095d14a351a1eff96b4b0
It's a very basic modification of ob-clojurescript. Though, at the moment I have only tested a few basic evals.
Awesome, thaks @adam.james!
Is there a clever way to create help from the ":doc" data in the ":tasks" map in a bb.edn file?
Hi, hope this is the right place to ask.. but I can't seem to access pprint
in expression mode, but I can access it when using the repl. Like here -> https://asciinema.org/a/422396
I just installed babashka, so I'm not sure if I'm missing some setup? I'm using arch linux and installed the official package
I create a separate :usage key and then use that to check required arguments are given for a task - https://github.com/cldwalker/bb-clis/blob/9ba19aa9beee9c85ed1ac2eb98e24cad992afc9a/bb.edn#L9-L23
@vishalsachdev199 in the REPL, some vars are automatically referred, like in the normal clojure REPL
In "expression" mode you can use clojure.pprint/pprint
fully
Ah... got it.
Thanks for the help
When writing scripts it's recommended to use require
explicitly (you'll get better linting from clj-kondo for example)
Yeah, the namespace and function having the same name tripped me over. clojure.pprint
is available as pprint
so I should've used pprint/pprint
in the expression mode, but I kinda missed the namespace part. Funny because I was using json/parse-string
fine in the same expression.
clojure.pprint
isn't aliased as pprint
by default
there are some pre-defined aliases like json
but it's not done for every available namespace in bb
Here's what I came up with for a babashka "help" task:
help {:task (let [docs (->> (slurp "bb.edn")
edn/read-string
:tasks
vals
(filter map?)
(map :doc)
(filter identity))]
(doseq [doc docs]
(println (str "\n" doc)))
(println))}
Here's an example non-help task:
run-lein {:doc "run-lien: Executes 'lien run'"
:task (apply shell "lein" "run" *command-line-args*)}
@hairfire Any reason to not just use bb tasks
for this? It does almost the same as your help task
I'll give it a try. Can you point me to the docs for "bb tasks"? I looked around, but did not run across this.
Just run it on the command line and you'll see what happens
bb tasks will be just fine. Anyway to alias it to "help", just because my users are more likely to try help
If you type bb --help
you see the docs for it:
Tasks:
tasks Print list of available tasks.
(it prints it with the docstrings)is "bb tasks" documented in http://book.babashka.org? I didn't see it while looking around for it.
aliasing it as help will override bb's own help :) -- although you can always get to the built-in options using double dashes as well
yes, it's documented here: https://book.babashka.org/#_discoverability
Thanks for gracefully tolerating my ignorance :face_with_rolling_eyes:
oh no problem at all, I hope you had fun :)
@hairfire if you want to disable some tasks showing up in the bb tasks
output, you can make a task "private" by starting the name with a dash
e.g -helper-task ...
Cool!
Last ping here. I have updated the gist to properly provide 'babashka-mode'. It is just a derived mode using clojure-mode as the base. This is necessary to get font-locking in babashka blocks. Font locking is syntax highlighting and indentation, in case you didn't know (I didn't know myself until I looked it up). edit: adding link https://gist.github.com/adam-james-v/f4d2b75a70b095d14a351a1eff96b4b0