4 ms·
How on earth would a two-dimensional array be their first approach? And then acting like a tree is a novel concept? I had to double-check that this wasn't a dev
by von_lohengramm 5y ago
How on earth would a two-dimensional array be their first approach? And then acting like a tree is a novel concept? I had to double-check that this wasn't a dev.to article.
- jeroenhd 5y agoWhy a 2D array makes sense: many people using multiplexers like this seem to use them in a 2x2 or 3x3 grid. You could easily represent panes like that by making an HTML-like grid where each row and column contains a number of which pane it belongs to. As for why trees seem to be a novel concept: the code is written in Rust, and tree algorithms specifically are hard to do in the traditional way (pointers to pointers being moved around) without unsafe code. While you're at it, you may just as well explain trees I guess. Of course Rust trees can be done, but the resulting data structure is often unwieldy and ugly. When I'm writing Rust, I tend to avoid writing structures like that because I don't want to deal with Box<Arc<RefCell<X>>> or whatever the correct type is for writing mutable tree structures.
- von_lohengramm 5y agoAnecdotally, I've never used or seen anyone use a pure NxN grid. It's always a series of horizontal or vertical splits (a tree). I'll admit that this being Rust is likely the cause, but this is a simple binary tree. There's no need for backpointers or any troublesome algorithms or anything. It's just a tad annoying that Rust pushes people towards crappy solutions by making the better solution _spooky and dangerous_ when said solution doesn't even involve the _spooky and dangerous_ `unsafe` keyword.
- da39a3ee 5y agoYou're forgetting that the author of the article might not have your level of experience in computer science/engineering. And now you've added a sneering comment to their HN thread. And caused me to make another one that's potentially patronizing. Maybe it would have been better if you had thought a bit more imaginatively / empathetically before your post?