r/ProgrammingLanguages • u/Luroqa • Jan 24 '26
Discussion Why don't any programming languages have vec3, mat4 or quaternions built in?
Shader languages always do, and they are just heaven to work with. And tasty tasty swizzles, vector.xz = color.rb it's just lovely. Not needing any libraries or operator overloading you know? Are there any big reasons?
110
Upvotes
View all comments
Show parent comment
31
u/alphaglosined Jan 24 '26
Optimising backends do a lot of pattern matching to determine what optimisations to do.
And yes that also includes things like matrix multiplication.
You as a compiler developer working on a frontend, are unlikely to beat what backend developers can do here. They have target-specific information, and they are constantly changing the backend to improve codegen.
For mathematics like this, the context is in the expression/IR, you don't need to attribute anything to it for the backend to recognise it.
Library types that represent mathematics like linear algebra are very likely to optimise to pretty close to the maximum for the target these days. Auto vectorisation has improved a lot over the last 15 years and is no longer awful.
I have been able to in the past, match the codegen of handwritten assembly and intrinsics by simply writing D code more or less naively.