r/ProgrammingLanguages • • Oct 29 '26

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

1

u/arthurno1 29d ago

What is the difference between procedure and function?

2

u/ThomasMertes 29d ago

In Seed7 the type proc (=procedure) is defined as func void (=a function which returns nothing).

1

u/arthurno1 29d ago

Why? Is there something special about functions that return nothing so you need to burden the user with two terms?

3

u/ThomasMertes 29d ago edited 29d ago

If a Seed7 function returns a value the value must be used. For example:

aVariable := aFunc(something);

Writing just

aFunc(something);

leads to an error. C and other languages have the concept of voidening (the value is silently thrown away). I don't think that this is a good idea. If you want to ignore the result of a function you must do it explicitly:

ignore(aFunc(something));

Procedures on the other hand return no value. They are called with:

aProc(something);

-2

u/arthurno1 29d ago

Yes but I asked you why do you have two terms, both "proc" and "func", not why you declare a return value. You have introduced an extra cognitive burden on your users, when "func", would be completely enough. Do you have "method" too? :)

There is a fine line between classifiying and sorting exact everything, and doing it where it matters. Every "branch" you introduce is an extra cognitive load on the programmer. The art is to create a language that does not burden people where it does not matter. A programming language is typically invented for humans, to make their job of writing computer programs easier, not harder. In your particular case "func" would do in both case, since you have type information.

As an illustration, C never had "function" or "procedure" keyword, because it is not needed. A compiler can deduce on it's own whether you are declaring a variable or a type. Considering they designed the language to be compiled in 1.5 pass back in 70s when computers were quite slow, that can't be too much to ask. The biggest lesson of C is their philosophy that "use looks like declaration"; i.e there is no separate syntax to declare things compared to when you use those types and functions. The reason was of course to make it easier for the programmers to learn and use the language. C has lots of other problems of course, but they did that thing right I think. To the degree that was possible to do, of course.

3

u/Tuxinoid 29d ago

C did not make a difference between functions and procedures because the original design of C was something better than assembler - and K&R did not care very much about strong typing and such things.

Other languages did make that distinction - and it is for a reason: to prevent errors. A programmer who feels "burdened" by the distinction between procedure and function should rather look into something else than programming ...

1

u/arthurno1 29d ago

C did not make a difference between functions and procedures because the original design of C was something better than assembler - and K&R did not care very much about strong typing and such things.

That is a massive oversimplification dude and historical inaccuracy.

The K&R very much cared of typing. C did not omit the distinction simply because it was "better assembler" or out of apathy for typing. C evolved from BCPL and B, which were typeless languages. Early C did not even have a void type; everything defaulted to returning an int. This was a pragmatic design choice aimed at simplifying the language grammar and the compiler for 1970s hardware, specifically for systems programming. They still though gave you types and had type checking, that was one of the big improvements of C compared to what it was replacing B and BCPL.

Other languages did make that distinction - and it is for a reason: to prevent errors.

Older languages like Pascal enforced a strict keyword distinction (procedure vs. function) to clarify intent and prevent assigning empty results to variables, but modern compiler theory has made this obsolete. Today's strictly typed languages (Rust, Go, Swift, Kotlin, Java) unify them under a single concept (functions/methods). They prevent errors using return types like void, Unit, or () which proves that a robust type system does not need this vocabulary distinction at all. In other words, less is more still holds.

A programmer who feels "burdened" by the distinction between procedure and function should rather look into something else than programming ...

This is just ignorant and stupid gatekeeping, that actually does not deserve the answer since it borders to trolling. By asserting that developers who dislike this distinction shouldn't program ignores the entire development of modern language design, which you so believe you are supporting. The industry has almost universally abandoned the procedure/function split because unified abstractions are cleaner. Relying on type signatures rather than distinct keywords is the standard for safe, modern software engineering.

2

u/ThomasMertes 29d ago

Yes but I asked you why do you have two terms, both "proc" and "func", not why you declare a return value. You have introduced an extra cognitive burden on your users, when "func", would be completely enough.

Yes, func would be completely enough and proc is just a shortcut for func void

proc is shorter, but nobody hinders you to forget about proc altogether and use func void everywhere instead.

Seed7 and its libraries define many types (see here). Currently the Seed7 manual lists 49 types and proc is just one of them. You don't need to know all these types when you start programming in Seed7. Beginners just need a few of them:

$ include "seed7_05.s7i";

const proc: main is func
  begin
    writeln("hello world");
  end func;

You see: At the beginning you don't need to know func. :-)

1

u/arthurno1 29d ago

proc is shorter, but nobody hinders you to forget about proc altogether and use func void everywhere instead.

You now what they say about design:

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away."

-- Antoine de Saint-Exupéry in The Little Princ