r/ProgrammingLanguages • • 29d ago

How programming languages approach graphics

Many general-purpose languages delegate graphics to third-party libraries (like SDL, Raylib, or OpenGL). Seed7 integrates portable 2-D graphics right into its standard library. This IMHO improves portability. I also thought about introducing operators / statements to do graphics, but until now I don't use operators or statements to do graphics.

29 Upvotes

81 comments sorted by

View all comments

Show parent comment

2

u/ThomasMertes 29d ago

Does it improve portability?

Yes, if you use 2-D graphics.

If you write a graphic program with X11, GDI, GL or Vulkan you probably need at least 100 lines of code to set up the graphic library, handle events, define callback functions, etc. Did you know that REDRAW / EXPOSE events exist, which tell the program: Some part of your window has been erased. In case of these events the program needs to redraw the erased parts. Imagine if that happens to data in your program: "Some of your data is now garbage, you need to restore it now." Graphic libraries think that this is normal.

The Seed7 graphics library does all that background work for you. So the Seed7 graphics library is not only portable, but it removes some burden from the shoulders as well.

Graphics API's move moderately fast

For this reason Seed7 supports 2-D graphics, an area which has not progressed so fast. This way Seed7 is well suited to write retro games (these games run in the browser - just click on them).

7

u/tsanderdev 29d ago

For GL and especially Vulkan 100 lines is a massive understatement lol. There are projects like webgpu and sdl gpu that reasonably abstract 3d graphics though, but of course it's a lowest common denominator.

6

u/Valuable_Leopard_799 29d ago

But if you're writing portable graphics you can use a portable library. It doesn't need to be part of the standard library.

Why couldn't this Seed7 graphics library be in userspace and expose the exact same functionality?

2

u/tsanderdev 29d ago

Ideally the standard library isn't just magic builtins anyway but mostly a first party library in the language itself that's guaranteed to be available.

1

u/Dykam 29d ago

I meant to imply that point too, but I should have been explicit about it.

1

u/ThomasMertes 28d ago edited 28d ago

But if you're writing portable graphics you can use a portable library.

In this case you need to ensure that this portable library is installed when you move your program to a new computer.

It doesn't need to be part of the standard library.

The Seed7 standard library is guaranteed to be always available.

Why couldn't this Seed7 graphics library be in userspace and expose the exact same functionality?

The Seed7 graphics library is not in kernel space.

There are driver libraries written in C, which interface the graphics library of the operating system. On Linux X11 is interfaced, on Windows GDI is interfaced, and in the browser JavaScript is used.

When Seed7 is compiled the corresponding graphics driver library is used.

If a Seed7 program calls a graphic function the C function of the driver library is called, which checks parameters and then calls one or more functions from the graphics library of the operating system.

As described in the previous post a lot of maintenance work is done by the graphics driver library as well.

Edit: The X11 and GDI libraries are not in kernel space either. Kernel space would refer to the operating system kernel. None of the libraries mentioned in this discussion are in kernel space.

2

u/Valuable_Leopard_799 28d ago

But if you're writing portable graphics you can use a portable library.

In this case you need to ensure that this portable library is installed when you move your program to a new computer.

The stdlib has the same issue, either you are compiling it in which solves it for both, or you depend on something being installed on the target machine. By portable library I meant something in Seed7.

The Seed7 standard library is guaranteed to be always available.

That is of course a very good point, but it's a trade-off.

Why couldn't this Seed7 graphics library be in userspace and expose the exact same functionality?

The Seed7 graphics library is not in kernel space...

And a userspace Seed7 library wouldn't have to be either. I'm used from my languages to having portability libraries where you get a subset of all the possible features but the library is able to target, any of a number of backends based on your needs. The backends being the C libraries for one example, but it could be anything else.

The choice is of course up to any ecosystem to make, it just seems that one of the stated pros of having it in the standard library was "portability", which wouldn't necessarily be the case, unless I'm missing something big.

1

u/ThomasMertes 28d ago edited 28d ago

And a userspace Seed7 library wouldn't have to be either.

I am not sure I understand your term "userspace library" correctly as all the libraries we are talking about here are in userspace (and not in operating system kernel space).

Can it be that you use "userspace library" for libraries written in Seed7 as opposed to libraries written in C. Is this your definition of "userspace library"?

Many languages provide libraries which are operating system dependent. For example an X11 library which is just available under Linux and a win32 library which is just available under Windows. Based on these lower level libraries a higher level library could provide a portable graphics API. Maybe you would use the term "userspace library" for this higher level library.

By design Seed7 has no operating system dependent libraries. There is neither an X11 library nor a win32 library. This guarantees that it is impossible to write Seed7 programs, which run just under Linux or just under Windows. This is the precondition for the claim that it is impossible to write non-portable programs in Seed7. Every Seed7 program is automatically capable of running on all supported platforms.

This design forces that system dependent parts of the runtime library are not available to Seed7 programs. This is the reason driver libraries (written in C) exist. The Job of these driver libraries is: Abstract everything that is operating system dependent away.

0

u/arthurno1 28d ago edited 28d ago

I am not sure I understand your term "userspace library" correctly.

If you don't understand the difference between "userspace code" and "userspace library" and system calls and system libraries, you shouldn't be in the business of desining "systems programming languages" and software libraries at all.

Neither win32 nor X11 are systems library, they are both user-space libraries.

Just to give you a taste of your own rhetorics, which you so happily used in another thread. I suggest lookup what those terms mean. Since you have LLM:ed your entire "programming language" and "libraries", you can perhaps ask LLM to give you the answer. I am sure it will be unfortunately more knowledgable than you.

1

u/ThomasMertes 28d ago edited 28d ago

The general purpose language Seed7 is based on my Diploma thesis and my PhD thesis and has been released in 2005 long before LLMs were a thing.

1

u/arthurno1 28d ago

Very cool; how did you get a PhD if don't understand difference between user-space and kernel-space? Both x11 and win32 are user-space libraries. They are "system dependent", but they are user-space.