r/AskComputerScience • • Jul 12 '21

What is actual the difference between programming languages?

Maybe it's a very noob question, but in 5y i've never had a good answer. I only really developed for C# and 6502 assembly, those languages I clearly understand the difference, but to me all high level languages appear the same just with different syntax when you strip them of the frameworks and stuff (and I imagine probably isn't the case), but I see some people with very strong opinions about some languages, and doesn't make sense to me, people say "you can do anything with Python", "c++ is messy" and I really don't understand what they are refering to, anything in the same layer of abstraction looks the same to me

29 Upvotes

30 comments sorted by

18

u/Putnam3145 Jul 12 '21 edited Jul 12 '21

people say "you can do anything with Python",

you can do anything with any language

"c++ is messy"

it's nearly 40 years old and the standard has updated over the years such that a lot of the old "right way" to do things have become the "wrong way", but you still have to deal with the "wrong way" cause it being a language of medium age with widespread use means you get a lot of old code you still need to understand

anything in the same layer of abstraction looks the same to me

honestly just look at some Haskell or, hell, even Rust code and try to say the same? at least most C# programmers I've met seem to have problems with Rust's syntax, especially the stuff it basically got from Haskell

1

u/Luizaguzzi Jul 12 '21

Im not saying those things, im just quoting, and what i mean is, besides syntax, there's some difference?

4

u/Putnam3145 Jul 12 '21

I'm explaining why people say these things.

And yes, there's difference besides syntax.

C++ is primarily "manual memory management", usually using smart pointers and RAII, instead of, say, proper manual memory management, which involves explicitly allocating and deallocating, such as in C; this is technically possible in C++, but usually not preferred. Python and C# are both garbage collected.

C# has interfaces. C++ does not, but has something similar in the form of "abstract classes", classes which cannot be instantiated, only inherited from. It should be very much noted that these are not the same thing, though. Python doesn't have interfaces at all, and has duck typing. These aren't mere syntax differences, they lead to very different abstraction methods.

Python is (usually) interpreted, C# compiles to an intermediate representation which is then just-in-time compiled and C++ is compiled. These all have pretty different results: Python's usually pretty slow, C++ can be extremely fast if you use all the tools available, and C# will often be faster with "normal" code than either, though C++ will beat it if you really dig into it.

There's other stuff too, surely, but these are all tertiary languages for me. I've mostly done stuff in D and Rust.

1

u/Luizaguzzi Jul 13 '21

Thank you :) but wait, so there's high level language with manual memory access? Like register addressing and stuff? That's mind blowing

0

u/[deleted] Jul 12 '21

[deleted]

1

u/nzre Jul 12 '21

I'd take the statement as being more pragmatical, especially since this question is about languages rather than ecossystems.

17

u/nuclear_splines Ph.D Data Science Jul 12 '21

Oh, there are a boatload of ways to answer this question! Among imperative languages, we often describe languages along an axis from "low level" to "high level", as you've alluded to. While C++ provides many abstractions that C and assembly do not, it still provided manual memory management and strict types - programmers often need to think about the size of things in bytes, and when memory will no longer be needed, that you don't need to concern yourself with in higher level languages like Python. That axis is an oversimplification though, and hand waves across type systems, grammar, object oriented programming, and use-case (for example, JavaScript and PHP's close association with web programming).

Among very high level interpreted imperative languages (Perl, Python, Ruby, etc), differences are often incremental. Python 'improves' (though improvements are always somewhat subjective) on Perl by using simpler, more consistent grammar, without messy bits like automatic variables or regular expressions as a primitive operation. Ruby 'improves' on Python by providing private methods and variables, adding code blocks as a type, and borrowing more heavily from functional programming than its predecessors.

But as you point out, there are many similarities between imperative languages, and generally anything you can build in one you can build in more or less the same way in any other language. The differences are important, but not staggering. The real big differences are when you compare imperative languages to things outside that paradigm, like functional or logic languages. Alternative paradigms force you to completely restructure your thoughts and represent the problem you're solving in radically different ways out of scope for a single reddit comment.

2

u/Luizaguzzi Jul 12 '21

Thanks, that really clarified a lot of things

-1

u/awwwqweqe Jul 12 '21

What about the Lisp family?

2

u/east_lisp_junk Jul 12 '21

What about it?

2

u/nuclear_splines Ph.D Data Science Jul 12 '21

That’s in there! Lisps are dynamically typed functional languages.

1

u/awwwqweqe Jul 14 '21 edited Jul 14 '21

There are Algol languages that are dynamically typed and functional but that doesn't make them Lisps.

Common Lisp, for example, I would not describe as dynamically typed and it's not functional -in the same say Haskell is- although it can be used to write in a functional style. It also supports OO but it's not an OO language in the way that, say, Java that insists that everything is a class.

If you had to pick out distinguishing features you might pick: code is data, data is code; programmable programming language and image based development.

1

u/nuclear_splines Ph.D Data Science Jul 14 '21

I agree with all of that! But I’m not sure how we drifted here; my original comment doesn’t mention Lisp, nor does it claim that I’d described all programming languages.

1

u/awwwqweqe Jul 14 '21

You were asking about the difference between programming languages.

1

u/nuclear_splines Ph.D Data Science Jul 14 '21

Nope! That was OP. I was just listing a few ways of characterizing and differentiating them.

1

u/awwwqweqe Jul 15 '21

Either way it answers your question :)

1

u/FricketyCrickity Oct 04 '25

what? they didn't ask a question

6

u/develop-mental Jul 12 '21

It's true to say that any program can be written in any Turing complete language. So the rubber-meets-the-road difference between them is how easy a language makes it to solve a problem. And in that way, there are a ton of differences, and most are a spectrum from one end to the other.

Typing (static vs dynamic): Statically-typed languages such as Java and Go enforce a type on a variable when it is declared. Dynamically-typed languages like Bash and Python try to determine what the type of the object you've declared at runtime. It matters because not having to worry about typing can make code faster to write and possibly more readable, but it makes it easier to make a mistake.

Compiled vs interpreted: Interpreted languages allow you to run the code directly at runtime, while compiled languages require you to run your code through a compiler, which reads in the code and generates a set of machine code or an executable binary. This matters in practice because its easier to iterate quickly when writing in an interpreted language, because you don't have to recompile the code after every change. But compilers offer safety check to ensure your code won't have runtime issues, and it can also generate significantly faster code by optimizing the machine code it generates from your parsed human-readable code.

These are just 2 examples of differences between using alternate languages; there are of course many more, and it comes down to the preferences of the developer/team. But fundamentally, they can all do the same job.

1

u/Luizaguzzi Jul 12 '21

Thanks for the explanation :)

5

u/EatMeMonster Jul 12 '21

It matters because not having to worry about typing can make code faster to write and possibly more readable

You might save 10 seconds not worrying ahout typing lol, and it's all fun and games until your code crashes and you spend 10 hours tracking down a bug that could have been catched as a compiler error in a static language. (Speaking from strong personal experience.

3

u/develop-mental Jul 12 '21

Haha very true! Not a huge deal in a 10 line bash script, but it can certainly be painful in a large Python project.

Then Golang hits the other extreme, where you spend a bunch of time duplicating boilerplate code because its strong typing model precludes generics.

3

u/gilgoomesh Jul 12 '21 edited Jul 12 '21

Any language that is Turing Complete can be used to write the same code as any other Turing Complete language.

The difference is:

  1. the speed of writing code

  2. the mistakes you can make in the language

  3. the complexity of maintaining the code after it is written

All three of these are SUBJECTIVE which is why so many languages exist. Most people find that the core principles of one language or another just "click" for them in a way that the core principles of other languages do not.

Haskell eliminates certain kinds of problems due to state. Rust eliminates problems due to data races. C++ eliminates some kinds of code duplication. Swift eliminates problems due to null. And each of these type-safe languages can be written in a way that the compiler proves part of your algorithm's correctness.

But many consider these languages much slower to write in than Python or C. And some people consider maintaining code in Haskell to be impossible (mathematical syntax has a reputation for being write-only).

There's a final 2 differences:

  1. you may be using a framework that requires a specific language

  2. runtime performance or overheads

You often don't get to choose your language. Wanna write a native iOS app? Swift. Native Android? Kotlin or Java. Web app? Javascript. .NET app? C# or maybe F#. Yes, there are cross platform environments but they tend to be equally restrictive in language choice (C#, Javascript or Dart).

On top of that, you're unlikely to see a serious 3D game engine written in Python (although the game logic itself might be). You're unlikely to write embedded device code in Ruby. This matters in some cases but you'll generally know the domain your targeting and shouldn't start in an unsuitable language.

1

u/DerKnerd Jul 12 '21

Web app? Javascript

At least that changed since WASM.

1

u/gilgoomesh Jul 12 '21

I'm yet to encounter a team that is using WASM. Anecdotally, it does not yet appear to have much momentum.

1

u/DerKnerd Jul 12 '21

Absolutely, but now there are options. The project I am in nearly took blazor, but we thought we have to support IE and so WASM was no option...

2

u/turtle_dragonfly Jul 12 '21 edited Jul 12 '21

While in some sense you can do anything in any language, there are significant differences in how easy it might be to do, and how idiomatic and maintainable the code will be.

Even something simple like doing OO programming (in the C++/Java/etc. sense) — yes, you can do it in C as well, but you have to handle having a "this" pointer yourself. The language does not do that for you.

One feature that I really liked from Perl was having closures. Python did not have direct support for "real" closures until 3.0, with the "nonlocal" keyword. C++ didn't have these until lambdas were introduced in C++11. Many languages still don't have them. Yes, you can "implement your own closures", but it is much more clunky if you don't have built-in language support.

Some other things: exceptions, garbage collection, coroutines, first-class functions, pattern-matching of types.

There are also differences in the specifics of a given feature, even if multiple languages have it. For instance: most languages have the notion of a "function", but this is significantly different from a "pure function" in the Haskell/Erlang/etc. sense. In those languages, because they have built-in support for the concept of a "pure function" (which is guaranteed to have no side-effects) the tools can handle them in ways other languages cannot — eg: parallelizing without worrying about side-effects. You can certainly write a side-effect-free function in C, but the compiler won't be treating it specially.

Another example: various languages have garbage collection, but some are reference-count-based, and some are more general (compare Python vs. Java or Lua). And you could write a garbage collector in your C program of course, but that would be quite strange to do in the general case.

3

u/ghjm MSCS, CS Pro (20+) Jul 12 '21

The real difference is usually the contents of the standard libraries and the quality of available libraries in the ecosystem. If you're writing a database driven line-of-business web app, it's not so much that you want to work in Python as that you want to work with Django. Etc.

Some languages have unique problems or benefits that are really part of the language itself, like Python's global interpreter lock, Golang's goroutines and channels, or Rust's memory safety. But usually, it's the libraries that make the difference.

0

u/[deleted] Jul 12 '21

Of the things that differentiate languages, my two suggestions are:

  1. Interpreted vs compiled, and the subsequent performance differences, and

  2. True object oriented decomposition and the associated security (private attributes/methods)

-1

u/spaztheannoyingkitty Jul 12 '21

I'll attempt an ELI5 style answer:

Programming languages are a way of letting humans tell computers what to do in a way that computers can understand. Think of them like translators between humans and computers just like translators between English and other languages. Each language tries to solve the human-computer translation problem in a different way.