3 ms·
You could offer to rewrite if for them... It's an implementation of a mathematical algorithm. It doesn't need allTheVariables toBeNamed likeThis. Single letter
by nicky0 10y ago
You could offer to rewrite if for them...
It's an implementation of a mathematical algorithm. It doesn't need allTheVariables toBeNamed likeThis. Single letters map to meaningful concepts in the mathematical algorithm.
I don't see how giving the variables longer names would make it more readable. Indeed I think long variable names would obscure the structure.
Code like this has to be looked at in the concept of the algorithm design (which I hope exists...)
- B1FF_PSUVM 10y agoIt's funny, because there's a whole couple of generations out there that have been taught that explicitVariableNames will fix their thinking deficit. I mean, if it weren't sad.
- johncolanduoni 10y agoOr maybe they think it'll just help other people (including future you) read the code? Like was claimed?
- pilif 10y ago> You could offer to rewrite if for them... Nope. Because I can't read it. I plainly do not have the information needed to understand what's going on here, nor is the design document part of the source code. As you seem to have no trouble understanding what's going on, can you enlighten me, for example, what's so special about the number 271 that we see M being compared to? > I don't see how giving the variables longer names would make it more readable. Variables that are part of the algorithm itself probably make sense in their short name (though that's a common problem with math in general. Being more expressive isn't a bad thing), but there are also parameters to public API that are equally short for no gain. Also, the code is full of magic numbers and I'm sure an algorithm design document would at least give names out to them. Besides, even if the document was available (it isn't, at least not to the public), there's absolutely zero harm in making the code more accessible or at least reference the spec.
- nicky0 10y agoOK but which is more readable ... (I know it's a bit silly, I juts made up names) } else if (D >= (1 << 14) || M == 0 || (x + 3) + M > 34) { } else if (DirectWeightingFactor >= HUYGENS_LIMIT || MariachiBand == 0 || (xylemNonce + STANDARD_PZSH_INCREMENT) + MariachiBand > SWIM_RATE_B) { I guess your opinion differs to mine. I like the one that looks like math.
- pilif 10y agoWhat about a middle ground? } else if (D >= HUYGENS_LIMIT || M == 0 || (x+3)+M > SWIM_RATE_B)
- Ralfp 10y agoAnd then somebody else will write angry hackernews comment how code is abysmal because it mixes in single char names. ;)
- randlet 10y agoThe more verbose name is infinitely more preferable to me. If I am tasked one day with doing some maintenance on this code and have never encountered it then at least I have a hint that I should be researching the aquatic properties of mariachi bands.
- dietrichepp 10y agoI would have a hard time with that, the long names hide the structure. Know your audience. Do you expect future maintainers for your compression algorithm to be people with knowledge of compression algorithms? Or do you expect them to be random programmers off the street?
- josephg 10y agoAs someone who's written and maintained code like this, in my experience the heavy algorithmic parts themselves usually requires almost no maintenance. Its the surrounding code - the API endpoints, makefiles and test suites that need to be modernized every few years. Algorithms like this are written, then used, then better algorithms are written from scratch. Code like this also usually can't be edited piecemeal. Any change requires reloading the entire algorithm into your head before a single line is changed. And as others have mentioned, the normal way to do that is to read the paper. .. And if you do that, the paper's naming convention becomes the natural way to express the algorithm.