r/ProgrammingLanguages • • 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

132 comments sorted by

View all comments

Show parent comment

1

u/arthurno1 Jan 26 '26

The idea that we can't support vec3/4 because someone might want vec19 seems silly to me.

That is exactly the case because game dev is a niche. A chemist would want their own types, and a mechanical engineer would want their own types, and a natural language researcher would want theirs, and everyone would want their own types. Guess what? Sometimes, these types would collide with each other and be similar but slightly different. Whom will you cater?

The answer is exactly: none. You give them tooling so they can introduce they own types as they need them. This talk is by the one of the most famous language designers or our time and deals exactly with these questions. Highly suggested.

1

u/Kaisha001 Jan 26 '26

Whom will you cater?

Well first vec3/4 are not 'gamedev' types, they are linear algebra types. Linear algebra is found everywhere. There's a reason reason why CPUs/GPUs have native linear algebra types and instructions is that is it near ubiquitous across computing.

The answer is exactly: none.

Linear algebra is used far more than any other field of mathematics apart from basic arithmetic. x86 has SSE/AVX, arm has NEON/SVE/SVE2, PowerPC has VMX/VSX, even the old MIPs line of chips and tiny MCUs like the ESP32 S3 (Tensilica Xtensa vector instructions). They're all basically the same thing, because linear algebra is near universal.

Even GPUs, which are used for FAR MORE than just graphics, and their associated languages, which have wildly different architectures, still have vec3/4 ect... as their base types.

For something so universal and stable, I don't see any good reason for languages to not support them.

1

u/arthurno1 Jan 26 '26

Linear algebra is used far more than any other field of mathematics apart from basic arithmetic.

You still haven't had your course on mathematical analysis I see?

x86 has SSE/AVX, arm has NEON/SVE/SVE2, PowerPC has VMX/VSX, even the old MIPs line of chips and tiny MCUs like the ESP32 S3 (Tensilica Xtensa vector instructions). They're all basically the same thing, because linear algebra is near universal.

Intel's SSE/SSE2 came as a direct effort to accelerate computer graphics after their first "multimedia extensions" were not very successful. Later on we have got extensions to those that work with bigger vectors than just 4 dimensional. I am so old that I actually remember when Intel launched them.

They're all basically the same thing, because linear algebra is near universal.

What you seem to confuse is that you equal linear algebra with three and four dimensional vectors. Three and four dimensional vectors and matrices are used in linear transformations and projections, used most famously in CG. In other words it is an application of linear algebra. They are just but a small and specialized subset, and those specialized cpu extensions dealing with 3- and 4-dimensional vectors are there so computers are better equipped with dealing with computer graphics.

There are other areas and other applications of linear algebra where we use other vector dimensions and other tools than linear transformations for projections, rotations etc.

Even GPUs, which are used for FAR MORE than just graphics, and their associated languages, which have wildly different architectures, still have vec3/4 ect... as their base types

GPU started as a tool to accelerate computer graphics and developed from there. Today they can also work with much bigger types than 3- and 4-dimensional vectors. vec3 and vec4 in shader languages and graphics APIs are for the convenience, not because they are basic building stones of gpus.

For something so universal and stable

Three and four dimensional vectors are used mostly in computer graphics, which is just but one area of applied linear algebra. They are not "so universal" as you think. There are other areas of applied lin algebra where we use much bigger vectors than three and four dimensional vectors and matrices.

I don't see any good reason for languages to not support them.

If you actually cared to look at the provided link and video you could perhaps gain some more insight instead of weaving with hands and providing word salad about topics you don't seem to even understand properly.

1

u/Kaisha001 Jan 26 '26

You still haven't had your course on mathematical analysis I see?

And here I thought we were having a discussion... Are there not enough places on reddit to troll that you have to take it here?

What you seem to confuse is that you equal linear algebra with three and four dimensional vectors.

No, it's just that is very common and also easy to implement in hardware. IE. it's the most mature implementation.

GPU started as a tool to accelerate computer graphics and developed from there.

Well aware, but just because they started in graphics, doesn't mean that's where it ended. Why that matters is beyond me.

vec3 and vec4 in shader languages and graphics APIs are for the convenience, not because they are basic building stones of gpus

Not originally. The older GPUs used SIMD. It wasn't till a bit later that NVidia introduced SIMT. But how it's implemented under the hood is secondary to programming languages. The reality is vec3/4 are common, convenient, efficient, mature, and used in many applications beyond 3D graphics. Hence why they are still kept around.

They are not "so universal" as you think.

They're not including 4D SIMD in Arm or Tensilica cores for 3D graphics.

If you actually cared to look at the provided link and video you could perhaps gain some more insight instead of weaving with hands and providing word salad about topics you don't seem to even understand properly.

We've hit peak irony. Coming from 'vec3/4 can only be used for 3D graphics' guy? Perhaps if you made it past grade 10 math you'd realize that linear algebra spans far more than just transforming triangles.

Stupid and toxic... reddit never fails to amuse.

1

u/arthurno1 Jan 26 '26

Are there not enough places on reddit to troll that you have to take it here? Stupid and toxic... reddit never fails to amuse.

Jesus Christ.