A collection of single responsibility code samples in a variety of programming languages for comparison, with an emphasis on functional programming. What I call fullstack fragments.
The supported programming languages are:
Every code sample is mirrored in each language, and each one implements these basic code quality tasks:
Every sample in every language can be run both locally and via Docker. See Running the code below.
fragments/env_vars
fragments/sql
fragments/redis_db
Each programming language supports local environment setup, or you can build and run with Docker instead.
Some fragments expect services to be running on particular ports, such as Redis. The easiest way to provision your local environment with the required services is through the provided Docker Compose setup. You'll need Docker installed and running.
Spin up the services before running any commands:
docker-compose up
All the node.js code is written in TypeScript. I'm using tsx
to transpile and
execute the code.
nvm
nvm install 22
if you don't already have this versionnvm use 22
npm install
at root of reponpm run fragments
npm run fragment -- fragments/env_vars/env_vars_utils.ts
npm run test
npm run lint
npm run tsc
npm run format:write
npm run format:check
docker build --force-rm -f docker.node.Dockerfile -t ff_node .
docker run --rm ff_node
docker run --rm ff_node fragments/env_vars/env_vars_utils.ts
docker run --rm --entrypoint npm ff_node run test
docker run --rm --entrypoint npm ff_node run lint
docker run --rm --entrypoint npm ff_node run tsc
docker run --rm --entrypoint npm ff_node run format:check
pyenv
pyenv install 3.12.4
if you don't already have this versionpython3 --version
prints the above versionpython3 -m venv .venv
source .venv/bin/activate
which python3
.pth
file in the virtual environment to set the repo in the Python path:
touch .venv/lib/python3.12/site-packages/ff.pth
pwd > .venv/lib/python3.12/site-packages/ff.pth
python3 -m pip install -r requirements.txt
python3 -m pip list
deactivate
to exit the virtual environment at any timepython3 ./fragments/main.py
python3 ./fragments/env_vars/env_vars_utils.py
python3 -m unittest -v
python3 -m mypy --config-file mypy.ini
python3 -m pylint ./fragments --rcfile ./pylintrc
python3 -m black ./fragments
python3 -m black ./fragments --check
docker build --force-rm -f docker.python.Dockerfile -t ff_python .
docker run --rm ff_python
docker run --rm --entrypoint python3 ff_python ./fragments/env_vars/env_vars_utils.py
docker run --rm --entrypoint python3 ff_python -m unittest -v
docker run --rm --entrypoint python3 ff_python -m mypy --config-file mypy.ini
docker run --rm --entrypoint python3 ff_python -m pylint ./fragments --rcfile ./pylintrc
docker run --rm --entrypoint python3 ff_python -m black ./fragments
docker run --rm --entrypoint python3 ff_python -m black ./fragments --check
rustup toolchain install 1.79.0
if you don't already have this version installedrustc --version
to confirm the above version is being usedclippy
for enhanced linting: rustup component add clippy
rustfmt
for formatting: rustup component add rustfmt
cargo run --bin fragments
cargo test
cargo build --release --bin fragments
cargo clippy -- -D warnings
cargo fmt -v
cargo fmt --check -v
docker build --force-rm -f docker.rust.Dockerfile -t ff_rust .
docker run --rm ff_rust
docker run --rm --entrypoint cargo ff_rust test
docker run --rm --entrypoint cargo ff_rust build --release --bin fragments
docker run --rm --entrypoint cargo ff_rust clippy -- -D warnings
docker run --rm --entrypoint cargo ff_rust fmt -v
docker run --rm --entrypoint cargo ff_rust fmt -v --check
goenv install 1.23.1
if you don't already have this version installedgoenv version
to confirm the above version is being usedgolangci-lint
for lintingcd ./fragments && goenv exec go mod tidy
goenv exec go run fragments/main.go
goenv exec go test ./fragments/...
goenv exec go build -o .bin/go_ff ./fragments/main.go
golangci-lint run ./fragments/...
goenv exec gofmt -w ./fragments
test -z $(goenv exec gofmt -l ./fragments)
docker build --force-rm -f docker.go.Dockerfile -t ff_go .
docker run --rm ff_go
docker run --rm --entrypoint go ff_go test ./fragments/...
docker run --rm --entrypoint go ff_go build -o .bin/go_ff ./fragments/main.go
docker run --rm --entrypoint golangci-lint ff_go run -v ./fragments/...
docker run --rm --entrypoint gofmt ff_go -w ./fragments
docker run --rm --entrypoint test ff_go -z $(gofmt -l ./fragments)