Skip to content

Conditional Printing #9

@nadavgover

Description

@nadavgover

Hi! I suggest a new idea, conditional printing.

Current state

(mate/dreduce + [1 3 5 7 9]) (as an example) will print all the stages to stdout.

Problem

  1. Printing is time consuming
  2. The developer writes the code especially for debugging
  3. Need to change the code for production in order not to have the time consuming printing

Suggested Solution

What if the developer will not have to change the production code and in the same time will not suffer from printing? Sounds good to be true? Sounds like conditional printing!
The whole idea is that during runtime we can decide whether or not to print. I suggest 3 methods to do that:

  1. Printing Levels:
    Every macro can take an optional printing level ∈ #{0 1 2 3 4 5}. This level must be >= mate/*min-level* for printing to occur.
    For example:
(mate/dreduce {:level 3} + [1 3 5 7 9])  ; Only activates printing when (>= 3 *min-level*) 

A developer can setmate/min-level by mate/set-min-level!

  1. Namaspace Filtering:
    Prints can be elided or filtered by the namespace in which they occur.
    For example, a developer can call
(mate\set-ns-patterns! {:whitelist #{"foo.bar.*"} :blacklist #{"bar.foo.*"}})
  1. Arbitrary Runtime Conditions:
    Each macro supports an optional arbitrary test expression:
(mate/dreduce {:when my-cond?} + [1 3 5 7 9])  ; Only activates printing when `my-cond?` is truthy

That's it, thanks :)
This idea and suggested solution was inspired by tufte profiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions