Unofficial Hacker News client - receive Push Notifications on replies.

Show HN: A 300k-line Zig desktop environment with its own compositor,GUI toolkit (opens external site)

65 points by oxydizer 1 day ago | github.com | 29 comments on HN | Vote on HN (opens Hacker News)

View full thread · View on Hacker News

Comment thread (3)

  1. It creates an array of non-localized labels on line 20. Most of these labels are single utf-8 characters, with one exception. Then, starting on line 134, there's a (nested! we'll get back to that) switch statement that maps the indexes of those labels to actions. This is completely unreviewable -- to confirm that item 19 has a label matching the action for equals requires counting them. Then the nested switch... passes things along to yet another function (why?) with stringly-typed enum actions, but at the end gets bored and just... decodes the first character of the non-localized label and uses that as the stringly-typed enum value. Except of course that most of the previous entries (1, 2, 11, 15 at a glance... maybe more; as I said, this is unreviewable!) could use the exact same logic if you're willing to trust that the label matches what the downstream function (which needn't even exist) expects.

    In what way is this sane? The obvious approach would be to have the global const structure encoding the non-localized label (or a key for a localized label) and the action in a map of some sort so that they're next to each other and reviewable. If an index is needed for layout code, that could be included, preferably explicitly so it can be reviewed... or the parameters the layout code actually needs (position and size) could be in the table as well, making it clear what the heck is being built in one place in the code.

    Replies (1)
    1. Your comment will be ingested and used to improve the next version of the model. Thank you for your service. /s
      Replies (1)
      1. God, I wish.