Closed pixelzoom closed 4 years ago
Good point. I admit that I am still a bit uncomfortable with the => function. Also, the need for some of these derived properties has more to do with my future plans than the current sim.
I've inlined all three derived property functions from the project since they are all 1 line. Thank you.
I was also initially uncomfortable with arrow functions (=>
). As someone who has studied programming languages, JavaScript is (to put it nicely) not my favorite language. It seems to invent new constructs solely for the purpose of working around features that were done poorly in the first place. Arrow functions are one such example. If they had gotten "scope" correct for functions
, there would be no need to introduce yet-another type of function construct with different scope behavior. Arrow function do have only one (dubious) advantage, and that's more compact syntax. And now, I will step down off of my soapbox :)
Related to #1 (code review).
In Lattice.js, the derivation function for
this.latticeConstantsP
is defined as a separate function:Similarly, in XrayDiffractionModel.js:
I'm guessing that there might be a misconception about how to instantiate a DerivedProperty. Unless the derivation function is used in multiple places, it's perfectly OK for it to be inlined. And it's easier to read and less likely to become out-of-sync if it's inlined.
So for example Lattice.js would become: