the-algorithm-ml
the-algorithm-ml copied to clipboard
Store returned metrics in variables prior to return statements.
I'm stepping through the code and there's a lot here. In general, it's a fantastic step in the right direction and I appreciate the willingness to open source the system. One nit I have is arithmetic in the return statements. As these modules evolve, it would be helpful to store the calculated values in variables and then return those variables. It's an extremely small increment toward overall improvement.
I look forward to getting my hands dirty here more and in the coming search system. 👍
The downside of storing values in variables unnecessarily before returning is that it can increase the memory usage of the program, which can impact performance, especially for large datasets. Additionally, it can make the code harder to read and understand, especially if the variable name does not provide any additional clarity or context. Therefore, it is generally recommended to only use variables when they provide additional clarity or are necessary for the logic of the program.
In general, if the expression is short and simple, it may not be necessary to store it in a variable before returning.
For metrics, the readability and extensibility of the code is probably more important than memory usage. There are other areas of a system where the same is not true. We could profile it if there were specific reasons why you think there could be some issue from a modest increase in memory usage here, but from what I can see the impact should be negligible.