Threadwell

Recent Notes

  • NOTimothyLottes

    Aug 25, 2026

    • archive
    • twitter
    • notimothylottes
  • cmuratori

    Aug 25, 2026

    • archive
    • twitter
    • cmuratori
  • Threads

    Aug 25, 2026

    • archive
Home

❯

Archive

❯

Threads

❯

nicbarkeragain

❯

An example of this - a classic way to construct a tree in code is with push / pop style calls.

An example of this - a classic way to construct a tree in code is with push / pop style calls.

Properties5
typearchive
sourcetwitter
date2026-08-05
tagsarchive, twitter, nicbarkeragain
descriptionAn example of this - a classic way to construct a tree in code is with push / pop style calls.

Aug 05, 20261 min read

  • archive
  • twitter
  • nicbarkeragain

Source

  • URL: https://x.com/nicbarkeragain/status/2084851804224004329
  • Author: Nic Barker (@nicbarkeragain)
  • Posted: 2026-08-05 03:59:39

Thread

1/ @nicbarkeragain

An example of this - a classic way to construct a tree in code is with push / pop style calls. Forgetting to call pop() or close() can be annoying to debug, and you can make this much easier just enforcing matching string tags on open / close. Also enforces readability:

Branches: 2026-08-05-lionkimbro10x-i-love-everything-about-this-and-i-agree-its-fine, 2026-08-05-hasen_95dx-this-particular-case-though-is-easily-solved-with, 2026-08-05-choco_dolphin7-1-got-into-the-habit-of-immediately-writing-free, 2026-08-05-borrowck_novel-thanks-a-lot-for-the-example, 2026-08-05-plasm_nl-thats-a-great-tip-i-always-used-comments-but-this, 2026-08-05-datgame-ah-matching-strings-just-like-xml, 2026-08-05-rep_movsd-or-you-could-use-c-with-raii-and-not-have-to-tie, 2026-08-05-eta9499-deferloop-is-super-useful-for-this, 2026-08-05-windless_mill-tangently-this-example-illustates-pretty-good-why, 2026-08-06-real_philogy-rusts-ownership-raii-makes-such-patterns-really

2/ @exacoustics

@nicbarkeragain

Stealing this idea

10 items under this folder.

  • Aug 06, 2026

    Rust's ownership + RAII makes such patterns really easy and nice to encode statically, no debug strings needed if the compiler guarantees you can't open another object at the same level if the previous one wasn't closed.

    • archive
    • twitter
    • nicbarkeragain
  • Aug 05, 2026

    @nicbarkeragain Thanks a lot for the example

    • archive
    • twitter
    • nicbarkeragain
  • Aug 05, 2026

    @nicbarkeragain 1.

    • archive
    • twitter
    • nicbarkeragain
  • Aug 05, 2026

    @nicbarkeragain Ah, matching strings, just like xml 🙃

    • archive
    • twitter
    • nicbarkeragain
  • Aug 05, 2026

    @nicbarkeragain DeferLoop is super useful for this

    • archive
    • twitter
    • nicbarkeragain
  • Aug 05, 2026

    @nicbarkeragain this particular case though is easily solved with `defer` or even `closures`

    • archive
    • twitter
    • nicbarkeragain
  • Aug 05, 2026

    I love everything about this.

    • archive
    • twitter
    • nicbarkeragain
  • Aug 05, 2026

    @nicbarkeragain That's a great tip.

    • archive
    • twitter
    • nicbarkeragain
  • Aug 05, 2026

    @nicbarkeragain Or you could use C++ with RAII and not have to tie yourself in knots

    • archive
    • twitter
    • nicbarkeragain
  • Aug 05, 2026

    @nicbarkeragain tangently, this example illustates pretty good why I like syntax with `end` keyword and optional name of closee better than just `{ ...

    • archive
    • twitter
    • nicbarkeragain

Created with Quartz v5.0.0 © 2026

  • GitHub