Fork me on GitHub
#babashka
<
2021-06-25
>
onetom05:06:52

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?

onetom05:06:40

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

onetom05:06:53

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 "[email protected]"]

user=> shell/sh
#object[babashka.impl.clojure.java.shell$sh 0x11d24ea2 "[email protected]"]

borkdude07:06:06

> 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.

borkdude07:06:04

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.

onetom10:06:32

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 🙂

borkdude10:06:53

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

borkdude11:06:09

which is also written here: https://book.babashka.org/#style

👍 2
borkdude11:06:58

it's a fair criticism but not something we can change at this point

👍 2
borkdude21:06:00

Btw, pprint isn't aliased at all, I see now

pithyless09:06:26

> 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 @U086D6TBN - 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

👍 6
onetom09:06:55

thanks @U05476190, 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 🙂

Jakub Šťastný14:06:56

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.

borkdude14:06:40

I think @U01LR7M2B7A uses something like this, you can maybe watch one of his streams

borkdude14:06:00

or search his github profile to see if he has some public dotfiles

Jakub Šťastný15:06:25

Cheers @U04V15CAJ, I will check search on his GH then!

Jakub Šťastný15:06:36

Found the Emacs config https://gist.github.com/adam-james-v/7a61612ce0649afc78513f54b337d8c9, but it doesn't deal with babashka as far as I see.

borkdude15:06:25

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.

borkdude15:06:10

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

👍 2
hkjels16:06:20

you need ob_babashka. Just use ob_clojure as a starting-point

hkjels16:06:38

it’s not that much work

Jakub Šťastný17:06:42

@U04V15CAJ 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).

Jakub Šťastný17:06:11

@U0B1SDL67 yeah I think so. I already checked the code for other languages, looks pretty straighforward.

adam-james18:06:30

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:

adam-james18:06:15

It's a very basic modification of ob-clojurescript. Though, at the moment I have only tested a few basic evals.

adam-james23:06:40

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

hairfire20:06:31

Is there a clever way to create help from the ":doc" data in the ":tasks" map in a bb.edn file?

cldwalker20:06:36

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

2
Vishal Sachdev20:06:52

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

Vishal Sachdev20:06:28

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

borkdude21:06:19

@vishalsachdev199 in the REPL, some vars are automatically referred, like in the normal clojure REPL

borkdude21:06:43

In "expression" mode you can use clojure.pprint/pprint fully

Vishal Sachdev21:06:09

Thanks for the help

borkdude21:06:40

When writing scripts it's recommended to use require explicitly (you'll get better linting from clj-kondo for example)

Vishal Sachdev21:06:51

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.

borkdude21:06:48

clojure.pprint isn't aliased as pprint by default

borkdude21:06:35

there are some pre-defined aliases like json but it's not done for every available namespace in bb

hairfire21:06:51

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))}

hairfire21:06:27

Here's an example non-help task:

run-lein           {:doc  "run-lien: Executes 'lien run'"
                      :task (apply shell "lein" "run" *command-line-args*)}

borkdude21:06:19

@hairfire Any reason to not just use bb tasks for this? It does almost the same as your help task

hairfire21:06:10

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.

borkdude21:06:54

Just run it on the command line and you'll see what happens

hairfire21:06:12

bb tasks will be just fine. Anyway to alias it to "help", just because my users are more likely to try help

borkdude21:06:01

If you type bb --help you see the docs for it:

Tasks:

  tasks       Print list of available tasks.
(it prints it with the docstrings)

hairfire21:06:31

is "bb tasks" documented in http://book.babashka.org? I didn't see it while looking around for it.

borkdude21:06:34

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

hairfire21:06:06

Thanks for gracefully tolerating my ignorance :face_with_rolling_eyes:

borkdude21:06:26

oh no problem at all, I hope you had fun :)

😬 2
borkdude22:06:34

@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

borkdude22:06:48

e.g -helper-task ...