diff --git a/README.md b/README.md index f44417cf..934820ce 100644 --- a/README.md +++ b/README.md @@ -351,7 +351,7 @@ The namespace `babashka.curl` is a tiny wrapper around curl. It's aliased as `curl` in the user namespace. See [babashka.curl](https://github.com/borkdude/babashka.curl). -## Running a file +## Running a script Scripts may be executed from a file using `-f` or `--file`: @@ -386,8 +386,6 @@ Using `bb` with a shebang also works: (println "Usage: ") (System/exit 1)) (write-html file (get-url url))) - -(System/exit 0) ``` ``` shellsession @@ -415,6 +413,42 @@ $ cat script.clj ("hello" "1" "2" "3") ``` +## Style + +A note on style. Babashka recommends the following: + +- Only use `*input*` and aliases without require in bash one-liners. + + Do this: + + ``` + $ ls | bb -i '(-> *input* first (str/includes? "m"))' + true + ``` + + But not this: + + script.clj: + ``` + (-> *input* first (str/includes? "m")) + ``` + + Rather do this: + + script.clj: + ``` + (ns script + (:require [clojure.java.io :as io] + [clojure.string :as str])) + (-> (io/reader *in*) line-seq first (str/includes? "m")) + ``` + +Some reasons for this: + +- Linters like clj-kondo work better with code that uses namespace forms, explicit requires, and known Clojure constructs +- Editor tooling works better with namespace forms (sorting requires, etc). +- Writing compatible code gives you the option to run the same script with `clojure` + ## [Running a REPL](doc/repl.md) Babashka offers a REPL, a socket REPL and an nREPL server. Look