So let's say I have a file PayYourSalary.scala, and somewhere in that file there is a method: def payEmployeeForOneDay(rate: Int, minutesWorked: Int = 8) = { // other stuff here } As you can see, there is a bug here. This method used to have a parameter hoursWorked with a default of 8 (a reasonable default!). But then it was changed to minutes and someone forgot to update the default. Because of this, some people end…
Setting a default value for an argument is an assignment, a real action that is taken by the code at runtime. The Java equivalent would be in two (or three, depending on how you count) parts, something like:
// Do the things.
// If minutesWorked is left at -1, this procedure will use the default value of 480.
void payEmployeeForOneDay(int rate, int minutesWorked) { // inert declaration
if (minutesWorked == -1) { minutesWorked = 8; } // active code with bug
// ...
}
Here we have a human readable specification of behavior, which has zero impact on the compiler or generated code, a machine readable description of an interface for other bits of software to interact with this bit of software, and some working code that will make something happen.This is interesting because the specification being described and implemented is not fully encapsulated by the function declaration/API, but also by the "non-code" english comment attached to it.
Is it fair use for me to copy this API by using the same function declaration but rewording the documentation, but writing my own implementation of the function body to correctly match the comment? What if I implemented a bug-compatible version of the body from scratch, and rewrote the comment to match?