How do languages like Java, Python and JS run if they're not compiled? Could someone kindly give me a rundown of each, detailing each step from writing the code to the machine instructions being generated?
Obviously JS for example must still become machine code at some point, why not just make it a compiled language?
Java is statically compiled to bytecode, which is run by the Java Virtual Machine, which is a program that provides a runtime for the byte code.
Python is parsed by a program called an interpreter, which then constructs a byte code representation of the language which it then provides a runtime for.
JavaScript is actually JIT compiled, which means that it is a hybrid of the two approaches above. It is still run by a program (javascript engine) that provides a runtime for the bytecode.
tl;dr they are programs that run other programs
Jose Ramirez
Interpreters have the benefit of the REPL. For JavaScript and web development, it’s very useful in debugging. Same with Python - rapid prototyping through the REPL makes it easy for development with some areas. And Java runs in the JVM so that it can run on any computer with a JVM, but I’m pretty sure Java is compiled.. correct me if I’m wrong.
Brody Collins
Thank you lad. Could you touch on what 'runtime' means? What's the difference between bytecode and a normal binary?
Connor Wood
If you know C or C++ or any compiled language, then write some simple program that prints back whatever the user inputs.
Then add some basic logic, that if the first word is "reverse", the rest of the input will be written in reverse. You can then add on many various functionalities: "if there is a '+' sign in input, try to add numbers which are after it and print it back". Then you can keep adding more and more functionality.
>why not just make it a compiled language?
Because compilation isn't easy. or rather, efficient compilation is hard as all fuck.
J$ doesn't exactly "become" machine code. But rather, depending on what the interpreter gets in input, different paths are run. I think it shouldn't be much harder to understand than the general idea of conditionals and different paths in program.
Justin Wilson
runtime is just the moment of time when the program is running
Wyatt Powell
>Could you touch on what 'runtime' means? Runtime simply means the environment your program executes in. For a Java program, it means the JVM which is responsible for executing the code and providing all the facilitation you need for I/O and threads and other things. For your C program, it basically just means the image process loader that loads your code and whatever you linked against (for example the standard library and other libraries) into memory in order for the CPU to start running it.
>What's the difference between bytecode and a normal binary? "Normal binary" is machine code which is understood natively by your CPU.
Bytecode can mean both that, or some other agreed upon format that isn't ran natively but is executed by something like a virtual machine.
Justin Ortiz
>tfw you'll neber be a horny boy and squirt ur semen on her mamaries
Nathaniel Ward
Okay, but at the end of the day, there is still something running at the native machine code level that interprets your other programs, be it Python, JS or otherwise?
I'm sorry if I sound like a jackass, I write C/C++ and asm for a living and this whole abstract interpreted language thing is really out of the way I normally think. People treat these languages as black boxes that "just werk" but I want to know the why and how of it all.
I know that Python is built on C, so Python interpreter is actually just a C program which runs my Python code?
>there is still something running at the native machine code level that interprets your other programs, be it Python, JS or otherwise? Yes.
>I write C/C++ and asm for a living and this whole abstract interpreted language thing is really out of the way I normally think. I find it quite scary that you write C for a living and have never taken a class on compiler theory or know what ASTs are etc.
>I know that Python is built on C, so Python interpreter is actually just a C program which runs my Python code? The reference interpreter, CPython, is, yes.
Leo Mitchell
I know how compilers work, but how is that relevant to my knowledge of how non-compiled language function?
Benjamin Mitchell
>but how is that relevant to my knowledge of how non-compiled language function? All of them are compiled, albeit in different ways.
They work more or less the same way though, the difference is that some are run ahead of time, others are run just in time (JIT) and others just store the representation and interpret it live.
Also, linking in libraries and setting up a runtime isn't that different fundamentally.
My reaction came because you didn't know what a runtime was and you referred to machine code as "binary".
Jackson Morales
If you're interpreting a dynamic scripting language like python, you usually do all the same steps as compilation except you stop after generating the AST. Instead of doing semantic analysis and generating machine code like a compiler would, you can just evaluate the AST. That's a basic interpreter.
Levi Hughes
I wanna compile that pizza **IF** you get what I mean...
Carter Butler
I meant binary as in a binary file, ELF, DWARF, etc
Jaxon Thomas
Python byte code (.pyc) is also a binary file, so are compiled Java files (.javac). You clearly mean an executable file.
Zachary Price
Executable binary, how does that do it for you mate
No I don't, she doesn't even have a tray for that thing.
Liam Bailey
why is the pizza cut like that
Camden Martinez
The JVM is very similar to a CPU. It has a whole CPU architecture on it. The instruction set might have more or less features than the actual silicon it is running on, hence the "virtual machine" is emulated over the actual hardware. It isn't necessarily one to one with machine code, but can be close. Theoretically you could create a Java CPU, but that's a fucking terrifying idea.
>Theoretically you could create a Java CPU, but that's a fucking terrifying idea. Some ARM CPUs supported hardware execution of Java bytecode. A small number of opcodes would trap but for the most part it was direct code execution.
>The JVM is very similar to a CPU. More like a computer than a CPU.
>Theoretically you could create a Java CPU, but that's a fucking terrifying idea. There exist a couple of JVM implementations (partially) in hardware though.
>The JVM is an interpreter, nothing like a CPU. There are JVM implementations in hardware.
Luis Gomez
Who's this beauty
Ian Diaz
>>>/your favorite search engine/
Camden Lee
Abigail Shapiro, Ben Shapiro's sister. She's sung on broadway and shit, so she's literally a degenerate broadway jew which is why Jow Forums is so obsessed with her.
Christian Cooper
its exatly like a CPU
Gabriel Sullivan
Post more of her.
Jackson Lewis
>why not just make it a compiled language? Because its semantics are too dynamic, that means too many things are known at runtime only, that means compiled binaries would have to include a lot of checks and can apply less optimizations ultimately making it slower than being JIT compiled.
Could be worse: There are languages like Python and Ruby that are so dynamic in all the wrong places that even a JIT compiler can give you a ~8x gain avg.
Ian Davis
do craftinginterpreters
Adam Jones
tfw none of these embryos have seen this movie
Wyatt Torres
A lot of effort has been put into making Javascript content faster. There are Javascript engines like Chrome V8 that go the whole way and JIT-compile Javascript to machine code before executing it.
Matthew Russell
GIB AAAAAAAAA
Nicholas Scott
JVM actually compiles bytecode to machine-dependent binary so it doesn't have to re-interpret the code every time it's encountered. Of course,it can't make some optimizations that are available to normal compilation.
Jaxon Baker
>Large breasted woman for your help. Jews don't count
Liam Ross
Sorry, but no she's not, retard. Abigail looks completely different.
Aaron Wood
Emily barren I should've reverse searched rather than trusting a kike loving nigger faggot
James Ross
Bravo, it only took you fucking nine and a half hours to figure that out.
John Adams
python is run by an interpreter
Xavier Richardson
>Java is statically compiled to bytecode, which is run by the Java Virtual Machine, which is a program that provides a runtime for the byte code. yes >Python is parsed by a program called an interpreter, which then constructs a byte code representation of the language which it then provides a runtime for. wrong >JavaScript is actually JIT compiled, which means that it is a hybrid of the two approaches above. It is still run by a program (javascript engine) that provides a runtime for the bytecode. close enough
John Sullivan
>wrong Python isn't JIT compiled, if that's what you're implying. The compiled Python is just a binary representation of the AST.
Jeremiah Cox
Its not what I'm implying.
Interpreters don't "construct a byte code representation". They interpret byte code.
Parker Howard
It was a simplification, you sperg. You know as well as I do that the first step when running your Python source code through the interpreter is compiling it to a binary representation of the AST (aka byte code).
Justin Powell
Not op but how do you even program a compiler? Say you want to write a C compiler. Can you write it in C? What if the old version of the compiler has a bug, how can you update to a newer version if the bug will be compiled as well?
Isaiah Diaz
>Say you want to write a C compiler. Can you write it in C? Yes
>What if the old version of the compiler has a bug, how can you update to a newer version if the bug will be compiled as well? That's not how it works.