//
// B(m,n)(x) = binomial(m,n) * (1-x)^(m-n) * x^n
// __ m-n
// (1-x)^(m-n) = \ (-1)^i * binomial(m-n,i) * x^i
// /_ i=0
// __ m-n
// B(m,n)(x) = binomial(m,n) \ (-1)^i * binomial(m-n,i) * x^(i+n)
// /_ i=0
//
Polynomial Polynomial::bernstein(unsigned m, unsigned n) {
Polynomial B(m);
unsigned j = m-n;
double scale = binomial(m,n);
for (unsigned i = 0; i <= j; i++)
if (isEven(i))
B[i+n] = scale*binomial(j,i);
else
B[i+n] = -scale*binomial(j,i);
return B;
}[0] https://github.com/sourcegraph/sourcegraph/blob/2.13.0/doc/d... [1] https://github.com/sourcegraph/sourcegraph/blob/master/doc/d...
Note: For anyone else interested, you can read the architecture doc mentioned in the parent comment at https://docs.sourcegraph.com/dev/architecture.
BTW, it would be awesome for someone to build a Sourcegraph extension (https://docs.sourcegraph.com/extensions) that renders Mermaid/Graphviz diagrams in code. Then you could see the rendered graphs when browsing on GitHub if you use our Chrome/Firefox browser extensions (https://docs.sourcegraph.com/integration/browser_extension).
One project in particular was troubling. It was an industrial spray controller for vinyards and such. As is typical with these older products, the microcontroller that drove it was an 8051 (some SiLab part I think). Normally that wouldn't matter, but this project was written in assembly. Even worse, it was one big file (something like 17k lines).
All of the main variables we're statically allocated for easier ram usage and eeprom saving. There were deliberately few functions in the program (almost everything was in the main loop), due to stack size limitations (it was a 23 byte stack I believe). I don't think a single macro was used in the entire project. Basically this was a very old and very crusty project.
The comments were the only redeeming quality. Timing diagrams, menu layouts, waveforms, LCD illustrations, etc. There were whole PAGES of ASCII art, and it saved my butt. Thank you to whoever made the decision to properly comment that code. I owe you a few beers.
EDIT: That's also around the same time I started using VS Code, which was a huge help. It beats the heck out of whatever 1990s-looking IDE they had me using to debug the project. You don't realize how nice it is to have proper search functionality and the ability to open a file in multiple frames until you don't have it anymore.
It’s unfortunate they decided to discontinue its development [2].
A little one I done with it: https://github.com/salgadobreno/dme/blob/master/README.md
Abusing unicode chars, I've done some pretty interesting mock-ups...
[1] https://alternativeto.net/software/monodraw/?platform=window...
[1] https://monodraw.helftone.com
Example copied from a program that fetches data from somewhere and prepares it and mounts it as a fuse file system:
/*
┌─────────────────────────────────────┐
│ ┌─────────────┐│
│ │ ││
│ ┌──memory───◀───┼───┬──────┐ ││
│ │main thread│ │ │parser│ ││
│ └───────────┴───┼───▶──────┘ ││
│ │ ▲ │ │ ▲ ││
│ │ │ │ │ │ ││
│ │ │ │ │ │ ││
│ ▼─│ │ │ │ ││
│ ;20s: │ │ │ ││
│ : ; │ │ │ ││
│ ╲ ▲ │ ▼─│ ││
│ │'│ └────;120s────┘│
│┌─────────┼─┼────────┐ ┌──▶: ;───┐ │
││ ┌────▼─┴────┐ │ │ ╲ ╱ │ │
││ │fast memory│ │ │ ' │ │
││ │main thread│ │ │ Λ │ │
││ └─┬───────▲─┘ │ │ ╱ ╲ │ │
││ │ │ │ │ ╱ ╲ │ │
││ ┌─▼─fuse──┴─┐ │ └── ◀─┘ │
││ │controller │ │ beacon │
││ └─┬───────▲─┘ │ ╲ ╱ │
││ │ │ │ V │
│└──────┼───────┼─────┘ │
│┌──────▼───────┴─────┐ │
││ fuse <> kernel │ │
│└────────────────────┘ │
└─────────────────────────────────────┘
*/
(screenshot of comment without the HN formatting issues: https://i.imgur.com/YOaysWn.png)edit.: No way I can make it keep format here lol https://github.com/salgadobreno/dme/blob/master/README.md
I'm still looking for an ASCII art editor to make it more pleasant to draw though. So far, I like the default styles in Asciio [1] the best.
[0] https://preetam.io/post/s3-static-hosting-https/
[1] https://metacpan.org/pod/distribution/App-Asciio/lib/App/Asc...
asciidoctor supports that (and lots of other specialized diagram tools) with little effort (https://asciidoctor.org/docs/asciidoctor-diagram/)
I think ASCII drawings should be used as an aid but not as a replacement for a textual description. If you use ASCII art on a website W3C recommends providing a text alternative [1].
The clear advantage is that the documentation is always up to date. Spend time once to develop your tool, generate your doc at any time you want with almost zero cost.
For a simple state machine sed/grep/awk magic is sufficient to generate a dot file.
For a more complex data processing graph, I use boost graph.
(UGH! HN doesn't seem to support unicode in comments!)
I'm not sure if it's a whitelist or a blacklist, but either way it's a deliberately curated subset.
http://www.dbfree.org/webdocs/1-documentation/0018-developer...
blast from the past!
Then for fun, if you have to email the diagram, use the shaky tool [2] to convert it to an image.
[1] http://www.asciidraw.com/#Draw [2] http://shaky.github.bushong.net/
https://github.com/linpengcheng/PurefunctionPipelineDataflow...
advantages:
- It don't break the syntax of any programming language, you can compile directly. comment area markup method can be applied to any programming language and any markup (including Org,rst, asciidoc, etc.), which is the greatest advantage.
- you only need a single line of regular replacement preprocessing, then you can use any Markdown parse or converter.
- Support any code editor that supports Markdwon Live preview, allowing the source code of any programming language to become rich text in real time. In the code's comment area, You can use the markdown to draw flowcharts, tables, task lists, and display images on the live preview panel, enhance the readability of your code.
- If you extend the Markdwon tag, you can implement the eval code, print result, display data visualization and other instruction tags, to achieve live programming, live test.
the main purpose of the Code comment area markup method is to live Preview directly in the Code Editor Preview panel without exporting or any preprocessing.
I think:
- Literary Programming, Programming was the first, Literary was the second.
- The entire file is compliant with the programming language syntax and can be compiled directly.
- When writing (reading or refactoring) code files, I can modify and live preview directly in the editor without exporting or any preprocessing.
- Do not interfere with people who do not understand the markup language to read the code.