Skip to content

ER: add abs/0; deprecate or discourage NUMBER | length #2672

@pkoppstein

Description

@pkoppstein

Most programming languages have an abs or similarly named function for convenient computation of the absolute value of a number. In its stead, jq has length, which
for many people is at best surprising. It is also noteworthy that this oddity was
not documented in jq 1.6 documentation until a recent commit (dd5ce98 on 2023-06-21).

Since NUMBER | length has been around for a while, and since it has been documented,
I am not proposing that it be done away with, only that the recent above-mentioned update be further updated by deprecating or discouraging it. As @nicowilliams wrote: "Too much polymorphism in a dynamically typed language is a mistake."

In the context of jq, this is surely the pre-eminent example. AFAIK no other programming language uses the word length for absolute value, and even if that's not the case, abs more clearly indicates intention.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions