36

Please see Jon Ericson's answer and reply to his concerns and questions. Thank you.


I am requesting implementation of Snippets functionality for Mathematica Stack Exchange.

Similar functionality for other sites is discussed in:

Unlike that implementation we could presumably not have a Run Code button, unless Stack Exchange wishes to pay for a webMathematica or Mathematica Online service, but instead:

  • Show Code
  • Copy to clipboard
  • Save as file

Additionally I would like a button for uploading a text-based file such as a Notebook (.nb) or Package (.m) into a Snippet. The Save as file function should remember the file extension if possible.

  • 3
    I haven't used Mathematica in over a decade, so forgive my ignorance. Are there any files other than Notebooks and Packages that would be sensible to upload? When it comes to displaying the content of these files, is there any difference between the various types? – Jon Ericson Apr 14 '15 at 17:37
  • 1
    @JonEricson Good question(s). (1) In addition to the native types it would also be desirable to share text-based data because we get a lot of "I am importing my file X with..." without actually having file X. (2) Both Notebooks and Packages follow standard Mathematica syntax, so despite using a lot of unusual Symbols (reserved function names) in the case of Notebooks they can both be parsed/styled as Mathematica code. Please let me know if you have any other questions that I can attempt to answer! – Mr.Wizard Apr 14 '15 at 17:50
  • 1
    @Mr.Wizard You're assuming WR would want to cash in.Perhaps they may consider this a community service instead. No joking. – Dr. belisarius Apr 15 '15 at 15:00
  • @belisarius I suppose it couldn't hurt to ask but I get the feeling they are more interested in fostering their own Community site. – Mr.Wizard Apr 15 '15 at 15:05
  • 2
    @Jacob I am speaking of "raw" Notebook files but I see this as the "lesser of two evils" compared to embedding arbitrary code in imgur images.. Frankly I don't know where to fall on the issue but I think publicly readable Notebook data is clearly superior to obfuscated and programmatically loaded PNG trickery. If you feel that neither option should be employed I strongly encourage you to post an "answer" about it here. – Mr.Wizard Apr 15 '15 at 15:53
  • Hmpf, even Import["nb.nb", "Elements"] is not safe, maybe I should report. – Jacob Akkerboom Apr 15 '15 at 17:24
  • 1
    @Jacob I contacted a couple of community managers (Shog9, Jon Ericson) and before implementing anything they wanted to see details and support for it on the site Meta. I believe implementation is likely if we have agreement on specific requirements. The 24/0 vote record on this Q is a good start; your concerns are an additional step. Let me think if there is anything else I should bring before the community regarding this first, but soon I shall contact the community managers again. – Mr.Wizard Apr 29 '15 at 3:30
  • @Mr.Wizard excellent! Thank you for making the effort :). – Jacob Akkerboom Apr 29 '15 at 16:22
  • @Jacob I am sorry, I really let this one fall through the cracks. Shortly after writing my last comment I did contact the support team and they said try again next Monday when the person who would handle this is back in the office. I never did and I simply forgot about this until now. This Monday I will try again. Kick me if I forget! – Mr.Wizard Jun 5 '15 at 23:43
  • So... I suppose gists are kind of nice. How about link rot, will my silly gist remain forever? Or should I link it to an account? Too bad they also don't have a "copy to clipboard" button, which is why I linked to the raw page. You can return to the gist by chopping off a part of the url. There is a download file button though. Another thing is that the gists don't have syntax highlighting. – Jacob Akkerboom Jun 26 '15 at 9:09
  • Just sharing some of my thoughts, because there hasn't been any reaction after Jon Ericson's answer. I wonder if other sites on the network would like to see the features we currently request, I would think they do. – Jacob Akkerboom Jun 26 '15 at 9:16
  • @Jacob Jon Ericson's answer implicitly calls for a reply; if you are inclined to respond I suggest you post a second answer to address his points. – Mr.Wizard Jun 26 '15 at 9:19
15

I support this feature request, because I feel especially a copy to clipboard button would be very nice. However, I have some concerns with respect to request "Additionally I would like a button for uploading a text-based file such as a Notebook".

My concerns

I am against sharing "raw" (unconverted, including a lot of Box expressions) notebook files on the site without warning, as they can contain malicious code in many unexpected ways.

For me, the main difference between sharing notebook files directly and using the SETools is in what a user can reasonably expect. I feel that the security measures for notebook files often not match reasonable expectations, in the case of Import, the handling of dynamic content and the possibility of invisible code.

For example, it is safe to get a Notebook expression using the SETools, but using Import on a notebook file is not, even though the result is similar. If you deliver somebody a Notebook expression wrapped in HoldComplete, at least they have to know what they are doing before they can use it as a notebook in the Front End. When using the SETools, it is clear that an image can contain any expression. When you see the head is Notebook, it is easy to imagine that somebody simply used the head Notebook and put malicious code inside, so that you at least expect the danger.

Conclusion

I would be in favor of editing the request by Mr.Wizard in either one of the following ways.

  1. Removing the request for notebook file handling.

  2. Adding an explicit request for a warning dialogue when downloading notebooks. Possibly the dialogue could contain a link that we supply to information on how to safely handle untrusted notebooks.

  • 7
    In an ideal world I would love to have a Notebook up/download feature, but I agree with you that it is too dangerous in the world we're actually living in. I already voiced my concerns to Halirutan in chat and he hasn't convinced me that the current solution is safe. In full Notebooks code can be made invisible using white text or by code in an embedded Manipulate (using SaveDefinitions etc.). – Sjoerd C. de Vries Apr 16 '15 at 5:49
8

I'm trying to get my head around the root of the problem. According to the SE-Tools README:

The possibility to insert images is pretty nice, but what if you need to share a large expression, that is too large to include it as code-block in an answer? Or you want to share a cell with fancy formatting? Or you want to share a whole Notebook with titles, sections, text, code, etc? You could post a screenshot of this, but then no one can edit your code.

So the three needs are:

  1. collapsable code,
  2. sharing formatting code not intended for human consumption, and
  3. the ability to save complete examples.

Currently, snippets support just the first requirement. (As an aside there is an argument against code folding features.) I think something like Gists would fill the third requirement. I'm not sure what the formatting requirement would entail, but Jacob's answer suggests that we'd need to do some sort of sanitation and error checking. If it isn't possible for a human to figure out what the code does by examination, it would be difficult to moderate posts with such code.

So here's the difficulty I have pitching this feature to our developers: snippets only do a third of what the feature requires and there's already a third-party tool that does all of the things you need. Now I know the tool is a hack (a lovely hack, actually) and that an ideal tool would be built into the site itself. It's just difficult to justify the resources needed to implement it.

On the other hand, we brainstorming several more general features that might satisfy some of the need expressed here. Being able to share detailed examples helps make programming sites like Stack Overflow and Mathematica Stack Exchange more useful for people to learn from each other. Code snippets for JavaScript were just the low-hanging fruit. We need to do better for coders who happen to use other languages.

  • Thanks for this reply. I hope that the community will address this. – Mr.Wizard Jun 13 '15 at 1:25
  • If JavaScript snippets were enabled for MSE we as a community could provide a decent enough resolution to most of this by using some iframes and a free part of Wolfram's Cloud stack: sandbox.open.wolframcloud.com/app/view/newNotebook – b3m2a1 Jan 25 '18 at 7:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .