4 ms·
I don't disagree that badly-written scientific code exists (both in academia and in the industry), but I want to point out a couple of things for people who hav
by ubasu 11y ago
I don't disagree that badly-written scientific code exists (both in academia and in the industry), but I want to point out a couple of things for people who have only a software engineering background.
1. Keep in mind that most scientific code for numerical analysis, being based in mathematics, follows the convention for using algebraic symbols, e.g. even in physics, we write
F=m*a
instead of the wordy version, which we overcame a couple of centuries ago. So using shortened variable names [1] comes from that background, and using longer names as in Java-world seems like a regression.
2. Writing code like [2]
Ax_1 += Bx_1 + Cx_1 # Add Bx_1 to Cx_1
Ax_2 += Bx_2 + Cx_2 # Same thing, but for Ax_2
Ax_3 += Bx_3 + Cx_3 # "
Ay_1 += By_1 + Cy_1 # "
is known as loop unrolling [3,4] and is used for optimization.
[1] https://news.ycombinator.com/item?id=10539078 https://news.ycombinator.com/item?id=10539078
[2] https://news.ycombinator.com/item?id=10540446 https://news.ycombinator.com/item?id=10540446
[3] https://en.wikipedia.org/wiki/Loop_unrolling https://en.wikipedia.org/wiki/Loop_unrolling
[4] http://stackoverflow.com/questions/2349211/when-if-ever-is-loop-unrolling-still-useful http://stackoverflow.com/questions/2349211/when-if-ever-is-l...
- chrisseaton 11y agoWhy isn't your compiler unrolling your loops for you?
- ubasu 11y agoModern compilers should, but there is a lot of legacy code.
- ambiate 11y agoI don't know why this is getting down voted. I've come across near duplicates of this code and its always "that's how we did it after punch cards."