Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> That all programming languages, down to statically typed assembly, don’t support something as simple to validate as unit consistency [...]

Many programming languages are flexible and strong enough support this. We just don't do it by default, and you'd need libraries.

Btw, units by themselves are useful, but not enough. Eg angular momentum and energy have the same units of Newton * metre, but adding them up is not recommended.



> Eg angular momentum and energy have the same units of Newton * metre, but adding them up is not recommended.

The unit of angular momentum is kg.m^2.s^-1, you're thinking of torque. Although even then we distinguish the Newton meter (Nm) from the Joule (J) even if they have the same dimensionality.


Thanks, yes, I meant torque.

Well, 1 J = 1 Nm, the differentiation you mention only helps humans a bit, but would be really hard to make work for a computer.


I don't think it would be too difficult for a computer to handle. We already deal with situations like float(1) = int(1), it doesn't seem any harder to handle torque(1) = energy(1).


The problem is that you want torque not being equal to energy.

Specifically you have:

torque = force * distance

energy = force * distance

The only difference being that in the former the farce is perpendicular to the distance, and in the latter it's in line with the distance.

A vector based system could distinguish the two, but you don't always want to deal with vectors in your computations. (And I'm fairly sure there are problems where even using vectors ain't enough to avoid this problem.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: