(un)descriptive variable naming



  •      int NUMBER_OF_ELEMENTS;
        float *x,  *y,  *xp,  *yp,  *dist,  *dist1,  *M,  *N;
        float s1x, s1y, s2x, s2y, A;
        float midx, midy;
        float p0x, p0y;
        float lambda;
        float min_n, min_m, m1, n1;
        float D, hh;
        float temp, minimum;
        int m, n;
        int twodfftsize;
        int twodfftsizeM, twodfftsizeN;


        NUMBER_OF_ELEMENTS = (int)ArraySpec.ArrayElement.size();
        lambda = fft_elements.lambda;

    --snip 20 or so lines of initialization--

        //Sort the rows of [xp yp dist] by distance
        int zzz = sort(dist, xp, yp, NUMBER_OF_ELEMENTS);

        s1x = 0;
        s1y = 0;
        s1x = fabs(xp[1]);
        s1y = fabs(yp[1]);
        //s1x = xp[1]; s1y = yp[1];

        int iiii = 2;
        s2x = 0;
        s2y = 0;



  •  That variable naming doesn't really seem that bad to me.  You just need to have the original mathematical function that that code is based on as the variables seem to be named for the variables in that original function.



  • Meh... throwaway variables. We do this all the time... in our code you'll see lots of "foo" and "bar" and "JimmysWifeIsATramp" variables - usually a counter or something. It's obviously just a temporary spot to store something that isn't very important, so it doesn't need a descriptive name. TRWTF is the apparent lack of any naming convention at all.



  • zzz and iiii are kind of dumb. The rest of it looks fine.



  • Needs more Spectate. ' 10-08-02



  • @DescentJS said:

    You just need to have the original mathematical function that that code is based on

     

    I sort of agree, now if I could only find that mathematical function.

     

    [quote user="jasmine2501"]

    Meh... throwaway variables

    [/quote]

     

    This is all the variables in the function, which goes on for another 300 lines.  

     



  • @noitcif said:

    @DescentJS said:

    You just need to have the original mathematical function that that code is based on

     

    I sort of agree, now if I could only find that mathematical function.

    The Real WTF is that whoever wrote this didn't include the function they were replicating in a comment.



  • @noitcif said:

    now if I could only find that mathematical function.

    Looks like you are doing a 2-dimensional Fast Fourier Transform of dimensions M and N? besides iii and zzz, they are all pretty standard notation ... I guess the file name was no help in this?  



  •  What's so special about NUMBER_OF_ELEMENTS? That's what I'd like to know.

     Funny how that's the sort of thing you can happily get away with calling n.

     



  •  @rad131304 said:

    @noitcif said:

    now if I could only find that mathematical function.

    Looks like you are doing a 2-dimensional Fast Fourier Transform of dimensions M and N? besides iii and zzz, they are all pretty standard notation ... I guess the file name was no help in this?  

     

    Thanks, that actually helps.  I guess I'm TRWTF for not knowing what FFT stands for.  But to answer your question, no.<font size="2"><font face="Calibri">  </font></font>Method: <font face="Courier New" size="2">array_matrix</font><font size="2"><font face="Calibri"> </font></font>File: mi0cin.cpp. <font face="Calibri" size="2"></font>



  • @noitcif said:

    Thanks, that actually helps.  I guess I'm TRWTF for not knowing what FFT stands for.  But to answer your question, no.<FONT size=2><FONT face=Calibri>  </FONT></FONT>Method: <FONT size=2 face="Courier New">array_matrix</FONT><FONT size=2><FONT face=Calibri> </FONT></FONT>File: mi0cin.cpp.

    Wow, no, those names are total crap. I have to agree (somewhat) with blakey, TRWTF is not having a descriptive method/file name for exactly what was going on.

    That said, I probably would have named the method something like two_d_fft and then felt that the rest was obvious.



  • @jasmine2501 said:

    in our code you'll see lots of "foo" and "bar" and "JimmysWifeIsATramp" variables - usually a counter or something. It's obviously just a temporary spot to store something that isn't very important, so it doesn't need a descriptive name.
     

    Are you fucking kidding me?



  •  OK, so now I know this uses FFT, but I don't think its an excuse for shitty variable names that need a decoder ring.  Maybe this is why I've always hated math. 

    In a large collection of code, for anything other than counters and throwaway variables, I want a real name! With IDE auto-complete is it so hard to use 'y_Intercept' instead of 'b'?



  • It's math! It's supposed to be non-understandable </irony>

     

    Meh... throwaway variables. We do this all the time... in our code you'll see lots of "foo" and "bar" and "JimmysWifeIsATramp" variables - usually a counter or something. It's obviously just a temporary spot to store something that isn't very important, so it doesn't need a descriptive name.
    I can't understand this mindset. Are you a slow typist without autocomplete? Do you enjoy revisiting code with the single purpose of renaming variables?

    My boss is guilty of this too.

    I only do it in real throw away code — ie code that gets deleted imediately after use and is never seen by other eyes —, and even so very sparingly, as minimally descriptive variable names help one think.

     

    int NUMBER_OF_ELEMENTS;
    So is that a... "runtime constant"?



  • @noitcif said:

     OK, so now I know this uses FFT, but I don't think its an excuse for shitty variable names that need a decoder ring.  Maybe this is why I've always hated math. 

    In a large collection of code, for anything other than counters and throwaway variables, I want a real name! With IDE auto-complete is it so hard to use 'y_Intercept' instead of 'b'?

    Don't you mean 'vertical_positon_intercept'?



  • No, he meant Sys_Constant_Gratuitously_Long_Variable_Name_That_Stores_A_Real_Number_Which_Is_The_Vertical_Position_Intercept_Unless_You_Are_Using_Left_Handed_Coordinate_Systems...



  • @ekolis said:

    No, he meant Sys_Constant_Gratuitously_Long_Variable_Name_That_Stores_A_Real_Number_Which_Is_The_Vertical_Position_Intercept_Unless_You_Are_Using_Left_Handed_Coordinate_Systems...


    SysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystems sysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystems = SysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystemsFactory.newSysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystems();

    Now it's in Java! :D



  • @Xyro said:

    @ekolis said:
    No, he meant Sys_Constant_Gratuitously_Long_Variable_Name_That_Stores_A_Real_Number_Which_Is_The_Vertical_Position_Intercept_Unless_You_Are_Using_Left_Handed_Coordinate_Systems...
    SysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystems sysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystems = SysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystemsFactory.newSysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystems();

    Now it's in Java! :D

     

    I thought that was .Net as well

     



  • Same thing, different authors.



  • @noitcif said:

    OK, so now I know this uses FFT, but I don't think its an excuse for shitty variable names that need a decoder ring.  Maybe this is why I've always hated math.

    I guess I just wouldn't ask or expect somebody who didn't know how to compute an FFT to be maintaining the code that performs the FFT ... I personally think that it's kind of a WTF to roll your own FFT/iFFT. Unless you really need to control something in the implementation, writing the code is only really useful for learning about how an FFT is computed. There should be a library out there that you can pull that from in any language.



  •  @Xyro said:

    @ekolis said:
    No, he meant Sys_Constant_Gratuitously_Long_Variable_Name_That_Stores_A_Real_Number_Which_Is_The_Vertical_Position_Intercept_Unless_You_Are_Using_Left_Handed_Coordinate_Systems...
    SysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystems sysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystems = SysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystemsFactory.newSysConstantGratuitouslyLongVariableNameThatStoresARealNumberWhichIsTheVerticalPositionInterceptUnlessYouAreUsingLeftHandedCoordinateSystems();

    Now it's in Java! :D

    JohannGambolputtyDeVonAusfernSchplendenSchiltterCrasscrenbonFriedDiggerDingleDangleDongleDungleBursteinVonKnackerThrasherAppleBangerHorowitzTicolensicGranderKnottySpelltinkleGrandlichGrumblemeyerSpelterwasserKurstlichHimbleeisenBahnwagenGutenabendBitteEinNürnburgerBratwustleGerspurtenMitzWeimacheLuberHundsfutGumeraberShonendankerKalbsfleischMittlerAucherVonHautkopftOfUlm johannGambolputtyDeVonAusfernSchplendenSchiltterCrasscrenbonFriedDiggerDingleDangleDongleDungleBursteinVonKnackerThrasherAppleBangerHorowitzTicolensicGranderKnottySpelltinkleGrandlichGrumblemeyerSpelterwasserKurstlichHimbleeisenBahnwagenGutenabendBitteEinNürnburgerBratwustleGerspurtenMitzWeimacheLuberHundsfutGumeraberShonendankerKalbsfleischMittlerAucherVonHautkopftOfUlm = JohannGambolputtyDeVonAusfernSchplendenSchiltterCrasscrenbonFriedDiggerDingleDangleDongleDungleBursteinVonKnackerThrasherAppleBangerHorowitzTicolensicGranderKnottySpelltinkleGrandlichGrumblemeyerSpelterwasserKurstlichHimbleeisenBahnwagenGutenabendBitteEinNürnburgerBratwustleGerspurtenMitzWeimacheLuberHundsfutGumeraberShonendankerKalbsfleischMittlerAucherVonHautkopftOfUlmFactory.newJohannGambolputtyDeVonAusfernSchplendenSchiltterCrasscrenbonFriedDiggerDingleDangleDongleDungleBursteinVonKnackerThrasherAppleBangerHorowitzTicolensicGranderKnottySpelltinkleGrandlichGrumblemeyerSpelterwasserKurstlichHimbleeisenBahnwagenGutenabendBitteEinNürnburgerBratwustleGerspurtenMitzWeimacheLuberHundsfutGumeraberShonendankerKalbsfleischMittlerAucherVonHautkopftOfUlm();

     MPTFY.



  •  @frits said:

    @noitcif said:

     OK, so now I know this uses FFT, but I don't think its an excuse for shitty variable names that need a decoder ring.  Maybe this is why I've always hated math. 

    In a large collection of code, for anything other than counters and throwaway variables, I want a real name! With IDE auto-complete is it so hard to use 'y_Intercept' instead of 'b'?

    Don't you mean 'vertical_positon_intercept'?

    Exactly.  Math is an exception to descriptive variable names.  Why should we be more descriptive than the professors?

    OTOH, Math professors and text authors are TRWTF.

     


  • ♿ (Parody)

    @hoodaticus said:

    Math is an exception to descriptive variable names.

    I guess the answer is that for many famous equations, those undescriptive names are how the parts of the function are known. Long variable names simply clutter up an equation, reducing the legibility. Of course, there's a trade off when putting that into code, since the function is likely to be broken up and used differently.

    y = m * x + b

    vs

    vertical_coordinate = slope * horizontal_coordinate + vertical_intercept

    The first is instantly recognizable. The second uses "nice names," but it takes more time to recognize what it is.



  • @dhromed said:

    @jasmine2501 said:

    in our code you'll see lots of "foo" and "bar" and "JimmysWifeIsATramp" variables - usually a counter or something. It's obviously just a temporary spot to store something that isn't very important, so it doesn't need a descriptive name.
     

    Are you fucking kidding me?


    Have you met Jimmy's wife? I assure you it's all true.



  • @jasmine2501 said:

    @dhromed said:

    @jasmine2501 said:

    in our code you'll see lots of "foo" and "bar" and "JimmysWifeIsATramp" variables - usually a counter or something. It's obviously just a temporary spot to store something that isn't very important, so it doesn't need a descriptive name.
     

    Are you fucking kidding me?


    Have you met Jimmy's wife? I assure you it's all true.

    Hrm, I'd like to meet Jimmy's wife. :)



  • @dohpaz42 said:

    @jasmine2501 said:
    @dhromed said:

    @jasmine2501 said:

    in our code you'll see lots of "foo" and "bar" and "JimmysWifeIsATramp" variables - usually a counter or something. It's obviously just a temporary spot to store something that isn't very important, so it doesn't need a descriptive name.
     

    Are you fucking kidding me?

    Have you met Jimmy's wife? I assure you it's all true.
    Hrm, I'd like to meet Jimmy's wife. :)

    She is an ugly tramp, plus she has crabs



  • @boomzilla said:

    y = m * x + b

    vs

    vertical_coordinate = slope * horizontal_coordinate + vertical_intercept

    vs.

    int y; // vertical coordinate
    int m; // slope
    int x; // horizontal coordinate
    int b; // vertical intercept
    ...
    y = m * x + b;
    

Log in to reply