https://blog.regehr.org/archives/1653 Embedded in Academia Explaining Code using ASCII Art --------------------------------------------------------------------- People tend to be visual: we use pictures to understand problems. Mainstream programming languages, on the other hand, operate in an almost completely different kind of abstract space, leaving a big gap between programs and pictures. This piece is about pictures drawn using a text character set and then embedded in source code. I love these! The other day I asked around on Twitter for more examples and the responses far exceeded expectations (thanks everyone!). There are a ton of great examples in the thread; here I've categorized a few of them. Click on images go to the repositories. Data Structures One of the most common kinds of ASCII art in code is illustrating the shape of a data structure. The example I started with comes from LLVM: [llvm1] The layout of a data structure in the Jikes RVM: [jikes] A tree rotate in Musl: [musl] Double-ended queue from the Rust library: [rust-deq] Swift compiler internals: [swift] Malloc header layout: [malloc] State Machines JavaScript profiling: [js-profile] RPCs in Cloud Spanner: [go-rpc] I/O stream states: [stream] Logical Structure in the Problem Domain Control flow in an NWScript program being decompiled: [decompile] ECC internals: [dalek] Formatting numbers: [number] A quantum circuit: [quantum] Balancing memory management objectives in an OS kernel: [paging] Subtyping relations (this is a very cool special case where the ASCII art is also code): [racket] The format of a DBF file: [dbf] A lookup table for image processing: [sharpen] Shape of a color function: [color] Structure of a URI: [uri] A very quick tutorial on undo systems from emacs: [undo] Geometry Attitude control in the Apollo Guidance Computer (!!!): [apollo] Image tiling: [image1] Boomerang trajectories in Nethack: [boomerang] Rendering CSS borders: [css] Quadtrees: [quadtrees] Speed control in a milling machine: [milling] Scrolling web pages: [scrolling] I hope you enjoyed these as much as I did! February 18, 2019 regehr Uncategorized --------------------------------------------------------------------- 11 responses to "Explaining Code using ASCII Art" 1. Magnus says: February 18, 2019 at 4:04 pm Ha ha brilliant! I've done plenty of these, when I wanted to switch half my brain off but still do something time-consuming and fiddly, but still kind of productive. Very therapeutic! 2. Tymtam No Choc says: February 18, 2019 at 7:57 pm These are examples of beauty in engineering. Using text, not images, would make it b.e.a.u.t.i.f.u.l. 3. Phillip says: February 18, 2019 at 9:54 pm You should publish them, it's a good way to store knowledge besides being therapeutic. I'd personally would love to see classic science books put in this format, Euclid's Elements or Newton's Opticks but don't have the time to do the work. I think this and something like itty.bitty.sites could help ease access to information. 4. err says: February 19, 2019 at 1:26 am please convert this to tikz and back 5. HaQadosch says: February 19, 2019 at 3:46 am http://asciiflow.com/ 6. Nick says: February 19, 2019 at 3:00 pm You might be interested in stream-tree, a library I created for expressing functions as ASCII flow charts in JavaScript. https://github.com/Widdershin/stream-tree Here's an example of a slides app that uses stream-tree. https://github.com/Widdershin/ how-to-write-javascript-without-going-insane/blob/ ce84669d40c7109c8c10b93175f5b56bd2079a24/index.js#L55-L108 7. foo says: February 20, 2019 at 7:40 am I did some animated ascii art explanations of basic algorithms a while ago https://stackoverflow.com/questions/198199/ how-do-you-reverse-a-string-in-place-in-c-or-c/21617273#21617273 https://stackoverflow.com/questions/21863609/ building-a-binary-heap/43077941#43077941 https://stackoverflow.com/questions/4833423/ shell-sort-java-example/22408617#22408617 8. Dan says: February 20, 2019 at 6:20 pm Nice collection! One more category that seems like it would fit is describing the hardware that will be controlled by the software. Warren Creemers drew/gathered a collection of Arduino layouts to add as comments in Arduino scripts: http://busyducks.com/wp_4_1/2015/11/16/ascii-art-arduino-pinouts/ (github: https://github.com/busyDuckman/ascii-art-arduinos) There is also a tool called AACircuit by Andreas Weber that is used to lay out circuits in ASCII art: https://josoansi.de/aacircuit.php (github: https://github.com/Andy1978/AACircuit) Gary Richardson made a Python version, but I haven't been able to track down the actual files. Here's his post about it back in 2005: http://sci.tech-archive.net/Archive/sci.electronics.design/ 2005-12/msg05445.html Another example of schematics used in Arduino code (by carlynorama): https://github.com/carlynorama/ASCII-schematics 9. Paul Black says: February 25, 2019 at 11:25 am Marvelous! Thank you for collecting and sharing those. 10. Rob says: February 27, 2019 at 9:19 am I'm a fan of ASCII art in source code but have always been bothered by the inconvenience of modifying the diagram. I recently decided to learn Javascript, so I wrote a tool which lets you draw line diagrams. The tool converts the diagram into ASCII, and appends a string representing the serialized, compressed version of the diagram. This lets you get recreate and modify the original line diagram-round-trip editing. 11. Rob says: February 27, 2019 at 9:20 am http://buttersquid.ink Embedded in Academia Proudly powered by WordPress