wow
I'm looking through CovidSim.cpp and:
C:
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif
This is
literally the example they give of why macros are bad
C:
//// soc dist
if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative place contact rates over time given social distancing by place type", "%lf", (void*) &P.SD_PlaceEffects_OverTime[0][0], P.Num_SD_ChangeTimes * P.PlaceTypeNum, 1, 0))
for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) //// by default populate to values of P.SocDistPlaceEffect
for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++)
P.SD_PlaceEffects_OverTime[ChangeTime][PlaceType] = P.SocDistPlaceEffect[PlaceType];
//// enhanced soc dist
if (!P.VaryEfficaciesOverTime || !GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Relative place contact rates over time given enhanced social distancing by place type", "%lf", (void*) &P.Enhanced_SD_PlaceEffects_OverTime[0][0], P.Num_SD_ChangeTimes * P.PlaceTypeNum, 1, 0))
for (int ChangeTime = 0; ChangeTime < P.Num_SD_ChangeTimes; ChangeTime++) //// by default populate to values of P.EnhancedSocDistPlaceEffect
for (int PlaceType = 0; PlaceType < P.PlaceTypeNum; PlaceType++)
P.Enhanced_SD_PlaceEffects_OverTime[ChangeTime][PlaceType] = P.EnhancedSocDistPlaceEffect[PlaceType];
There's endless amounts of this kind of copy-pasted code, just hand-written array copies or very simple things like "multiply by a constant". C'mon, if you're not going to use any C++ features to encapsulate this in a class method or something, at
least write a "do X to all array slots" function that takes a
pointer.
C:
int GetXMLNode(FILE* dat, const char* NodeName, const char* ParentName, char* Value, int ResetFilePos)
For the love of God, they're parsing XML
by hand, on disk by scanning through the file with C-style I/O. Why?!
Note the lack of any sort of stack here - if you ever happened to have a tag with the same name inside of your targeted tag this would break.
C:
if (P.DoUTM_coords)
{
for (i = 0; i <= 1000; i++)
{
asin2sqx[i] = asin(sqrt(((double)(i)) / 1000));
asin2sqx[i] = asin2sqx[i] * asin2sqx[i];
}
for (t = 0; t <= 360; t++)
{
sinx[(int)t] = sin(PI * t / 180);
cosx[(int)t] = cos(PI * t / 180);
}
}
This little bit of premature optimization just tickled me - let's precalculate some trig tables for degree values!
EDIT: Oh wow, I just noticed that t is a
double here! That's right, just step it like it's an int one-by-one, I see no problem with that
C:
char buf[65536], txt[65536];
I was vaguely surprised that this is allowed - since when can you allocate that much on the stack?
Also, check out the RNG library for some
vintage 1980s C code - even including gotos!
Looking forward to seeing everyone's favorite nonsense out of here.