Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guideline for repeated code block in Jupyter notebook #45

Open
pllim opened this issue Sep 11, 2018 · 1 comment
Open

Guideline for repeated code block in Jupyter notebook #45

pllim opened this issue Sep 11, 2018 · 1 comment
Labels
question Further information is requested

Comments

@pllim
Copy link
Contributor

pllim commented Sep 11, 2018

Something brought up by @samanthalh -- When one is developing notebook for users and find oneself in a situation where one needs to copy and paste the same code with slight variations (e.g., plotting results of subsequent tweakreg runs on the same dataset), is it better to:

  1. Brute force copy and paste; OR
  2. Write a function of the repeated code and then call it with different inputs where they vary?

Brute force way is more tedious and provides clarity and possibly is resistant to out-of-order cell runs in some cases. A function might be more elegant and reduce future maintenance but user needs to scroll up to see what happens in the function, and the cell with the function needs to be run before all the other stuff.

Is a guide line for such a thing within scope of this document?

@hcferguson
Copy link

It's a common quandary. My preference would be to define each function in a cell of its own with if it's more than a few lines long, since otherwise all that repeated code can just obfuscate the examples being communicated in the later cells. As a matter of style, I'd suggest these be collected in their own section early in the notebook, and descriptions of what they do in separate markdown cells.

@stscicrawford stscicrawford added the question Further information is requested label Nov 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants