algorithm-archive
algorithm-archive copied to clipboard
Make use of code-run-websites
For many languages websites exist, where people can run code snippets. We currently don't really do that in the AAA, but I think it's a cool thing to add for languages supporting it. People wouldn't have to download and install everything needed just to run some code and people could also run code on mobile.
This topic came to my attention again, because of this https://github.com/algorithm-archivists/algorithm-archive/pull/164 which included a convenient way to run the code.
So I open this issue for discussion about this topic. What do you guys think?
I see the value in this. I myself tonight copy/pasted some matlab code in the matlab online website because I don't have matlab installed on this machine (... oh wait... I just realized I do have it... gah...). What would be great is having some way of automatizing it. Are there tools like that?
I can see two different methods of doing this. Either include just a link to the website or have it somehow integrate in the AAA. I think the first one will be fine for now, while the second one is something to consider for the future, because I imagine to to be far more complex.
@jiegillet I would say just creating it manually and checking if the output is right is enough. We need to pay attention to this then in future PRs of course, but I think this will be fine. I don't know what you mean by tools... A GitBook plugin doing that would be neat (and cover the second method I named), but I highly doubt it exists.
Yeah I was thinking GitBook plugin... We have all the informations, where the file is, what the language is. Some online interpreters can handle hundreds of languages. But yes, chances are low it exists.
I must say I'm not a fan of integrating these tools. I'd support the decision to have an introduction chapter with a bunch of links to such online interpreters/compilers, but in the end, we're writing a book. I don't think it needs live code execution.
Secondly, I don't like the idea of creating a bunch of dependencies on third-party services. They can go down, change their APIs and it will be work to maintain working connections to them.
@Gustorn recently brought up that we could do something like this: https://doc.rust-lang.org/book/second-edition/ch01-02-hello-world.html, where each codeblock can be run in the background. I don't know how well this will play with the include-codeblocks and theme-api plugins.
@julianschacher mentioned we could use this too: https://docs.microsoft.com/en-us/dotnet/csharp/quick-starts/hello-world?tutorial-step=2, which brings up a separate editor so people can play with the code.
I also don't know what languages are supported for a similar feature. Like @Butt4cak3 I don't know if these services will be stable for a long time or not... But I am not sure how long our current tools will be stable for anyway.
A neat example of how to implement this can be seen in the Ant Design docs. Click on view code and note the small icons that link to the code preview sites.
@Butt4cak3 I don't think it would hurt too much to just link to their sites like in this example ^ (most projects do that). I know it's super annoying to deal with changing APIs and whatnot, but if they do go down it wouldn't be too hard to remove them.
@leios Something similar to what the rustlang book does is very hard for anything that's not JavaScript. I'd suggest linking to the code playground sites instead.
Here are a few good ones that we can link to:
JavaScript: https://codepen.io / https://jsfiddle.net/ / http://jsbin.com/ Rust: https://play.rust-lang.org Python: https://trinket.io/python/ C/C++/C#/Java/PHP/Ruby: https://code.sololearn.com/
Cannot we just test in local what the results are, and cheat a little bit : when the user will press on buttons like 'play' or something like that, the results are stored somewhere and are just display! It's not the best solution, but It will do the job!
@xam4lor The cool thing with those code running websites is, that people can modify the code and see what happens. With our cheat this wouldn't be possible. We also decided not to provide output files (and maybe use random input) for our implementations, right here: https://github.com/algorithm-archivists/algorithm-archive/pull/55 (scroll down a bit)
Yes that's right!