You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
- 80I religiously unit test most of my code but I have found unit testing exploratory, scientific code less than useless. The methodology fundamentally doesn’t seem to work here. I don’t know any computational scientist in my field who unit-tests their analysis code. I’m not sure what the reason for this mismatch is but one of the reasons is certainly that, except for trivial units, it’s hard or impossible to establish good test cases.Konrad Rudolph– Konrad Rudolph2018-07-06 11:30:01 +00:00Commented Jul 6, 2018 at 11:30
- 23@KonradRudolph the trick in those cases is likely to be clean separation of concerns between parts of your code that have clearly definable behaviour (read this input, compute this value) from the parts of your code that are either genuinely exploratory or are adapting to e.g. some human-readable output or visualisation. The problem here is likely to be that poor separation of concerns leads to blurring those lines, which leads to a perception that unit testing in this context is impossible, which leads you back to the start in a repeating cycle.Ant P– Ant P2018-07-06 12:19:24 +00:00Commented Jul 6, 2018 at 12:19
- 18On a side note, version control also works quite nicely for LaTeX documents, since the format is amenable to text diffing. In this way, you can have a repository for both your papers and the code that supports them. I suggest looking into distributed version control, like Git. There's a bit of a learning curve, but once you understand it, you've got a nice clean way to iterate on your development and you have some interesting options to use a platform like Github, which offers free team accounts for academics.Dan Bryant– Dan Bryant2018-07-06 13:20:59 +00:00Commented Jul 6, 2018 at 13:20
- 12@AntP It's possible that there just isn't that much code that can be meaningfully refactored out into well-defined testable units. A lot of scientific code is essentially taping a bunch of libraries together. These libraries will already be well tested and cleanly structured, meaning the author only has to write "glue", and in my experience, it's damn near impossible to write unit tests for glue that aren't tautological.James_pic– James_pic2018-07-06 15:54:14 +00:00Commented Jul 6, 2018 at 15:54
- 8"Between version control and writing unit tests as you go, you code will naturally become a lot cleaner." This is not true. I can attest to it personally. Neither of these tools stops you from writing crappy code, and in particular, writing crappy tests on top of crappy code just makes it even harder to clean up. Tests are not a magic silver bullet, and talking like they are is a terrible thing to do to any developer still learning (which is everyone). Version control generally never causes damage to the code itself like bad testing does, though.jpmc26– jpmc262018-07-06 19:01:26 +00:00Commented Jul 6, 2018 at 19:01
| Show 13 more comments
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. design-patterns), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-py