portfolio-performance / portfolio

Track and evaluate the performance of your investment portfolio across stocks, cryptocurrencies, and other assets.
http://www.portfolio-performance.info
Eclipse Public License 1.0
2.92k stars 601 forks source link

refactoring: using collections instead of arrays #3239

Open Marfir opened 1 year ago

Marfir commented 1 year ago

The project heavily using old school Java arrays instead of collections. Collections available since Java 1.2 and the common save way. The code will be get an huge improvement. Then it's possible to using streams and also a lot of code checks (to avoid e.g. IndexOutOfBoundsException) can be removed.

e.g. see class PerformanceIndex

chirlu commented 1 year ago

Processing speed.

Marfir commented 1 year ago

Yes, you can also speed up your code writing with collections and streams.

buchen commented 1 year ago

I get the point by @Marfir. Arrays need additional care. And the getter of course expose the array for modifications. On the other hand I definitely do not want to add boxing/unboxing of those long/double values. And the charting library works with arrays as well - therefore I just pass them on.

(and maybe as a side remark: the code is > 11 years old. There are so many places where I think "gosh, was I drinking at the time?!?" 🤣 but I am practicing acceptance and try to balance time on features vs. refactoring. I try to do the same with the Java 17 upgrade - there are many place that could benefit from new language features, but I apply them as I touch files).

Marfir commented 1 year ago

Yes. Sonar mostly mark lines that contains arrays because it's unsecured. It's also not improving the performance if you need to change manually the size of an array again and again.

I'm using jFreeChart in my project as long as I remember: https://www.jfree.org/jfreechart/samples.html With it you are not forced to using arrays. Yes I know this problem with huge old code base. My astronomy project has currently ~113k LoC (Java). It's only possible to using the 'boy-scout rule' to handle it.