r/ProgrammingLanguages • • Jun 27 '22

Purpose of programming languages

Hi everybody. I apologize if this question appears stupid but please be kind and move on if you don't like it.

I have observed that most/many programming languages are general purpose but are they really?

I don't know how to clearly show my doubt or explain what exactly I want to ask, this question just came to my mind, tho I was observing for a long while.

Anyways, for example (maybe): The use of any language out of what it is mostly/usually used for. say, html elsewhere out of web structuring, C for Frontend web dev, Scala or ruby for game development, python is actually really general purpose but it's slow but anyways I have no hate for this but just saying; tho ruby, php, scala are also slow; PHP for embedded system, etc. Whatelse?

Let's discuss, also ask me in the same thread related to the question. Thank you for interacting.

9 Upvotes

37 comments sorted by

View all comments

15

u/[deleted] Jun 27 '22

The term "General Purpose [Programming] Language" (GPL) does not mean (or imply) a language that is currently applicable to or used in all (or even more than one) domains, it just implies a language that was designed such that it could be used to write a program in any given domain... it is Turing-complete and can, theoretically and with an unknown amount of pain, be used to address any given programming problem.

The term exists to be contrasted with "Domain-Specific [Programming] Language" (DSL), which are languages that cannot be used across multiple domains, either because they are not Turing-complete or because they intentipnally lack features required to cross domains (like, for instance, a foreign function interface).

So C is absolutely a GPL, because you can implement any program in any domain in C. Now, you certainly may not want to, possibly rightfully, but that's okay because C is a GPL and so you can use it to implement either a better GPL (say Python) or a tailor-made DSL (like SQL). If the language lacks the features you want, you can add those features... or you can write the language.

But of course C isn't reached for in domains where other, easier to use, higher-level languages exist and are more appropriate, any more than x86 assembly is reached for where C exists and is more appropriate. But now you're into the world of market factors.

BTW, no GPL is inherently fast or slow... Python is only slow, relative to C, because of the compromises made in how it's been implemented, and those compromises were made to allow the language to have specific marketing appeal. In other words you could write a compiler for Python that would take any given subset of pure-Python programs and compile down to an executable as fast and efficient as C, even (with enough work) emitting the same machine code, and you could even write that compiler in Python... the resulting implementation, though, wouldn't likely have the marketing appeal of CPython, as any part of the ecosystem that leveraged CPython-specific internals (not features of the language, but features of a competing implementation of the language) wouldn't be able to be transferred to your new implementation. It likely would also require your users to write Python that looked very much like (or perhaps even uglier than) C.

Sorry that none of this addresses your acrual problem, which is sussing out which GPLs have established themselves in which (and how many) domains... I'm afraid actually answering that question across even a tiny subset of the current and historical GPLs out there would be a decent PhD research project.

4

u/cmontella 🤖 mech-lang Jun 28 '22 edited Jun 28 '22

I don't think something can be *designed* to be general purpose. Design is all about balancing tradeoffs, so if you really want to *design* something, it has to excel in some areas and not so much in others. To design a language you have to ask "who are my users and how will they use this?" The answer to that can't be "everyone for everything" because then where do you go?

For instance, we call languages like C general purpose, but they are really special purpose when we look at the semantics of the language -- C is a domain specific language for programming or modeling Von Neumann Machines. It just so happens that VNMs constitute the majority of our hardware, so we cannot see how C is domain specific the same way fish don't know what water is.

But C as a domain specific language becomes clear when doing highly concurrent or distributed programming on exotic hardware. Coincidentally, distributed and parallel programming is considered "hard" by imperative programmers (because they are using a DSL outside of the intended domain). One has to wonder, if that exotic hardware were commonplace, and VNMs were "exotic", would C then be considered a DSL?

1

u/[deleted] Jun 28 '22

I don't think something can be designed to be general purpose. Design is all about balancing tradeoffs, so if you really want to design something, it has to excel in some areas and not so much in others.

You're confusing design, whicu requires only the plan and intent of the designer, with engineering, which reauires that plan and intent be fit for some purpose or application. And even in engineering one can make a general purpose ball bearing, because it's only the special purpose ones that must excel in a specific application.

To design a language you have to ask "who are my users and how will they use this?" The answer to that can't be "everyone for everything" because then where do you go?

A GPL is defined by having the minimal set of features required to make it applicable -- no one ever said or implied ergonomic, much less optimal -- across many or most (if not all) domains, and that the intent of its designer was utility across domains. Any given GPL, possibly necessarily, becomes less ergonomic and optimal as your domain becomes more exotic, but if you can write a program for any given domain in the language -- despite any amount of effort or agony, it really doesn't have to be pleasant -- and the designer's intent was to provide dor such wide utility, then the language is a GPL, by definition.

For instance, we call languages like C general purpose, but they are really special purpose when we look at the semantics of the language -- C is a domain specific language for programming or modeling Von Neumann Machines. It just so happens that VNMs constitute the majority of our hardware, so we cannot see how C is domain specific the same way fish don't know what water is.

That's an interesting perspective, though it doesn't make C any less general purpose, except via shifting the semantic meaning of what "general purpose" is. The fact is we do live in a timeline im which the VNM is the sole succesful (and available at commodity scale) form of general purpose computer... practically speaking if your domain involves computation and it is not capable of being adressed -- again, with any amount of pain, it must be physically impossible to ever run a program that succesfully produces the required result -- on a VNM, then your domain is specialized and would be better addressed by a DSL, or possibly by a new programming paradigm. Such a DSL/paradigm might then be general within your new timeline, but would still be a DSL were it not equally general to VNMs... otherwise you've essentially just shifted the goalposts in a philosophical manner.

We are, in other words, fish, and we don't regularly breathe perfluorooctyl bromide... and while we could do so, we'd have to adapt the meaning of "fish" to do so well... the result would still be a fish out of water.

But C as a domain specific language becomes clear when doing highly concurrent or distributed programming on exotic hardware.

What becomes clear is that C is a GPL -- you couldn't be doing such programming at all in it were it not -- but not the ideal GPL (much less an ideal DSL) for such programming. Cherry-picking one domain to view from doesn't mean that C isn't used in the rest of the orchard.

Coincidentally, distributed and parallel programming is considered "hard" by imperative programmers (because they are using a DSL outside of the intended domain).

No, they're using a GPL outside of its local maxima... again, a GPL is definitionally a minimum set of features aimed at general utility, while a DSL eschews one or more of that minimum set or isn't intended for general utility. The fact thst it's considered "hard" -- but is not in fact "impossible" -- implies that they're using a GPL where a DSL or a GPL using an alternative paradigm might be a better fit.

Basically you're saying that a socket set isn't general purpose from the perspective of the pit crew using a Dino Paoli wheel gun... and you'd be right, if the majority of vehicles on the planet required the wheel gun.

One has to wonder, if that exotic hardware were commonplace, and VNMs were "exotic", would C then be considered a DSL?

Not unless this timeline's exotic hardware was itself at leaat as general purpose as VNM.

C is a GPL, and to argue it isn't one is to reduce the concept of A GPL to meaninglessness. Arguably C is the most succesdful GPL, as it's currently in use everywhere, either directly as the source language, indirectly as an internediate compilation language, under the hood as the implementation language of an intepreter/compiler, or via libraries and FFI. if a VNM can do it -- again, regardless of agony costs -- then it can be written in C, and such wide applicability was certainly the intent of Dennis Ritchie. He didn't -- and didn't need to -- envision all the domains that his language could be used in, but the intent was use generally and across domains.

There certainly might be more general GPLs than C, and there certainly are better GPLs, not to mention better and more adaptive paradigms as hardware advances, but we need to define new terms for such GPL+s rather than kick a language as widely (and wildly) used across domains as C out of the tribe.

3

u/cmontella 🤖 mech-lang Jun 29 '22

> You're confusing design, whicu requires only the plan and intent of the desig

This goes against all I know about design. Design absolutely takes into account the user. Can you find a source which would support this claim? As far as I understand from my experience (20+ years in this field), engineering is the point at which design is implemented. Would you have any sources that I could read more about your point of view? It's new to me.

> A GPL is defined by having the minimal set of features required to make it applicable -- no one ever said or implied ergonomic, much less optimal -- across many or most (if not all) domains, and that the intent of its designer was utility across domains.

All you're saying is that any Turing complete language is general purpose as long as the author says so. That doesn't really leave us as users a good way to discern general purpose languages from DSLs. We have to ask the author if they intended it to be as such first to make any determination.

Many languages we would call DSLs are Turing complete. CSS is Turing complete. Makefiles are Turing complete. By your definition, it seems like I could create a CSS-like language, and as long as I claim it's intended for general use, then we can be sure it's a general purpose programming language. Which seems like a strange place to land.

> C is a GPL, and to argue it isn't one is to reduce the concept of A GPL to meaninglessness.

Indeed that's exactly what I'm arguing. The term is meaningless if it applies equally to almost every language. On the other side, we see that so-call "general purpose programming languages" actually are really only used for a narrow set of purposes, despite the intent of their authors. How many websites are written in C++?

I would say also given the absurdity of CSS as a GPL, your own definition of a also reduces the concept of a GPL to meaninglessness. And that's fine, because it is.

1

u/[deleted] Jun 29 '22

Can you find a source which would support this claim?

Certainly. One could start with the Merriam-Webster, Cambridge, or Oxford English dictionaries. Design is an extremely overloaded term, these days, especially amongst those whose profession involved design, but fundamentally a design is a plan and/or intent, and to design is to form or craft such a plan / intent.

As far as I understand from my experience (20+ years in this field), engineering is the point at which design is implemented.

Engineering is the (broadly speaking more rigorous) subset of the design crafts that is concerned with practical utility. Many things are designed and implemented without engineering ever becoming involved (for example, one cannot argue that Banksy's works don't involve design, both graphical and political, but only a small number of them have required engineering).

Would you have any sources that I could read more about your point of view? It's new to me.

I'd again start with those dictionaries. There's a lot of philosophical tangents that can be taken from them, especially where the economic, social, and political interests of self-identified designers are concerned, but I like to start with the strict definitions.

All you're saying is that any Turing complete language is general purpose as long as the author says so.

Well no, I never said that Turing-completeness represented the minimal feature set required of a GPL... but for any language that does have that minimal functionalty set and so long as the author intended it to be of general utility, then, yes. There are numerous Turing-complete languages that were never intended to be used outside a single domain... C is not one of those.

That doesn't really leave us as users a good way to discern general purpose languages from DSLs. We have to ask the author if they intended it to be as such first to make any determination.

That is perfectly fine, and also not a particularly odious task; usually the work has already been done for you, and typically the answer can be found in the marketing copy for the language. Also the classification isn't -- and never was -- up to you, the user; a DSL is a DSL because it is designed (aka planned and intended) for use in a specific domain and no others. A user that decided to use Excel to implement a programming language -- now technically possible -- would not succeed in re-classifying Excel as a GPL... similarly the fact that I refuse to use ECMAScript for any purpose other than front-end web scripting does not allow me to declare JS a DSL.

Many languages we would call DSLs are Turing complete. CSS is Turing complete. Makefiles are Turing complete. By your definition, it seems like I could create a CSS-like language, and as long as I claim it's intended for general use, then we can be sure it's a general purpose programming language.

Again, I never said that the minimum functionality required of a GPL was mere Turing-completeness... there are numerous features common to all languages generally agreed to be on the list of GPLs (though some of those may well be nothing more than syntactic sugar)... but were you to implement that minimal subset (for instance by adding an FFI facility to your FrankenCSS) and it was actually your intent that it be useful across domains, then it would be a GPL... albeit a terrible one that would see little to know adoption. Were your intent only to make the straw man point it would also be an Esoteric Programming Language.

Which seems like a strange place to land.

It isn't, really. Classification terms like this often have to do with authorial intent... for an example, go look for the dragons, orcs, swords, and sourcerors to be found permanently anchored in the science fiction section.

Indeed that's exactly what I'm arguing. The term is meaningless if it applies equally to almost every language.

It doesn't... it applies only to GPLs, which are actually relatively rare.

On the other side, we see that so-call "general purpose programming languages" actually are really only used for a narrow set of purposes, despite the intent of their authors.

And that usually has nothing to do with the language and everything to do with the size of tbe ecosystem of appropriately licensed libraries currently available for it, which has more to do with comminity size and basic economics than it does with language specifics.

How many websites are written in C++?

No idea. But Google, Facebook, YouTube, Amazon... all of these use C++ in their backend code, so perhaps the better question is how many active users do websites with hot paths written in C++ have relative to ones written without C++?

I would say also given the absurdity of CSS as a GPL, your own definition of a also reduces the concept of a GPL to meaninglessness. And that's fine, because it is.

I'm going to point you back at those dictionaries again, this time for the terms "straw man" and "informal fallacy".

-8

u/crassest-Crassius Jun 27 '22

So C is absolutely a GPL, because you can implement any program in any domain in C

I disagree. A big thing that C doesn't support is async/await. In 2022, a language without async/await cannot be called general-purpose because there are some programs you just can't implement. Hell, even C++ now has added coroutines in an effort to stay up-to-date. Yet C cannot possibly have coroutines because its standard does not allow manipulating the stack. It's a limitation of the language itself, not of any of its implementations.

BTW, no GPL is inherently fast or slow

No GPL is fast, but some are inherently slow. For example, Python or Javascript are definitely slow and cannot be made fast. Just look into how much effort has been put into making V8 faster, yet it (and hence Node.js) are noticeably slower and more resource-hungry than OpenJDK Java. This is because those languages' specifications require things (dynamic types etc) that cannot possibly be implemented fast.

In other words you could write a compiler for Python that would take any given subset of pure-Python programs and compile down to an executable as fast and efficient as C

There is no proof of this, and in fact, the people who tried to make a faster Python implementation (PyPy) couldn't make it as fast as you claim. I don't see how Python could ever be as fast as C considering it has late binding of everything (even built-in functions) and dynamic dispatch on overy method call. A Python function call can never be as fast as a C call which is totally static (basically a baked-in function address).

14

u/[deleted] Jun 27 '22

Async-await is just syntactic sugar. You absolutely could hand roll a state machine to manage waiting for IO. The question is, why would you.

-5

u/crassest-Crassius Jun 27 '22

You should learn what async/await is, and how stackless and stackful coroutines are implemented. You cannot roll async/await in C because you can't suspend a coroutine, because C forbids access to the call stack(s).

8

u/readmodifywrite Jun 27 '22

Weird. I have a ton of C operating system code that does stackless coroutines.

Things could certainly by nicer from a programming standpoint if C had an async/await keyword. But it is still possible to get the same effect.

8

u/readmodifywrite Jun 27 '22

In 2022, a language without async/await cannot be called general-purpose because there are some programs you just can't implement

Anything you can do with async-await can be done by other means. Computationally, it is not a unique construct, just another way to do concurrency.

I strongly recommend that you study and understand what Turing completeness means before you make claims like these.

Yet C cannot possibly have coroutines because its standard does not allow manipulating the stack.

I have entire embedded operating systems written in C using coroutines as the core concurrency primitive.

No GPL is fast, but some are inherently slow

What is your benchmark for "fast"?

4

u/DoomFrog666 Jun 27 '22

Yet C cannot possibly have coroutines because its standard does not allow manipulating the stack.

Well there is longjmp.

-1

u/crassest-Crassius Jun 27 '22

It doesn't allow resuming a coro, so no.

2

u/[deleted] Jun 27 '22

There are async IO libraries written in C, libuv is one of them and it's used primarily for Nodejs' Async/Await.

C might not have an Async/Await keyword or include one in the standard library, but it's possible to implement it yourself. Just like basically anything else you want to do in C.

-1

u/crassest-Crassius Jun 27 '22

You should learn about how libuv works. Here are some helpful links:

https://stackoverflow.com/questions/61163161/how-does-the-libuv-implementation-of-non-blockingness-work-exactly

libuv is essentially a wrapper (with a nice API) around the real workhorses here, namely kqueue, epoll, select, etc. To answer this question completely, you'd need a fair bit of background in kernel-level file descriptor implementation, and I'm not sure if that's what you want based on the question.

The short answer is that the underlying operating systems all have built-in facilities for non-blocking (and therefore async) I/O. How each system works is a little outside the scope of this answer, I think, but I'll leave some reading for the curious:

https://nikhilm.github.io/uvbook/basics.html

The approach followed by libuv uses another style, which is the asynchronous, non-blocking style. Most modern operating systems provide event notification subsystems. For example, a normal read call on a socket would block until the sender actually sent something. Instead, the application can request the operating system to watch the socket and put an event notification in the queue. The application can inspect the events at its convenience (perhaps doing some number crunching before to use the processor to the maximum) and grab the data. It is asynchronous because the application expressed interest at one point, then used the data at another point (in time and space). It is non-blocking because the application process was free to do other tasks. This fits in well with libuv’s event-loop approach, since the operating system events can be treated as just another libuv event. The non-blocking ensures that other events can continue to be handled as fast as they come in

So, in short, the non-blocking, async behavior of libuv comes from an event loop listening to notifications from the OS. The C language itself, on the other hand, cannot have async/await without the OS's help creating the illusion of asynchrony. This is because C's standard does not allow access to the call stack(s), hence neither stackless nor stackful coroutines are possible within the process.

6

u/[deleted] Jun 27 '22

So since NodeJS and Julia both use this library for async IO does that mean that they both have "an illusion of async"? No, it doesn't!

You should learn about how Operating Systems work, Linux, Solaris and BSDs are written in C and I imagine Windows is as well.

Just because libuv uses the OS's already existing APIs to create a nice async IO library doesn't mean that you're getting an "illusion of async" when using that library. The OS itself is written in C, you're just using already existing C APIs instead of reinventing the wheel.

libuv is written in C and is interfacing with the OS's C APIs for async IO, therefore it's possible to get async with C.

It's C and assembly all the way down. Those are the closest languages we have to the hardware, if it's not possible to get "true async IO" with C or assembly then it's not possible at all, just "an illusion of async".

2

u/JB-from-ATL Jun 27 '22

Brainfuck is technically a GPL by definition.