Fork me on GitHub
#babashka
<
2023-05-05
>
borkdude09:05:43

For a talk at bb conf, are there any topics (related to bb, the wider ecosystem, clojure, software dev in general, the answer to the universe life and everything) you'd like me to address? I have some ideas myself, but I'd like to hear if you have any. 🧵

2
borkdude09:05:50

Feel free to respond here

elken09:05:34

I/we tend to use bb as a better Makefile so something around that would be good 🙂

👍 6
pesterhazy10:05:15

What are the design ideas behind bb? What compass do you use to make decisions?

teodorlu10:05:35

I’d like to hear your thoughts around how to contribute productively to open source. I feel like I’ve learned a lot contributing to Neil about the social aspects, and how to structure a “piece of work” as PRs. Plus “let’s not make things complicated if we don’t have to”.

teodorlu10:05:07

I’m also interested in whether there’s a system behind all your open source projects. Do you loose track? No? Is that just plain old experience? Or do you use “I want to make a small library” as the “first meaningful thing”? I get the impression that cherry and clj2el just started as simple things, and you figured “we can open source this”. What level of “readyness” should a thing have before one invites others to play? Is there a difference between “I want to help make this” and “I want to use this”?

borkdude10:05:27

good questions :)

eval-on-point12:05:04

The inclusion of a library in bb (think httpkit vs clj-http) may become a consideration regarding the lib's usage outside of bb. In other words, our project favors httpkit and has moved off of clj-http just for uniformity's sake. Any positive or negative thoughts on babashka serving as a sort of "tastemaker" in this way?

mmer14:05:18

I think bb is possibly the lowest entry set up for getting into clojure. I know you have covered this before, but starting from scratch to running program. One aspect that slightly confuses me about bb is the use of namespaces. I can run a 'script' without any name space but there are times when a namespace helps. Project setup s different if you use namespaces. Other aspect would be when you use bb in a bash script and when you use shell from within a bb script. Recently I tried to convert a bash script to bb and emulating things like grep and sed and awk where not that straight forward - thoughts. thanks.

borkdude14:05:35

@U4C3ZU6KX Thanks. I think what may confuse some people is that you need a classpath for bb to find namespaces on. By default the classpath is empty. But if you set it to . you can just use namespaced scripts in the current working directory. We can talk in another thread about this if you want.

judepayne06:05:01

I'd stress how easy it is to begin contributing to this language and it's ecosystem, and how welcome you're made to feel when you do it! In contrast most other languages out there

judepayne06:05:14

'Scaling borkdude' (to add on to teodorlu's points) would be another interesting one

2
❤️ 2
judepayne06:05:50

If there's any meaningful update on Java on Truffle at this point and how that can broaden bb's use cases, would be interesting.. but I had a look at that project recently and it's hard to see where it's at

judepayne06:05:24

Finally on use cases, bb's stating use case is 'scripting' but I will often use it while developing a clojure/ mixed library. The instant repl startup and overall feeling on greater snappiness at the repl is compelling. So 'developing' is the key (secret) use case for me

👍 2
judepayne06:05:44

'PRs welcome!' is a good summary of my first two points, and needs to be on the next bb t-shirt!

pesterhazy10:05:18

I'm having so much fun writing babashka scripts • it's so FAST! (50ms end-to-end test turnaround time) • TDD for more complex scripts is not just possible but FUN • Clojure is the data-wrangling language PER EXCELLENCE, ideally suited for scripting • babashka.process and babashka.fs are SO MUCH BETTER than what bash offers

❤️ 15
9
gratitude 4
🎯 10
pesterhazy10:05:12

So many good decisions that went into making babashka such a joy to work with - well done @U04V15CAJ!

4
babashka 2
teodorlu10:05:27

on babashka.process and babashka.fs. First I thought Bash had the upper hand, processes and files are exactly what bash is made for. Now I come to prefer these two Clojure libraries with some Clojure glue / data transformation code.

jackrusher11:05:00

@U3X7174KS The question of why bash is so widely used for scripting recently came up on the Future of Coding slack, and I think the answer might be helpful here: > There were better shells for writing scripts before bash , but they were generally regarded as less pleasant to use interactively (completions, forward/backward search, &c). Because most people spend more time composing little one-liners at the command line than writing scripts — an activity that favors those interactive features — bash became increasingly popular. Once people were used to using bash syntax for one-liners, they preferred to just keep using it in small scripts, despite its many shortcomings as a programming language. Ubiquity was ultimately driven by Linux making it the default shell, which had to do with GNU/licensing preferences.

👍 4
borkdude11:05:04

One of the non-goals (explicitly mentioned from the start in the README) of bb is to replace existing shells like bash. It wants to replace the scripting language, not the shell.

👍 2
💯 4
teodorlu11:05:15

Aaaah, that makes sense. Bash is indeed quite pleasant to use interactively. Thanks! I might have to join that slack.

borkdude11:05:39

The "I don't like the language but it's here anyway, so let's use it for more things" sounds a bit like JavaScript's history as well ;)

❤️ 4
😔 4
😂 2
pesterhazy11:05:26

Bash is easy ("ready-at-hand") and I don't blame people for liking it. But also, with babashka we can code circles around bash people – like 2x, 10x faster, plus it takes longer to hit the complexity ceiling where you don't understand anything anymore

borkdude11:05:31

I still like bash, but you have to know when to stop

borkdude11:05:01

like, when hitting a (nested) if / else, I usually give up ;)

2
borkdude11:05:47

"should this be -z or -eq ..." those kinds of things I only remember by looking at past scripts..

pesterhazy11:05:14

I start all scripts with babashka now, even if bash is more familiar With bb, when I encounter a problem, I learn and understand; the next time I'll know what to do. In bash, on the other hand, I don't learn anything other than workarounds.

8
borkdude11:05:55

I think the places where I mostly still touch bash is in clj-kondos and babashka installer scripts

👍 2
borkdude11:05:21

one other benefit that bb gives me in other projects is that those scripts run in all platforms including Windows

borkdude11:05:54

I think you could get bash to run on Windows (cygwin or so) but there's always some thing that's different

2
👍 2
lread14:05:18

And even where bash runs on multi-platforms there can be confusing differences and incompatibilities in tooling. The fact that babashka can also remove these un-fun mysteries from scripting is another awesomeness.

Noah Bogart14:05:06

I posted a question in the github discussions about https://github.com/babashka/babashka/discussions/1554. If anyone has experience with this, I'd love to hear about it.

borkdude14:05:46

You mention stack traces in that discussion, but note that stack traces in bb due to interpretation work quite different from JVM Clojure. Have you tested whether your bb workaround works as desired?

Noah Bogart14:05:06

it works perfectly fine, just hoping to get back some performance

borkdude14:05:58

Well yeah in JVM Clojure you can't create custom exception types, so you have to write .java. This is not possible in bb. So I think there aren't many alternatives to your approach

👍 2
Noah Bogart14:05:00

farolero's main building block is the Signal, which is used extensively as a means of early exiting and control flow

borkdude14:05:54

What are you going to use farolero for, splint? Note that such libs may have impact on performance in bb as well

borkdude14:05:40

But if you don't care much about it and the script/project works quite fast, then it's all good. Just something to be aware of.

Noah Bogart14:05:54

I thought I'd see how it works as I've been struggling/annoyed with error handling in Splint (as seen in your recent issue (that I need to publish the new release for oops))

borkdude14:05:38

Using more dependencies is also going to affect startup time. Keeping things more "vanilla" will work best for bb. In terms of errors that probably means: 1 Don't throw, but return exception values 2 Or embrace ex-data and just work with that

borkdude14:05:13

but at the end of the day it's just a matter of trying out

👍 2
Noah Bogart14:05:45

Yeah, i've played with farolero before but not for anything meaningful and this is a somewhat fresh codebase so using it is pretty easy

borkdude14:05:39

there's also slingshot which is quite popular

anovick14:05:21

Finally I have a scripting problem, and a setup where I can develop babashka code. Getting my hands dirty with some data processing Some script that does sequential text file reads -> maps numbers from these reads into a vector -> write that vector in some specific text file format... that kinda thing 🙂

🎉 2
anovick15:05:09

When creating a new project for Babashka using Cursive, which project type should I choose?

grzm14:05:24

@ericdallo was sporting a very snazzy babashka t-shirt at the conj. Are those generally available?

grzm14:05:58

Done and done!

grzm14:05:16

wonders if this should be his first tattoo

borkdude14:05:58

I take no responsibility for that :)

😂 4
borkdude14:05:11

Interesting observation here: https://clojurians.slack.com/archives/CLX41ASCS/p1683298055351499?thread_ts=1683280663.603409&amp;cid=CLX41ASCS Some people will try to use namespaces and will just try to put the files in the current working directory (or src?) I think and then wonder why it doesn't work. The reason is that bb's classpath is empty by default. Should it default to .:src ? The reason I've not done so is to avoid conflicts with JVM Clojure, but perhaps that's not a good reason. Reply in 🧵 if you have thoughts.

2
mkvlr15:05:16

does clojure not default to „src“ only? Same default would be least surprising to me

seancorfield15:05:59

clojure -T defaults to "." but other clojure invocations default to "src" -- the latter is based on the default :paths in the "root" deps.edn (inside tools.deps).

borkdude15:05:43

Yes, clojure defaults to src but I think most newcomers aren't even familiar with that and just expects scripts to work on the top level

borkdude15:05:56

planck for example has .:src as the default classpath maybe for this reason

borkdude15:05:16

or we could improve the error message when a namespace could not be found and the classpath is empty ;)

seancorfield15:05:27

I think, for a scripting tool, I'd expect "." TBH. I think there's a potential for confusion if it was ".:src"...?

borkdude15:05:07

yeah, I think . would be a good choice, if the classpath is not specified otherwise.

borkdude15:05:02

but some people will read clojure tutorials and would expect src to work by default like with deps.edn

borkdude15:05:25

for #C029PTWD3HR I went with .:src from the start

seancorfield15:05:33

Hmm, and another data point would be Joyride which has its scripts in scripts but pulls libraries from src by default... :thinking_face:

borkdude09:05:53

I think for someone like this, making their first steps with babashka: https://github.com/somecho/utility-scripts I think they would indeed be trying to require scripts from the local dir if they haven't read any further docs yet

borkdude09:05:27

So I'll start adding the local dir as the "fallback" classpath in one of the next releases

borkdude09:05:24

Hmm, one downside of adding . to the paths is that when creating an uberjar, it zips up the whole directory

Joshua Suskalo18:05:20

I'd like to announce that https://github.com/IGJoshua/farolero v1.5.0 is out now, and adds support for using the library from Babashka! 🎉

🎉 7
babashka 4
borkdude18:05:04

Great! :) Some feedback on the README: it would help me get going faster if there was a

(require '[farolero.core :refer [handler-case signal]])
above the example

Joshua Suskalo18:05:51

Good point! I'll get that in there.

Joshua Suskalo18:05:36

While you're here, I was very explicit about using :farolero.core/blah throughout most of the readme, and only use ::far/blah later. Should I move to just using the alias as a part of adding that require with an :as far in it? Would that still be clear enough about them all being namespaced keywords in the farolero namespace?

borkdude18:05:15

yeah, I think alias is good. A rule I keep more or less for my own readme is that you should be able to copy paste the code in a REPL

👍 2
Joshua Suskalo20:05:53

@U04V15CAJ thanks to your suggestion I just went through and updated all the references to be easy to work with from a repl. Thanks a lot for the feedback!

👍 4
thompen20:05:54

How can I get back all of: STDERR, STDIN, exit code, when executing a process with the babashka.process functions?

borkdude20:05:15

@U02NJTR0718 stdout/err as string?

borkdude20:05:54

(process/sh "ls -la")
would be the best default here

borkdude20:05:39

with shell:

(shell {:out :string :err :string :continue true} "ls -la")
:continue true means: don't throw on exit non-zero

borkdude20:05:56

with process:

@(process {:out :string :err :string} "ls -la")

borkdude20:05:25

they all make use of the same underlying code, but have different defaults. sh is the closest to what you asked

thompen20:05:40

Thanks borkdude! Amazing to get a response from the source so fast :) "$" seems to work the same as well.

borkdude20:05:05

True:

@($ {:out :string :err :string} ls -la)