OpenSees Cloud
OpenSees AMI
Right, then Left
Original Post - 10 Nov 2023 - Michael H. Scott
Visit Structural Analysis Is Simple on Substack.
I don’t expect every OpenSees contributor to be an expert coder, but I see some dubious coding more frequently than I should. And when I see questionable coding practices, I will call out the offenses so that maybe, just maybe, someone else will consider leaving the cargo cult.
For example, the author of CargoConcrete23 wrote the following code in the constructor to make sure f’c was always positive.
double temp;
temp = fabs(fc);
fc = temp;
But, one line is all it takes.
fc = fabs(fc);
In C++, and every other useful programming language, the compiler will evaluate the right-hand side of an expression first, then write the result into the left-hand side. There’s no need to define a temporary variable.
Maybe the author wanted to lead the compiler to water, but the compiler already knows how to drink.