Comprehensive collection of well-known, and not so well-known, programming styles using a simple computational task, term frequency. This is the Rust Version. For the original python version and the companion book see https://github.com/crista/exercises-in-programming-style.
Feel the pain of programming in 1970.
- Good old times - Minimal memory and no identifiers
- Go Forth - Working on a stack
It happens every day. You have seen it already.
- Monolithic - One big program with no named abstractions and no clever library usage
- Cookbook - Procedural code with global state
- Pipeline - (Impure) Nested Functions
- Code Golf - Short code by clever std library usage
Combine functions in interesting ways.
- Infinite Mirror - Recursively, call yourself.
- Kick Forward - Callback style like in good old javascript
- The One - Use a kind of a Monad to create a pipeline, Functional composition
Stateful encapsulated things talk with other encapsulated stateful things.
- Things - Object-oriented
- Letterbox - Communication by untyped messages between objects
- Closed Maps - An Object is just a Map of functions
- Abstract Things - Objects implement Interfaces (Traits)
- Hollywood - Objects need to register at a fancy framework, which calls the objects
- Bulletin Board - Objects communicate via an Eventbus
When code knows about itself and hacks itself.
- Introspective - Code know about itself
- Reflective - Code can modify itself
- Aspects - Add general aspects like logging to existing code, without modifying the source code
- Plugins - Load external code without recompiling
How to prevent errors or deal with it.
- Constructivist - Check Arguments. If something goes wrong, use fallbacks and defaults
- Tantrum - Check Arguments. Handle problems when the occur by (logging and) forwarding the error to the caller
- Passive Aggressive - Check Arguments. Forward problems to the caller as default (Exceptions)
- Declared Intentions - Declare and enforce types
- Quarantine - Handle IO differently (Kind of IO monad)
It's about relations between data.
- Persistent Table - Put data in a (relational) database and query it
- Spreadsheet - Like dependent cells in a excel sheet
- Lazy Rivers - Streams of data instead of loading everything into memory at once
Doing work in parallel.
- Actors - Like Letterbox but things have independent threads of execution
- Dataspaces - Concurrent units read/store data in synchronized common data spaces
- Map Reduce - Divide data in blocks, map over it (parallelized) und reduce it to result
- Double Map Reduce - Like Map Reduce, but result of first map step is regrouped for a second parallelized map step which makes reduce trivial or unnecessary
Interacting with an user or client.
- Trinity - The famous MVC = Model-View-Controller Pattern
- Restful - Client accesses resources on server by using uniform resource identifiers
Do it in the Rusty Way.
- Rusty - Idiomatic efficient Rust solution with complete error handling
cargo run --bin 06-code-golf test-data/input/simple.txt
./test.sh
MIT
Copyright (c) 2017 Marco Stahl