Skip to content

shybyte/exercises-in-programming-style-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exercises in Programming Style - Rust Version Build Status

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.

List of Exercises

Part 1 - Historical

Feel the pain of programming in 1970.

  • Good old times - Minimal memory and no identifiers
  • Go Forth - Working on a stack

Part 2 - Basic Styles

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

Part 3 - Function Composition

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

Part 4 - Objects and Object Interaction

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

Part 5 - Reflection and Metaprogramming

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

Part 6 - Adversity

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)

Part 7 - Data-Centric

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

Part 8 - Concurrency

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

Part 9 - Interactivity

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

Part 10 - Rusty

Do it in the Rusty Way.

  • Rusty - Idiomatic efficient Rust solution with complete error handling

Run one variant

  cargo run --bin 06-code-golf test-data/input/simple.txt

Run and test everything

  ./test.sh

License

MIT

Copyright

Copyright (c) 2017 Marco Stahl

About

Exercises in Programming Style - Rust Version

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published