6

那些代码里有趣的字母拼图注释 | 程序师 - 程序员、编程语言、软件开发、编程技术

 1 year ago
source link: https://www.techug.com/post/explaining-code-using-ascii-art/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

那些代码里有趣的字母拼图注释

图示是最容易让人理解的表达方式,我们使用图片来认识问题。各种主流编程语言,从某方面来说,都使用了完全不同的编程理念或数据操作方法,给人们的认知留下了巨大的鸿沟。本文展示了一些嵌入在源代码中,使用字母排列拼出来是图案注释。我们很佩服这些注释!

数据结构注释

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.jpg

The layout of a data structure in the Jikes RVM:

jikes.jpg

A tree rotate in Musl:

musl.jpg

Double-ended queue from the Rust library:

rust-deq.jpg

Swift compiler internals:

swift.jpg

Malloc header layout:

状态机注释

JavaScript profiling:

RPCs in Cloud Spanner:

I/O stream states:

逻辑结构注释

Control flow in an NWScript program being decompiled:

ECC internals:

Formatting numbers:

A quantum circuit:

Balancing memory management objectives in an OS kernel:

Subtyping relations (this is a very cool special case where the ASCII art is also code):

The format of a DBF file:

A lookup table for image processing:

Shape of a color function:

Structure of a URI:

A very quick tutorial on undo systems from emacs:

几何学注释

Attitude control in the Apollo Guidance Computer (!!!):

Image tiling:

Boomerang trajectories in Nethack:

Rendering CSS borders:

Quadtrees:

Speed control in a milling machine:

Scrolling web pages:

希望你也会喜欢这些有趣的代码注释!

http://asciiflow.com/

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

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

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

字母拼图制作工具

http://buttersquid.ink


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK