Skip to content

Design Proposal: Debug expression #1181

@sargunv

Description

@sargunv

Design Proposal: Debug expression

Motivation

When writing complex expressions, I sometimes have a logic bug and need to debug my expression. Most programming languages have some sort of "print statement debugging" trivially available to debug things even without a dedicated debugger tool. The expression system has no feature available, other than assigning some value to a SymbolLayer's text field to display it on the map.

Proposed Change

A new expression, perhaps called println or debug-log or something, that takes one or two parameters. When it's evaluated, it simply logs to stdout (native) or console (browser) whatever value it received on the first parameter, and returns that same value. If the second parameter was provided, it's a string label for the log line.

This way, the style writer can wrap any portion of an expression with println to log the output of that expression, or wrap a large expression with multiple printlns with different labels to really understand what might be going on.

It's not really intended to be used in production styles; just while developing a style.

Signature: ["println" value label?] -> value

API Modifications

^

Migration Plan and Compatibility

Nothing to migrate; fully backwards compatible.

Rejected Alternatives

  • As described above but name it log: would be confusing with math expressions log10 and log2.
  • No new expression; just continue using SymbolLayer text as before to get some debug output. This is unwieldy, especially if I want to log multiple values.

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