News for hackers. Stuff that matters.
Re:Think in Math, Write in Code by onion2k on Thursday July 18, 2019 @06:27AM (#20468408)
I think single letter variable names are fine within the scope of a single function.

I don't. One of the things I like most about eslint is the id-length rule - https://eslint.org/docs/rules/id-length

Re:Think in Math, Write in Code by skohan on Thursday July 18, 2019 @08:50AM (#20469201)
I think it depends. In the context of a complex mathematical formula, where you have many intermediate results with very abstract meanings, I think it's more clear to use a single character name than to try to be descriptive with something like: `productOfLuminanceAndDotProductOfSurfaceNormalAndLightDirectionDividedByScatteringConstant`.

I think there are a lot of advantages to abiding by styling conventions and using linters to set a baseline, but there are always exceptions to the rule.

Re:Think in Math, Write in Code by onion2k on Thursday July 18, 2019 @10:30AM (#20470160)
* productOfLuminanceAndDotProductOfSurfaceNormalAndLightDirectionDividedByScatteringConstant*

Note that the id-length rule also allows you to limit the maximum length of a variable name. This is why.

Re:Think in Math, Write in Code by skohan on Thursday July 18, 2019 @10:37AM (#20470253)
I understand that, but what in your mind would be a good replacement to name such a complex, abstract value? A long acronym perhaps? I don't see how that's any more clear or less arbitrary than a single character name.
Re:Think in Math, Write in Code by wa1987 on Thursday July 18, 2019 @11:16AM (#20470685)
Agreed. I'd much prefer something along these lines as opposed to using an overly long name:

`

/* product of luminance and dot product of surface normal and light direction divided by scattering constant */

const prod = ...

`

Re:Think in Math, Write in Code by mruts on Thursday July 18, 2019 @10:29AM (#20470139)
I find that I can reason about code more effectively the shorter the variable names are. Rob Pike writes the same thing in the Practice of Programming.