Hacker News new | ask | show | jobs
by lelandbatey 1590 days ago
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 distracting compared to said code). Be ready to save an in-code diagram for the 1-to-3 places in the business where they'll be a godsend.
1 comments

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 precharge current
    *  and fast-charge current step size the
    *  nearest 1.25mA (<= 318.75mA) or 
    *  2.5mA (<= 500mA).
    */
etc, etc.

[1] https://www.ti.com/lit/ds/symlink/bq25155.pdf