4 ms·
Part of the problem here is that a variable in mathematics is a different concept from a variable in programming. Mathematicians are used to using one letter v
by drdec 5y ago
Part of the problem here is that a variable in mathematics is a different concept from a variable in programming.
Mathematicians are used to using one letter variables. Using a set of unwritten naming rules, mathematicians almost always know what concepts the variables are referring to (in a mathematical context).
So, I'd say if the code is only to be maintained by mathematicians, one letter variables for mathematical concepts only, would be an advantage.
The danger comes when you start using them for everything.
- nanis 5y ago<disclaimer>Not a mathematician, but took enough Ph.D. level classes to be dangerous with bad proofs.</disclaimer> > Using a set of unwritten naming rules Simplest being things like using upper case Greek for certain sets and lower case Greek for its elements. Or, in Statistics, using Greek letters for parameters and English equivalents for their estimates. So, if I were programming something to do something in that realm, I would write: for my $ω ($Ω) { # ... } where what Ω represents would be clear from the subfield of Math that is relevant to the program. Then, of course, you get people like one of my former professors who liked to invent notation on the fly and would quickly and up cycling through Greek (π, Π), Hebrew (פ), Blackboard (ℙ), and reach out for Sanskrit (?). (Symbols used here for illustration, this was a long time ago and we didn't even know if he was correct as we had no way of checking with no intarwebs back then.)
- Quekid5 5y agoI'm also under the impression that mathematicians generally work much more deeply with a smaller set of variables, so you actually don't need to name that many individual concepts. A typical program contains thousands and thousands of "named things", so you're naturally going to see a proliferation of names. That just doesn't seem to be that necessary in math once you're working in a particular context (e.g. statistics).
- kennywinker 5y agoTranslation: i learned my domain’s variable names, so you should have to as well. Currently learning some dsp. One of the biggest barriers to entry has been the inscrutable variable names inherited from the field’s math connections.
- kaba0 5y agoFeel free to reason about a complex statistics formula with full-blown variable names. There are reasons for short variable names. Pass into a specific function a descriptive name of what you do, but do use the mathematically "accepted" writing mode in the implementation of a well-known function.
- kennywinker 5y ago> There are reasons for short variable names Which are? I suspect the reasons are a combination of the price of paper and ink, the history of teaching using chalkboards. None of those mean we can’t make the canonical version of an equation the expanded representation. Why do we all know e=mc2 and not energy = mass * lightspeed^2. The broader the base of people that have to interact with a formula, the less mathy the terminology tends to be. Think of trigonometry. Instead of greek letters the sides of a triangle and the functions get real world names. Sine(angle) = opposite / hypotenuse. Sure when you write that out you use sin ϴ = O/H but that’s just a compressed representation of human-readable variable names.
- kaba0 5y agoHow about Gauss’s distribution’s density function? Or a numerically stable version of a simpler formula? Also, you forgot the usual case of implementing a whitepaper with mathematical notation. It is much easier to proof read that, when you copy largely the same in your program as well. And if you pass in the readable energy, mass, etc variables, inside the function you can use the domain-specific mathematical notation. That way it will be readable both outside and inside.
- 5y ago