How to improve the quality of code in OR?

Operations Research Asked on August 19, 2021

So I noticed, that a lot of students taking OR-classes come from non-computer science backgrounds (e.g. buissiness administration). They typically had only one other class in their first semester where they had to write (typically java) code, and therefore their code is very "hacky". It works, but I wouldn’t want to hire them as software devellopers, or have them write code that actually is used anywhere and needs to be maintained.

So my questions would be:

a) Is the expectation for entry level positions, that the applicant is able to produce high quality code, or is that something that would be learned on the job?

b) What are some good self-study resources to improve the quality of code I can recommend to my students?

c) Are there some reference codes, that would be good examples for high quality code?

3 Answers

Disclaimer: I have worked for 3 years as an optimization software developer at a utility company and now work for Gurobi.

Is the expectation for entry level positions, that the applicant is able to produce high quality code, or is that something that would be learned on the job?

There is no expectation because it is often not the case (as Nikos said). However, a candidate who is capable of decent coding is going to have much better chances, as very advanced theoretical knowledge is often not the most important hiring decision. Please encourage your students to have a github profile and post some stuff there; I always looked at that when we got applications in.

What are some good self-study resources to improve the quality of code I can recommend to my students?

There is a distinction to make here: for general coding the best book in my opinion is "Design Patterns" by the Gang of Four. Beyond that, code review is your biggest resource (you can even hire people online for $5), because that way you get feedback from someone else about your code.

As for OR-specific code: there are unfortunately no guidelines on this whatsoever. I wrote up some on LinkedIn a year or so ago (and writing this up in a book is still on my to-do), but I don't know of anything else. If you come across something, let me know.

Are there some reference codes, that would be good examples for high quality code?

For general software, just check out GitHub and off you go. You will recognize good code pretty quickly.

For OR-specific things, I did not find much (as Nikos said). For fun I implemented the rules I set out publicly in this repo about optimizing which drinks to buy for your bar. But it is far from perfect. It should though give an idea of how one can do it.

Correct answer by Richard on August 19, 2021

Unfortunately writing high quality OR code is beyond the reach of most academic settings. This is mainly because:

  • Writing high quality code is very time consuming.
  • The scope of OR code is much better suited to teams of people rather than a lone wolf trying to do everything alone.
  • Because it's time consuming, there's never enough time in academia to do this properly, as priorities are different (publish or perish).
  • Academia is a place to learn by doing things wrong. Industry is the place we go to after we've learned stuff.
  • Production code is the domain of professional developers. I thought I was pretty good at coding after my PhD, and all my developers put me to shame. Most of them are 10 years younger than me.
  • In most academic groups, even if a person who does things properly shows up from time to time their know-how leaves the group when they do.

Academia really needs to move away from the notion that a talented student can just "do things" alone. This is simply not true in software in any production setting. People need teams, support, infrastructure, and senior leads to guide development.

The remedy would be for academic groups to start employing professional developers full-time to support the researchers. This would have the nice side effect of training them to do things properly while they do research.

All this means that requirements are not really high from a coding point of view. This is dangerous because supervisors tend to accept candidates who simply don't have the background to do the work necessary. My advice for entry-level applicants is to really look into who is in the group, and how long the people who know what they're doing are going to be there after you join. If they don't have a computer science background they should be prepared to do a lot of work to catch up if you want to write good code.

A red flag is if the group doesn't have a repository to inherit code between students. If they have code, people should read that code before they join. Does the group have continuous integration? Does the code have unit tests? Are there 15 forks or does everything eventually get merged into the master branch? Is there a person responsible for maintaining the codebase? Who is that person? If they leave, are there plans to replace them?

My experience is that unless new applicants can get good answers to such questions the group is unlikely to have the culture to provide the support people need to write high-quality code.

For industrial entry-level positions it depends on the company - for instance at Octeract we have very high standards for C++, but we also don't have entry-level positions. We still do a lot of training, but mostly on advanced things.

Commercial solvers are of course not the only applications of OR, in other settings standards are lower and entry-level jobs are available.

The best open source OR code I've seen is MINOTAUR, but even that is a far cry from production-level OR code.

Good resources for students are predominantly to start using the tooling we use in the industry. They should learn how to use Git, Jenkins, and the Clang tools. They should read the Google style guide on how to format code properly. The should learn how to use static analysis tools, profilers, and Valgrind to diagnose the state of their code. They should get into the habit of writing unit tests for their code (Catch! is a good testing framework for C++). They should use Doxygen to automatically map and document the codebase.

Answered by Nikos Kazazakis on August 19, 2021

I can really only answer one point:

b) Clean Code: A Handbook of Agile Software Craftsmanship I think the examples in the book are even for Java, but it is applicable for other languages as well. (This is the entry book, there are follow up books in this series)

What helped me a lot is taking a piece of code i have written and then taking one concept of the book like "a function should only have one purpose" and then refactoring this code and then comparing the two versions. With time you do more of the stuff immediately.

What i think is important is that you do not only read books or other code, but you need to do this for you own code.

It is also important to tell the students, that you often first write code that works, but is not really of good maintainble quality and then you do a refactoring to make it more maintainable/better readable. This second step is something that requires discipline, because the code already works and there are only immediate costs involved in refactoring, but it bites back in the long run if you don't do it.

Answered by user3680510 on August 19, 2021

Add your own answers!

Related Questions

Multiple Knapsacks with splitting

1  Asked on December 20, 2021 by cesar-canassa


How to simulate computational execution time?

2  Asked on August 19, 2021 by matheus-digenes-andrade


Parallel nonlinear solvers

3  Asked on August 19, 2021 by josh-allen


Error evalution for linear fits

1  Asked on August 19, 2021 by jane


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP