HACKER Q&A
📣 zcheck

If all code runs as machine lang, why do programing languages matter?


I am learning to code and know a bit of Java and C. What i understand is all the code we write ultimately converted to machine language which is run in the CPU. The optimization we look forward while coding is for best time and space complexity which looks to me like language agnostic. So why do we have so many programming languages and ardent followers supporting or opposing one another? Is it mainly based on the programming paradigm (OOO vs Procedural)? If so, why the same paradigm has multiple languages?


  👤 nindalf Accepted Answer ✓
> So why do we have so many programming languages and ardent followers supporting or opposing one another?

This is two questions. Having a diversity of languages helps (I'll get into why). We don't need ardent followers advocating getting into flame wars that benefit no one.

As you say, every language is ultimately converted into machine code. However, the final machine code is not the same. Each language has it's own strengths and weaknesses and this affects the final output. Some of these are

* Strong or weak type systems - stronger type systems allows you to encode invariants of your program, ensuring that the final machine code doesn't blow up in unexpected ways when your user runs it

* Interpreted or compiled - Interpreted languages (arguably) allow faster iteration while compiled languages have a more optimized end product. More here - [1]

* Light or heavy run times - part of that machine code might or might not include a runtime. This runtime could manage threading, garbage collection and so on for your program.

These are some of the many are trade-offs that languages make. Depending on the trade-offs chosen, the language is a good fit for some applications but not others. For example, a runtime like the one used by Java probably makes it unfit for embedded programs compared to C, while Java is probably a better fit for writing web servers compared to C. Overall, we're better off because we have the option of choosing Java or C (or Python or Rust or ...) depending on the problem we're trying to solve.

As for people fighting over languages, don't pay it too much attention. Such discussions can get quite heated but ultimately they're quite meaningless. People will choose what makes sense for them.

[1] - https://craftinginterpreters.com/a-map-of-the-territory.html...


👤 strangattractor
Like many things the return on investment decreases with complexity. Assembly is easier than trying to program with the actual opcodes but is specific to a CPU. C and its ilk are portable between CPU's, easier to read, less error prone and easier to read for humans. After that the return starts to diminish.