Live data from Hacker News

Ask HN: What are the best coding practices in research projects?

news.ycombinator.com

11–14 of 14 posts

Re: Ask HN: What are the best coding practices in research projects?

#11
From my experience in knowing a few scientists, the pattern seems to be:

- Scientists try their best to be good programmers, but are scientists first.

- Someone the scientist knows, or someone on the team with more programming knowledge, turns what the scientist produced into something maintainable at some point.

- If they're lucky, the grant will have resources for a script/software maintainer.

Scientists are scientists. I know a few who can do things with awk that probably should never be done, but they use the tools they know to get the data to look the way they need.

Re: Ask HN: What are the best coding practices in research projects?

#12
JupyterHub allows you setup research clusters on GCloud, AWS and Azure. You can set CPU / GPU resource utilization limits, disk usage, memory, network. Even limit scaling to your budget. Once your experiment is up and running. It's simply another service running in a container. Have used it for a small distributed team. But can be scaled to corporate R&D teams with 1000s.

Core environment is still the Jupyter Notebook. So should remain familiar to most data scientists.

Zero to JupyterHub with Kubernetes

https://zero-to-jupyterhub.readthedocs.io/en/latest/

Re: Ask HN: What are the best coding practices in research projects?

#13
I think the first two are probably the right kinds of problems. Even in normal software engineering, you want to try out PoC's to prove that they are what your customer wants, and that things generally work the way you think they should.

Code quality is another problem entirely. I agree code quality can get out of control as soon as the PoC is promoted to something resembling "production."

My suggestions are:

- First, if you get frustrated at researchers for code quality, let them calmly know why you are upset. If they are being inefficient, many would love to hear tips to keep it from happening. Let them know when the things they are doing might affect large groups of people.

- Don't try to write tests for everything. This just slows you down, getting away from the good things above. Write tests for things that are frequently broken, and absolutely required to work, such as core functionality. If something gets broken 2 or 3 times, you should definitely have a test.

- Make your tests as high level as possible. Compute power is cheap, and despite what you might hear from the TDD/unit testing crowd, your tests don't need to run in 2 seconds to be useful. I like to have tests that emulate users, because as you change the logic of how you're doing things, you still have tests to back you up.

- Add lots of additional logging. This helps document the code (since the messages should be useful and say what is going on), and provides great info for debugging issues after they've already occurred. I've been saved by good logging more times than I can remember, especially on different OS/environments that aren't the test environment.

- Don't worry too much about edge cases. Just print a log line or crash out if it's something ridiculous you've gotten yourself into, which is a lot more friendly than figuring out some horrendous bug mired in retry logic that has masked the original issue.

- Insist on version control, but not code reviews. Code reviews can really slow you down. Instead, fix problems after they come up. You haven't shipped, right?

- Run the build and tests in a simple CI loop that runs overnight. Don't worry about testing each commit, just know if it works or doesn't work. Fix the problems.

These last two are related:

- Feel free to just start over. Delete huge amounts of code, and try a different approach.

- If you have gone past the point of no return (you don't want to start over), then start production-izing the code. Again, aim at the problems to start, not some coverage metric. Look over all the code and reduce redundancy. It's a lot easier to review code once it's all there, rather than bit by bit.

Re: Ask HN: What are the best coding practices in research projects?

#14

I used to be a software lead in a research organization. I have a LOT of opinions on the subject but I'll give you just a few points. - I've seen many cases where researchers refused to share their code because they knew it wasn't up to any reasonable standard. This is a red flag. If they are embarrassed by their code, I tend to discount their alleged results entirely. - Even in research, people should be required by…

To expand on your first and last points:

Your researcher got a result. Great. What is their objective evidence that the result is real rather than an artifact of a bug in their code? If the code is garbage, you can't trust the result, no matter how much of a breakthrough the result would be if true.

That doesn't mean that the code needs to be production-ready. It does mean that the code needs to be clean enough to be trustworthy. (Tests can be included in this evaluation.)

If the code's going to be product-ized... maybe ask the researcher which parts of the code they think are the most troublesome. Start by re-writing those pieces, from scratch, with production levels of rigor. Then, as other parts prove troublesome, rewrite those too. Don't band-aid them, rewrite them. Keep the interfaces, unless the interface itself is part of the problem.

Post reply on HN