• Stars
    star
    591
  • Rank 75,679 (Top 2 %)
  • Language
    Clojure
  • License
    Other
  • Created over 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CircleCI Clojars Project

spectrum

A library for doing static analysis of Clojure code, catching clojure.spec conform errors at compile time.

Wait what?

It's like core.typed, but it relies on clojure.spec annotations.

So it's an optional static type system?

Kind-of. It finds errors at compile time, and predicates kind of look like types. So sure.

Proving contracts ahead of time

Current Status

Developer Preview, not yet ready for any kind of use.

Current development is working towards making spectrum self-check.

Goals

  • usable
  • pragmatic
  • readable implementation
  • fast
  • configurable strictness levels
  • incremental checking

Non-goals

  • perfection
  • correctness
  • requiring 100% spec coverage.

In particular, spectrum aims to be fast and usable, and catching bugs. It aims to have low false positives, at the expense of potentially not catching 100% of type errors.

A tool that catches 80% of bugs that you use every day is better than a 100% tool that you don't use. Spectrum will converge on 100% correct, but won't guarantee correctness for a while.

Usage

Still under active development, so this is incomplete.

Use clojure.spec as normal. Then, at the repl:

(require '[spectrum.flow :as f])
(require '[spectrum.types :as t])

(f/infer-var #'foo)

There is also

(f/infer-form '(foo 3))

which is useful when you want to debug the signature of a form.

infer-form can optionally take a map of keywordized variables to types

(f/infer-form '(string? x) {:x #'string?})
#Value[true]

(f/infer-form '(string? x) {:x (t/value-t 3)})
#Value[false]

Limitations

  • It's still very early.

Justification

  • because I could
  • working example of types = proofs = predicates
  • Some properties of a program are easier to prove at runtime. Some at compile-time
  • this is extra checking on top of spec, not a replacement for it
  • to get HN to shut up about how adding a static type system to a dynamic language is impossible
  • why not just use spec by itself?
  • instrument doesn't check return values
  • check works best on pure functions with good generators.
  • Not all clojure code is pure
  • Not always easy to write a good generator for all functions (hello, any fn that takes a DB connection)
  • Not always easy to write a generator w/ 100% coverage
  • you can't spec non-defn functions
  • you can't spec higher order functions
  • generative testing with side-effects doesn't work well
  • generative testing gives false negatives on rare codepaths
  • static typing guarantees all codepaths are checked
  • spec doesn't deal with non-fn vars at all (binding, alter-var-root, set!, etc)
  • generative testing can be slow

Plan

Spectrum is still very early, and not ready for production use. Current development is focused on making spectrum self-check.

License

Copyright © 2019 Allen Rohner

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported

More Repositories

1

scriptjure

a Clojure library for generating javascript
Clojure
187
star
2

lein-daemon

A leiningen plugin for daemonizing a clojure process
Clojure
97
star
3

foam

Server Side Rendering for Om
Clojure
56
star
4

clj-wallhack

A clojure library for bypassing java protected fields
Clojure
45
star
5

lein-test-out

A leiningen plugin for running tests with junit XML / TAP output
Clojure
17
star
6

datomic-compound-index

A library for compound indices in Datomic
Clojure
17
star
7

om-html

hiccup for Om.Next
Clojure
15
star
8

find-aot-deps

A Clojure library to identify .jars containing transitive AOT dependencies
Clojure
12
star
9

lein-docker

Clojure
9
star
10

clj-blocks

A high level web framework that eliminates boilerplate
Clojure
7
star
11

clojure-contrib

User contributed libraries and examples for the Clojure programming language.
C#
5
star
12

wait-for8

Port wait-for to java-time
Clojure
4
star
13

lein-beandock

Clojure
3
star
14

sandbar

Web application libraries designed to be used with Compojure and Ring
Clojure
3
star
15

clj-kube

Clojure
3
star
16

pallet-rvm

A pallet crate for RVM
Clojure
2
star
17

arohner-utils

Clojure
2
star
18

clj-url

A library for parsing and emitting URLs
Clojure
2
star
19

lein-crate

Pallet crate for installing and using leiningen
Clojure
1
star
20

clj-table

a SQL ORM
Clojure
1
star
21

unbean

A simple library for creating java classes from bean maps
Clojure
1
star
22

defpage

Yet Another Clojure Web Library
Clojure
1
star
23

prxml

clojure contrib prxml as a standalone
Clojure
1
star
24

clj-ahttp

async + NIO http client
Clojure
1
star
25

sparrow

Deployment framework and scripts for Kubernetes
1
star
26

clj-r53

A Clojure library for Amazon's route 53 DNS service
Clojure
1
star