Live data from Hacker News

ASCII art for semantic code commenting

asciiflow.com

71–80 of 82 posts

Re: ASCII art for semantic code commenting

#71
post #54
post #34

Earlier quoted context omitted.

Do you have an example context in which you'd use these? I've never thought to do this and am curious about the possibilities and use cases.

Basically I use the same kind of philosophy as RFCs, and document things using ascii art where some kind of diagram makes sense. For example, see the TCP RFC https://datatracker.ietf.org/doc/html/rfc793 where they use it for packet layout, flow diagrams, block diagrams, etc. It makes the whole thing self contained, you can copy paste diagrams to almost anywhere, easy to modify. Disadvantage is in some more complex di…

RFCs are now allowed to contain SVGs though.

Re: ASCII art for semantic code commenting

#72

For what it's worth, I keep a file in my home folder containing some box drawing characters. It's not super fast to draw by copy-paste but the result usually looks quite nice. ─ │ ┌ ┬ ┐ ┄ ┆ ├ ┼ ┤ ╲ ╱ ┈ ┊ └ ┴ ┘ ━ ┃ ┏ ┳ ┓ ┏ ┯ ┓ ┏ ┳ ┓ ┏ ┯ ┓ ┅ ┇ ┣ ╋ ┫ ┣ ┿ ┫ ┠ ╂ ┨ ┠ ┼ ┨ ┉ ┋ ┗ ┻ ┛ ┗ ┷ ┛ ┗ ┻ ┛ ┗ ┷ ┛

For those on macOS/iOS, using custom text expansions [0] also helps to do this without having to leave the doc you’re editing. I’ve built up tons of these over the years for things like ⌘ (“commandkey”) → (“rightarrow”) (╯°□°)╯︵ ┻━┻ (“tableflip”) and of course, a party parrot wave for Slack (“parrotwave” → :parrotwave1::parrotwave2::parrotwave3::parrotwave4::parrotwave5::parrotwave6::parrotwave7:). They can sync over…

Did you override the hotkey to go to the end of a line for an emoticon? Or are those 3 different examples?

Re: ASCII art for semantic code commenting

#73

It's amazing that it is 2022, and not only can we not put any kind of media in source code comments, nobody even entertains the idea that it could be possible. Programming tooling really is living in the dark ages sometimes.

IMO text still provides the best combination of flexibility, power, simplicity and accessibility. A screen reader can’t describe a JPEG or animated GIF. You can’t diff images/animations as easily as text. You can’t automatically translate text in images. Images and their toolchains like imagemagick introduce attack vectors. They take up more disk space. You can’t change the font of text in images. Text in images is n…

>A screen reader can’t describe a JPEG or animated GIF.

Sure it can. There's a whole field of computer science for doing just that, computer vision.

>You can’t automatically translate text in images

You can use OCR to read text from images.

>Images and their toolchains like imagemagick introduce attack vectors.

This isn't fair. Text based toolchains can be vulnerable too. There have been millions of vulnerabilities with string handling

>They take up more disk space.

Buy a bigger hard drive / cloud storage.

>You can’t change the font of text in images.

Pick a readable font in the first place.

>Text in images is not greppable.

Again your could use OCR to make thi spossible.

>Do you need to change some text in that documentation image? Hope you have the vector-based original!

Check in the project file to source control or just draw over the current one.

Re: ASCII art for semantic code commenting

#74

For what it's worth, I keep a file in my home folder containing some box drawing characters. It's not super fast to draw by copy-paste but the result usually looks quite nice. ─ │ ┌ ┬ ┐ ┄ ┆ ├ ┼ ┤ ╲ ╱ ┈ ┊ └ ┴ ┘ ━ ┃ ┏ ┳ ┓ ┏ ┯ ┓ ┏ ┳ ┓ ┏ ┯ ┓ ┅ ┇ ┣ ╋ ┫ ┣ ┿ ┫ ┠ ╂ ┨ ┠ ┼ ┨ ┉ ┋ ┗ ┻ ┛ ┗ ┷ ┛ ┗ ┻ ┛ ┗ ┷ ┛

Vim has digraphs for all of these characters, which I like to use. e.g. you can get ┌ with dr (d = down, r = right), and ┨ with Vl (V = heavy vertical, l = left). To find the mappings, :digraphs shows the whole list, or copy this block of text and put the cursor over any of the characters in normal mode and type ga and it’ll echo things like “ 9504, Hex 2520, Oct 22440, Digr Vr”.

(I use a Compose key for almost all character composition, with plenty of custom mappings in my ~/.XCompose, but box drawing specifically I have skipped and use Vim digraphs, and so drop into Vim any time I want to write any.)

Re: ASCII art for semantic code commenting

#75
I love this and I'm going to use it for fancy comments in code and in the browser console. It'd be really cool if you could integrate something like http://www.figlet.org/ for inserting ASCII text art.

I wish I had known about this tool when I was building this little browser game https://replit.com/@aMoniker/Gush because all the levels & game objects are generated from multiline strings of ascii symbols, and it just took too long to do manually.

Re: ASCII art for semantic code commenting

#76

Earlier quoted context omitted.

It's fabulous in cases where there's a "big important business logic" or a "big important test" with tough to eliminate complexity, where you feel a diagram is so important that it's worth putting in comments beside said code. I do recommend that you be careful with this though; in places where it's not common to put ASCII art diagrams in code you'll probably receive pushback (it is afterall very large and distractin…

It's also extremely useful for bit-mapped registers in embedded code. EG the TI bq25155[1] battery charge controller PCHRGCTRL register (page 52) is divided into 3 fields. It can be quite helpful to show the layout before code to set the range. /* * ┌───────────────┬──────────┬─────────┐ * │ ICHARGE_RANGE │ RESERVED │ IPRECHG │ * │ 7 │ 6-5 | 4-0 | * └───────────────┴──────────┴─────────┘ * This function sets the prec…

[deleted]

Re: ASCII art for semantic code commenting

#77

Earlier quoted context omitted.

For those on macOS/iOS, using custom text expansions [0] also helps to do this without having to leave the doc you’re editing. I’ve built up tons of these over the years for things like ⌘ (“commandkey”) → (“rightarrow”) (╯°□°)╯︵ ┻━┻ (“tableflip”) and of course, a party parrot wave for Slack (“parrotwave” → :parrotwave1::parrotwave2::parrotwave3::parrotwave4::parrotwave5::parrotwave6::parrotwave7:). They can sync over…

Did you override the hotkey to go to the end of a line for an emoticon? Or are those 3 different examples?

They’re different examples.

Re: ASCII art for semantic code commenting

#79

It's amazing that it is 2022, and not only can we not put any kind of media in source code comments, nobody even entertains the idea that it could be possible. Programming tooling really is living in the dark ages sometimes.

HolyC has everything we wish for.

Re: ASCII art for semantic code commenting

#80

It's amazing that it is 2022, and not only can we not put any kind of media in source code comments, nobody even entertains the idea that it could be possible. Programming tooling really is living in the dark ages sometimes.

IMO text still provides the best combination of flexibility, power, simplicity and accessibility. A screen reader can’t describe a JPEG or animated GIF. You can’t diff images/animations as easily as text. You can’t automatically translate text in images. Images and their toolchains like imagemagick introduce attack vectors. They take up more disk space. You can’t change the font of text in images. Text in images is n…

Now do a list of all the things you can't do with text.
Post reply on HN