JuliaDebug / JuliaDebug/Cthulhu.jl

Allow user to overload printing behavior

Open
#535 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Julia
Stars
709
Forks
46
Avg merge
1d 13h
Merged PRs (30d)
2

Description

(x-ref https://discourse.julialang.org/t/proposed-alias-for-union-types/108205/142?u=milescranmer)

Julia’s type system is the best I’ve encountered in any language, but it can admittedly get a bit verbose at times. In particular things like optimizer options can make extensive use of type parameters and fill up multiple lines. Especially as some types stretch over the VSCode length limit in the Cthulhu labels and end up missing some information.

Therefore I was wondering if Cthulhu could permit the user to overload printing behavior for types in a Cthulhu printout, without necessarily overloading the printing behavior for all of Julia, like Float32 → F32, Tuple → Tu, etc, just to make the printouts less verbose.

For example:

import Cthulhu: type_string

## default defined in Cthulhu:
# type_string(t) = string(t)

# user aliases:
type_string(::Type{Float64}) = "F64"
type_string(::Type{Float32}) = "F32"

type_string(::Type{Missing}) = "?"

type_string(::Type{UInt8}) = "U8"

# Union{A,B} -> (A|B)
type_string(U::Union) = "(" * join(type_string.(union_to_tuple(U)), "|") * ")"
union_to_tuple(U::Union) = (union_to_tuple(U.a)..., union_to_tuple(U.b)...)
union_to_tuple(T::DataType) = (T,)

# Tuple{A,B} -> Tu{A,B}
type_string(::Type{T}) where {T<:Tuple} = "Tu{" * join(type_string.(T.parameters), ",") * "}"

# etc.

which you could have in your startup.jl. This would mean you get compact printouts like this:

julia> type_string(Tuple{Union{Float32,UInt8},Float64,Union{Float64,Missing},Missing})
"Tu{(F32|U8),F64,(?|F64),?}"

This is obviously a subjective choice to implement, but if it is simply something users can configure to their needs, it would be great!

This would be backwards compatible of course as it would simply expose an interface.

Cheers,
Miles

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Cthulhu's existing type-printing path and consider the proposed type_string entry point as the interface to customize. Done should allow users to define aliases or recursive formatting for types in Cthulhu printouts while preserving the default output when no customization is provided.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.