• Forum
  • Lounge
  • Whats the point of different programming

 
Whats the point of different programming languages?

Pages: 12
I was randomly going through the day and I wondered why there isn't one universal language that every system runs, for instance people/companies could just export .h files or whatever the language uses for things like so.
Generally, the answer is because either the language is designed for a specific purpose, or its flaws (regardless of how real they are) get in the way of universal adoption.

The closest thing we have to a universal language is C. Most operating systems have large parts of their code written in it (which isn't likely to change for a long time) and practically every compiled language supports linking with C libraries.

-Albatross
I wondered why there isn't one universal language that every system runs

There is, to an extent. It's called C.
But C is not sufficient for every kind of problem. So there's other tools for use when needed.

Simultaneously, a universal programming language should
- be highly portable
- offer excellent control of the machine
- be simple enough for the average developer to understand well
- supply abstractions sufficient to express algorithms elegantly and correctly
- be quick enough to use and still make money
- be hard to abuse, and resistant against subtle bugs
- Maybe there's more
Such a language would be at least tremendously difficult if not impossible to design. The above qualities are contradictory, maybe not inherently so, but at least with respect to the computers we're familiar with.

C itself attempts to satisfy the first three at the expense of the others. C++ tries to improve upon C's qualities, but at the cost of complexity. C++ compilers are less common than C compilers. Other languages try to balance these qualities differently, and to support different approaches to problems, but I don't believe any one is suitable for everything.
Last edited on
Whats the point of different programming languages?


Why was C++ created, using the base language C?

To solve problems easily that would require excessive code in C, if the problems could be solved at all.
You might look into Meme theory. I'm not talking about pictures with catchy phrases, but the actual theory that was created over a decade before the internet.

It's the evolution of an idea that I'm talking about. C evolved into C++, it doesn't mean that C has died off or ever will, but C++ found a strong foothold and was able to spread successfully. Java has also found a place where it can thrive, and it is also sending out little excursions into other domains. Look at what is happening with JavaScript, it's all over the internet and is growing at a surprising rate despite it's limitations.

A meme that is fit to survive is one that serves a purpose. Fire, the wheel, electricity and the light bulb. A programmable computer is comparatively a new technology and no language has yet fulfilled every possible frontier.

Memes abhor a vacuum.
Last edited on
Yeah there's a lot of reasons for different languages. Some are just experimental, built to illustrate a particular programming style, some are just accidental, created during the course of some big project but they leak out and people start using them for real. You've got some like Smalltalk that were a great idea at the time, but the hardware didn't support them, or politics or whatever killed them. Then there are some that are just created by people showing off how smarty pants they are, which only get used by a few people here and there. And of course, there's C#, MS' attempt to own their own proprietary version of Java, so there are commercial reasons for inventing languages and I'm sure there are plenty of those languages flying around.

As for a universal language, there is one universal language for every microprocessor, which is its native instruction set.

I agree there should be just one - Java is one that has a compiler for almost everything, though that's more than a "language" probably, in technical terms. And as has been noted, C and C++ compilers are widely available.

"The nice thing about standards is that you have so many to choose from." - unknown who was the original purveyor of this pearl of wisdom.

I feel the same way about soap.
"The nice thing about standards is that you have so many to choose from."

https://xkcd.com/927/
Isn't xkcd just awesome? I like this one:

http://www.explainxkcd.com/wiki/index.php/179:_e_to_the_pi_times_i
There is a lot of different programming languages, each used for different purposes. There can't be one universal language for everything.
Some of these comments are a bit odd.
I would assert that if a problem can be solved on a computer, then it can be solved in assembly language. If it can be solved in assembly language, it can be solved in C and C++ (along with many, many others). It may be more difficult to solve that one might like, of course. C and old C++, the programmer spent a LOT of time making 'libraries' to enable coding the actual problem at hand, hand-rolled data structures and whatnot. Ive got an ancient matrix library in old c++ that lets you write a = b+c or a = b*c and tons more ... and it serves as a great example.

consider just a = b*c;
to do that in C, you have to write something horrid like
a = matrixmultiply(b, c);
which isnt too bad. Except equations get hairy, right?
Now try to write
a = !( (b+c)*(d-e) ) where ! is transpose...

it becomes a = transpose( matrixmultiply(matrixadd(b,c), matrixsub(d,e)))
and quickly becomes pure gibberish to someone trying to turn many complex equations for a control theory problem into meaningful, readable, debuggable code.

Here, operator overloading and classes make c++ much better than C, though you could DO it in C.

Some of the help for people on this site show the reverse. Many simple 2-3 line C programs explode into a huge complex mess in modern c++. One of the best examples is just trying to do

printf("%1.20f, %5.10f\n", a,b);
which becomes something huge and unreadable like
cout << setw << setprecision << other << a << setw << setprecision << b << endl;


Last edited on
1
2
3
printf("%1.20f, %5.10f\n", a,b);
which becomes something huge and unreadable like
cout << setw << setprecision << other << a << setw << setprecision << b << endl;


Excellent example jonnin! I completely agree. I only use C++ features when they more efficiently and simply solve a coding issue - which they sometimes do and sometimes don't.

The situation with C++'s evolution from C is that attempting to do OOP in C was syntactically messy. Messy as h***! Sure structs could allow for having members as functions through function pointer syntax, but it was a syntactic nightmare involving function pointers and macros to attempt to clean it up.
Many simple 2-3 line C programs explode into a huge complex mess in modern c++. One of the best examples is just trying to do

printf("%1.20f, %5.10f\n", a,b);
which becomes something huge and unreadable like
cout << setw << setprecision << other << a << setw << setprecision << b << endl;
Your call to printf() may or may not be correct depending on the types of a and b. Incorrectly calling printf() triggers undefined behavior. For example, printf("%s", some_integer). The std::cout version will at worst only fail to compile. There are still some ways to cause undefined behavior (for example, by passing a char * that points to an unterminated string), but it's generally more difficult.

On the other hand, in modern C++ there's nothing preventing you from implementing a new_printf() function that does what printf() does, but much more safely.
new_printf("%1.20f, %5.10f\n", a,b);
new_printf() could use variadic templates to safely convert its parameters to the correct representation.

D's also evolution from C++ (Java is too)
I was randomly going through the day and I wondered why there isn't one universal language

You could also ask what is the point of different human languages. Why not have just one language? Saves a lot, if you need no translations or interpreters.

(Of course, you cannot ask that in english, which is hardly "the one universal language". Esperanto, maybe.)


If you can have only one of something, it may be "best" for some purposes, but not for all. Denying diversity decreases the chance of coming up with something better. We had it better. We did live in the sea. Cursed be the oddball that stranded and climbed to the trees?
Whats the point of different programming languages?
Each is adapted to the needs of their environment (or the hubris of the author). They evolve in much the same way spoken languages do,
to complicate everything
C isn't a Universal Language because there isn't one. It may rule in domains C++ developers might be interested in, but WhatsApp use Errlang, the web Javascript, Relational DBs SQL and so on for a reason.

See point 4 in mbozzi's post above.
helios wrote:
new_printf() could use variadic templates to safely convert its parameters to the correct representation.


Could I point out that std::printf (cstdio) is different to the C printf from stdio.h. From the C++14 draft standard n4296: (maybe this exists in earlier standards too, I didn't check)

17.2
The C standard library
[library.c]
1 The C ++ standard library also makes available the facilities of the C standard library, suitably adjusted to
ensure static type safety.
2 The descriptions of many library functions rely on the C standard library for the signatures and semantics
of those functions. In all such cases, any use of the restrict qualifier shall be omitted.


I wonder, to make it statically type safe (generate errors at compile time), did they change it from using C style variadic function arguments to C++ variadic template arguments?
std::printf() can't be made statically type safe (even when the contents of the format specifier is known at compile time) by using only the core language features available to a library implementer. (The type of a string literal does not depend on what the literal contains.)

Currently, checking the type and number of arguments to std::printf() and friends, and issuing a diagnostic if the validation fails (GNU with -Wformat, microsoft by default) is done by the compiler (not by the library; so this facility is available in both C and C++).

There are dozens of type safe C++ printf implementations (a github search for 'printf language:C++' yielded 78 hits); these perform format string checks at run-time.
It's a shame that it's not (yet?) possible to process string literal template parameters.
 
printf<"%d">(42);
Pages: 12