Mathematics should learn from programming standards

You’re the one who brought that example to the table. I just responded to it. Bring in some different examples or languages if they would illustrate your point better.

Having had this conversation many times, I anticipated your question “So should we switch languages”. I went to the trouble to preemptively address it in my reply. Behold!

So… I’ll happily continue this discussion of readability, once you demonstrate an adult grasp of the pre-requisite of… you know… reading.

Yep, I saw that, but you then ended with:

If your point was not that the language was the “real” problem, why bring this up at all?
So what then is the “real” problem with the 10 line function?

Suppose that a major-league pitcher throws a 100 MPH fastball, right over your head, so close that it messes up your hairdo. Does it hurt? Of course not. Why not, given that the ball was moving very fast? Because it was still moving nearly as fast right after its encounter with you: Its velocity had almost no change, so its acceleration was almost zero, and so, by F = ma, it had almost no force exerted on it (and hence, by Newton’s Third Law, it likewise exerted almost no force on you). Did it have a significant acceleration at some point before that? Sure, while the pitcher was throwing it, because then, his hand was exerting a force on it.

Now, there are other quantities in physics which do depend on mass and velocity: Momentum is mv, and kinetic energy is 1/2 mv^2 . But those are both different things from force (and from each other), and you’d be looking at them for different reasons, to answer different questions. If the baseball does hit you directly in the face or the gut or whatever, it’ll be momentum that determines if it knocks you over, and kinetic energy that (more or less) determines how much it hurts.

To point out for the Nth time (sorry, I guess I should save time by writing “timesThatIHaveSaidThisTh time”) that best practices are context-dependent, not universal.

It’s difficult to judge code I haven’t seen. I can only speak to my process and experience. From your high-level description, the verbosity seems unusually high for the purpose. As a general principle, before I try to make code pretty, I want to make it smaller. Smaller blocks are easier to understand than large blocks, they are easier to isolate and test than large blocks. Deleted code can’t fail.

But let’s say, for argument’s sake, that this function is as good as it can be. Let’s even say there’s a 5% bonus for speed-reading these 10 times of code. How often are we going to recoup that benefit? How often are we going to decide that “LetsReverseSomeText” has a new responsibility? I would suggest that if the answer is anything more frequently than “never”, this changes the character of the discussion entirely.

Saving a nickel on a transaction only matters in proportion to the frequency of the transaction. Context matters.

I’m struggling to reconcile these two posts:

You seem to imply that 10 lines of code to reverse text is a problem, like that number of lines to achieve that operation is a problem. But you also agree that we can’t just change programming languages because some other language can do it in one line.

These are the things you seem to be saying:
1 - 10 lines of code to reverse text is somehow related to the “real” problem (as opposed to the variable names)

2 - Ruby can do it in one line - so that is somehow related to the “real” problem

3 - But you admit we can’t just change languages chasing localized advantages and swapping out codebases

4 - And you can’t judge code you haven’t seen (which is fair)

But, there is a “real” problem with the code that you can see.
I’ll let you off the hook, you should have just stated “hmm, 10 lines seems like a lot for that function”, as opposed to stating so adamantly that you can see the “real” problem.
Here’s the code by the way:
public static void xxx(final boolean array,
final int startIndexInclusive,
final int endIndexExclusive) {
if (array == null) {
return;
}
int i = startIndexInclusive<0 ? 0 : startIndexInclusive;
int j = Math.min(array.length, endIndexExclusive) - 1;
boolean tmp;
while (j > i) {
tmp = array[j];
array[j] = array*;
array* = tmp;
j–;
i++;
}
}

I stated that the variable naming probably isn’t the problem. We seem to have a bad disconnect with you inferring things I didn’t say, so instead of talking about that, let’s talk about the code:

It’s Java? Okay then. Apache Commons has a widely used library that can accomplish that in 1 line(not counting the unavoidable Java boilerplate, but that doesn’t really contribute to the variable naming issue anyway).

So, the Real Problem diagnosed: reinvention of wheel. Prescription: use commons.lang, as Java programs typically do. Variable confusion: gone.

I asked you three times what is the “real” problem. You avoided answering it every time. Why didn’t you just answer the question to clear things up?

LOL. The example code above was taken from that exact library.

Why do you keep playing hide-the-ball? Why are you asking me to critique something without seeing it? Why weren’t you forthcoming about even the language you were talking about?

What point do you believe that you have made here? That you can’t lose an argument if you conceal the thing you’re arguing about? This has departed the realm of good faith; I’m out.

Many forms of mathematical notation could certainly be better and there have been attempts to reform some of them, but the nature of maths means that being economic with the number characters so that the important idea sticks out. This sounds to me like a solution in search of a problem.

Take the definition/identity below definition/identity of the Christoffel symbols of the the 2nd kind, which I’ve delibrately chosen as it is not easy to understand without a little bit of study of the relevant area of maths and in several ways it could be argued that the notation is confusing, but is still used because of its relative economy of symbols (in the context where it is often used, general relativity, it would represent 64 equations with 12 terms in each, though some of those equations would turn out to be the same). Could the OP give indication where they would make it more descriptive?

Γ[sup]i[/sup][sub]kl[/sub] = ½g[sup]im[/sup](g[sub]mk,l[/sub] + g[sub]ml,k[/sub] - g[sub]kl,m[/sub])

Where:

Γ[sup]i[/sup][sub]kl[/sub] is the (i,k,l)th component of the Christoffel symbols of the 2nd kind

g[sup]im[/sup] is the (i,m)th component of the inverse metric tensor

g[sub]mk,l[/sub]/g[sub]ml,k[/sub]/g[sub]kl,m[/sub] is the partial derivative of the (m,k)th/(m,l)th/(k,l)th component of the metric tensor with respect to the lth/kth/mth coordinate.

NB m is a dummy indice and is summed over.

You stated the “real” problem wasn’t the variable names.

I asked what was the “real” problem multiple times.

You ignored it until you provided the impossible but pretty entertaining answer about using the very library that the devs were creating.

And you conclude that it was somehow my fault?

That it was funny (thus the LOL)

There was and is no argument, just a simple question about what you meant when you said the variable names aren’t the “real” problem.

A person asking you to explain your statement isn’t an argument, it’s a one sided request for more information.

I’m still confused about what you originally intended when you said that.

What would the exchange have looked like if it was in good faith?

Can you point to anything specific that was in bad faith?

It is a well-accepted principle in CS that programs are harder to read than to write: that programs are harder to understand than to conceive: and that if you write a program that is as clever as you can make it, it will be too clever for you to debug.

One of the reasons math is hard is because you have to study the subject enough to memorize the symbology before you can read for content.

Because the topic is not about specific code. You made a broad claim about variables in every computer language. You argue that descriptive variable names are not useful (except in certain limited cases).

RaftPeople provided direct links to studies to show this is false. Using descriptive variable names greatly sped up comprehension of code in multiple studies. You then moved the goalposts to proving that using 10 lines of code to reverse a string is wrong.

Once again, a blanket claim about all code everywhere, not about any specific code. And one that seems especially ignorant since you assumed the context was one where existing libraries were available, rather than the actual code for those libraries. And it completely ignores the purpose of the study which was about understanding the code, not about whether said code was the best possible code.

You’re arguing something that is at odds with programming practices pretty much everywhere. Descriptive variables are the norm in every project I’ve seen. Because they make code easier to understand. Yes, comments can be good, too. So is structure. So are a lot of things. Good clean code has a lot of factors.

Descriptive variables are part of good clean code, and taught in every introductory course I’ve ever seen, as well as any book trying to guide people. And there is science–not just your personal opinion–to back that up.

You’re asking me what it would look like if you argued in good faith? Apparently we’re never going to know.

Can you point out where I posted something that wasn’t in good faith?

Really, you don’t see the self-contradiction in the criticism “you made a universal claim! With EXCEPTIONS”? Come on.

If we were discussing as adults then we could have separately treated the case “What if you don’t have a library”? Instead, he omitted the context and the result was “Gotcha! You don’t have libraries!” :rolleyes:

If you find that kind of gotcha tactic informative, let me pose one of my own: Go to that github repository where the code is stored. Fork it and make a pull request. Submit a patch demonstrating how the variables in the code ought to be better named. Let’s see what the maintainers/community have to say about it.

There’s a really easy way to put your money where your mouth is. Who’s up for it?

How could it possibly be a “gotcha” when I still don’t know what your original point was about the “real” problem. For some reason you felt compelled to post publicly that the vars aren’t the “real” problem but you still haven’t stated what the “real” problem was. Unless your reinventing the wheel problem you mentioned later was the original problem. But it’s unclear because of the wording in your later post sounded like it was a new analysis, vs the original.
Either way, it was a funny coincidence. I had no idea the researchers used that code, but I knew they pulled their code from a production source so I thought I would check and it turned out that is where they got it. Pretty damn funny don’t ya think?

Nobody said the variables in that code I showed you are bad.

The researchers modified that code and replaced all of the meaningful variable names with letters like a, b, c, etc.

After they did that, comprehension time was 2x to 3x (jumping from something like 2 to 8 minutes to 7 to 19 minutes (depending on the specific person)).

This isn’t unheard of with embedded systems and legacy code. At the fundamental level, any Von Neumann architecture has a limited number of actual variables - one for each register, an array for memory, and a stream for the external storage medium. If you make the jump from opcodes to mnemonics, there are still no meaningful variable names. Meaningful naming, as opposed to implimentation-specific standards (such as ecx for iteration), does not enter the picture until you add a linker to resolve labels.

I compare ‘pure’ mathematics with ‘pure’ computer science - older papers that have to describe machine code. Is it harder to understand? Yes. But the intended audience and the purpose is different too - they are written for the mathematics community, which demands that everything is well defined. A mathematics paper won’t say “plug this into your favorite hash function”, it must fully define the formula referenced or point to a specific publication that defines a specific formula. Once you start building layers of abstraction, and assume your audience is familiar with these layers, it ceases to be ‘pure’ mathematics and becomes a much more specialized field.

~Max

HMS Irruncible, when the question is “How do you write a straightforward function”, then the answer “you don’t, you use the library function” is critically flawed, precisely because someone still had to write the library function. RaftPeople, with your inadvertent help, just very succinctly pointed out that flaw.

“Mathematics” is a bit vague, but I can tell you as someone who has a degree in programming and make sure I use descriptive variable names when appropriate, who’s also taught high schoolers math and physics, that I do not want a reform replacing simple symbols in high school math and physics.

I also wonder if there is anyone who doesn’t just call their iterators i, j or n in loops?

Developing and understanding of math and physics involves a lot of working with and rearranging an increasing number of variables by hand. Who wants to derive

d = v_0 t + 1/2a*t^2

from v = v_0 + a*t and d = (v_0 + v)*t/2

using descriptive variable names.

Sure you should introduce velocity = distance/time in middle school with those terms, but it’s simply not viable to work like that at higher levels.

Even if you do start writing Energy_total = massacceleration_due_to_gravityheight + .5massvelocity^2 and that simplifies some aspects of understanding the formula, it’s still the case that some aspects requires you to have previous knowledge, and that previous knowledge might as well include the conventional symbols.

I’m sure plenty of people use longer descriptors - anybody who uses an iterator or for-each pattern as opposed to a loop counter (cx/ecx, i/j/k).

Let me google that for you: iterator - Google Search

The first result is “How to use Iterator in Java? - GeeksforGeeks

And there we see in all it’s beauty a class named “Iterator” instantiated with the descriptor “iterator”:


Iterator iterator = list.iterator();

~Max