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

7

u/Kaisha001 Jan 24 '26

The same could be said of any standard library... or even any language. Perhaps we should all be programming in asm?

At some point if something is common and stable enough (ie. there is really only one proper implementation most of the time), then there doesn't seem to be any reason not to support it.

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

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.

1

u/slicxx Jan 24 '26

I see where you're going, but more often than not, things are semi-built-in. The title asks why it's not built-in. I assume my definition of built-in is too literal, meaning usable without import. But standard libs (or standardized libs) do often exist and have big functionality.

I think a great example is the C language here. They want to stay minimal and portable, and of course stay close to the machine, only one hop away from ASM. No dynamic vectors exist, because growth handling, memory and error management, performance and so on do matter but in different ways for different use cases. But a simple "type" is one makro or a few lines of header files.

And for the n-D types? Different types (int, float32/64..) can be easily implemented but they would at least need different paddings inside to be efficient in cache.. A Vector3 is used in a widespread use, but in no way are they universal. They are highly domain specific, so let's just keep it in the math library, game engine or shading language which will hopefully be "optimally" compiled for the use case. And these environments all come with the type.

All about hitting the sweet spot between implementing nothing and delivering it all.

3

u/Kaisha001 Jan 24 '26

I assume my definition of built-in is too literal, meaning usable without import.

Fair enough, it was rather ambiguous. I assumed standard library type stuff.

And for the n-D types? Different types (int, float32/64..) can be easily implemented but they would at least need different paddings inside to be efficient in cache.. A Vector3 is used in a widespread use, but in no way are they universal.

There are SSE/AVX types on near every platform now. It's not an impossible task.

2

u/slicxx Jan 24 '26

You got a very strong point with SSE/AVX, so the reason might just be legacy for many languages nowadays, but it still makes sense for some hard typed languages to focus on the minimum.

Interesting discussion, now i wonder where the limits are and why we aren't pushing further in this direction, especially since a lot of things can be hidden from the user anyways or rather aggressive, maybe be compiled out if it isn't necessary.

1

u/Kaisha001 Jan 24 '26

TBH I'd prefer we just had better compute drivers, so HLSL/GLSL could become generic parallel languages, that could be run on the CPU, or GPU, or some combination.

1

u/slicxx Jan 24 '26

Yeah no way i'd like to touch GLSL when i had other options. In university, we coded our own operating system. This was painful for an average of 7.5 hours a day for about 5 months straight. But it was almost peaceful compared to the time we were forced to learn what is happening behind CUDAs curtains in my masters program. It was then and there, i decided to only do games engineering as a minor instead of my masters subject and just stick with Intelligent Systems because i didn't want to ruin my brain. A friend from uni started to work as a firmware developer for one of nvidias vendor companies... He will retire after roughly 7 years of experience but is about to get his second burnout diagnosis, i can see it in his eyes.

All of that, and we still have no real platform that crosses GPU and CPU universally outside of big data and gaming.

2

u/Kaisha001 Jan 24 '26

All of that, and we still have no real platform that crosses GPU and CPU universally outside of big data and gaming.

It is something I would love to see.