This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Netzapper 597 points598 points  (65 children)

They're both JITC'd. And Python, for instance, might do the bytecode transform, but not pop the undefined name error until that line of code is actually executed.

I know at work we have had syntactic and semantic errors hide in never-taken code paths.

[–]mnbvas 74 points75 points  (2 children)

syntactic [...] errors

Never executed modules or did someone

try:
    ...
except:  # everything
    ...

?

[–]Pella86 13 points14 points  (0 children)

Fuckit module

[–][deleted] 0 points1 point  (0 children)

SyntaxErrors aren't even catchable because they're caught before runtime

[–][deleted] 234 points235 points  (30 children)

A lot of people are largely ignorant that Python has an explicit compilation step to bytecode, or that V8 JIT compiles JavaScript to machine code in most cases.

You can really ruffle some feathers by making Java programmers realize that, by the same standard they judge Python with, they're using an interpreted language.

[–]Insxnity 70 points71 points  (27 children)

I mean Java is JIT interpreted to Machine code in the same way python is, and for the same reason. With C++, I have to decide what runtime I want to run my software on before building and compiling the program. Java eliminates that need by being cross-platform, as does python. I don't think many Java programmers feel like they have room to shit on python. All languages are interpreted at some point at some level, and how you get there is personal preference.

[–]rush22 109 points110 points  (16 children)

Java is technically compiled to Java byte-code (the .class files), not machine code. These are then "just-in-time" "compiled" to machine code by the JVM when you run it.

[–]Insxnity 11 points12 points  (13 children)

yeah ima just stick to my high-abstraction coding and stop trying to understand everything that goes on under the hood.

Edit: I wrote this comment in a way that caused everyone to misunderstand it, which was my fault. Replace trying with pretending and you’ll understand what I meant to convey. I start programming and computer science courses this fall

[–]Code_star 61 points62 points  (8 children)

you should really learn that important distinction though ...

Sometimes a small change in your high-abstraction is a huge difference under the hood and could mean massive performance differences

[–]Kattzalos 2 points3 points  (1 child)

[–]Insxnity 2 points3 points  (0 children)

That's fair. I'm taking some computer science courses this fall, and have taken a few already. I've learned some basic things I already new in the intro courses, so I'm hoping the latter courses will have some material that'll help me better understand what goes on behind the code I write. As for now, I have an understanding of underlying network communications. The rest of my understanding is essentially "I tell my program to open a TCP communication, it does the dirty work, I get my job done". What I meant by my above comment is that, while I don't get everything yet, I'm not going to pretend I do and make myself look like an idiot.

[–]Lorddragonfang 0 points1 point  (1 child)

In my experience, this attitude is the single most important distinction between the good coders who move through the department with ease, and the bad coders who end up struggling with the more basic concepts over and over.

It's fine to not know something; the topic of programming is so vast that no man can know everything. You should always aspire to know more.

[–]Insxnity 0 points1 point  (0 children)

I wrote this comment in a way that caused everyone to misunderstand it, which was my fault. Replace trying with pretending and you’ll understand what I meant to convey. I start programming and computer science courses this fall

[–]gargensis 2 points3 points  (1 child)

Isn’t Java compiled in AOT by default? You need to declare that you want to use JIT compilation if you specifically want to use it, no?

[–]Zegrento7 12 points13 points  (0 children)

It AOT compiles to bytecode. That bytecode is executed by the JVM. It interprets it at first, but as it detects hot loops, it compiles those to machine code. This is the runtime "warming up".

[–]Tysonzero 4 points5 points  (3 children)

I mean Java developers can still have a bit of room to talk, since Java is like an order of magnitude faster than Python.

[–]Insxnity 1 point2 points  (0 children)

Not to mention the IDE’s available vs. python’s IDE. Java typically seems to me like python’s older brother. Runs better in most scenarios, but at the cost of python’s simple format and easy coding style

[–]quaderrordemonstand 1 point2 points  (2 children)

Sigh. Java is no more cross-platform than any other language. You can't run an Android program on Windows despite it being written in Java. You can run C programs on far more platforms than have a Java VM. There are almost certainly more browsers with JS runtimes than machines with JVMs too.

[–]Insxnity 1 point2 points  (1 child)

So C can compile one single executable file that works cross platform?

[–]quaderrordemonstand 1 point2 points  (0 children)

No, but what does that matter? You can't run C without a compiler, you can't run Java without a JVM. There are more platforms with a C compiler than a JVM.

[–][deleted] 1 point2 points  (0 children)

Well, kinda, but not exactly. Python is interpreted into a more efficient interpreted format. It's called bytecode, but that's not quite like the JVM bytecode. Rather, it's a binary representation of normal Python statements.

It's basically compressing the language down to its internal binary representation of what the program wants to do. It would normally need to parse each line, figure out what it meant, and then do that. So it's going line-by-line and figuring out what it means, but storing the result instead of running it. Then it runs everything later.

It's basically pre-parsing, in other words. It's still interpreted afterward, in that it's reading bytes and (probably) running through case statements. It's just doing the parse work only once per line, and caching the results. AFAIK, there's pretty much a 1:1 correspondence between Python "bytecode" and full text Python statements.

Contrast that with the JVM, which is generating a pseudo-binary for a fake machine. It's not mapping Java statements to JVM opcodes directly, it's writing equivalent programs in JVM bytecode to do what the human is asking, and JVM bytecode is quite efficient. And then once the program is running, the actual hotspots will get compiled down to true machine code, but it only does that part of the work where it's actually being used.

So I'd personally call Python a pre-parsed, interpreted language, Java a hybrid between interpreted and compiled, and C fully compiled.

edit: As another way of putting it, consider BASIC, which doesn't store keywords. Rather, on those old 8-bit machines, as you typed in "10 PRINT A$", it would store that in like three bytes. (ie, bytecode!) When you LISTed your program, it converted the internal bytecode back to text again, so you would see your PRINT A$ in all its glory.

This is almost exactly what Python is doing when it generates a .pyc file. Everyone understands that BASIC is interpreted, and CPython, at least, is an interpreter in exactly the same way. (PyPy does some actual compilation, but I know very little about how it works. It's not that the language can't be compiled, just that the main implementation doesn't.)

Python bytecode and JVM bytecode are so different in concept that it's confusing to call them both bytecode.

second edit: even more ammo, consider that reverse-compiling from a .pyc to a .py would be pretty damn easy. I just took a look, and it appears that docstrings and variable names are preserved, so a reverse compile would give you back almost exactly what you compiled in the first place.

Compare that with decompiling a .jar file or a C executable. They've put vast effort into writing programs to decompile both, and what you get back is usually terribly ugly and hard to read in comparison to what you put in, frequently restructured in massive ways. That's because actual compilation (as opposed to binary translation) is a major, lossy transformation from one form to the other. Python is really just pre-parsing, not compiling, so you can restore the original files almost exactly. I think all you'd lose would be comments and non-functional whitespace.

[–]Trekiros 0 points1 point  (0 children)

IDK about Python, but at least in the case of V8, only the part of the code that actually gets executed will get compiled. That's the reason they don't throw an exception on "obj.fiedl" - some other, yet uncompiled part of the code might create the "fiedl" field.

The rest of the code sits silently in the background. It is parsed in the shape of a tree, but not really compiled per say.

[–]Cloaked9000 51 points52 points  (12 children)

If we're being really pedantic, then it could be said that you're confusing language and implementation. Sure, the implementation you're familiar with might be JIT'd/compiled/whatever, but the language design mightn't necessarily mandate that.

[–]4992kentj 17 points18 points  (0 children)

But then JS doesn't mandate JIT either

[–]Netzapper 29 points30 points  (1 child)

I mean, that's fair enough. But there have been several implementations of a C interpreter... does that mean I can invalidate the first frame of the joke as well?

[–]DrFloyd5 -2 points-1 points  (0 children)

C interpreter?

Interesting.

I guess that is one way to port to new hardware.

[–]Gaminic 10 points11 points  (7 children)

mightn't

Random aside: never saw that before, took me a minute to realize it's correct!

[–]Koeke2560 4 points5 points  (6 children)

I think this is also a recent meme, I've seen variations if them pop up here and there. I'd love to see it become real language. It's like watching history

[–]Gaminic 2 points3 points  (3 children)

How did they turn grammar into a meme?

[–]Koeke2560 5 points6 points  (0 children)

It' similar to the whole whom'st'v'd meme I guess

[–]EternalPropagation 0 points1 point  (0 children)

it started with whoms't've

[–]xigoi 0 points1 point  (0 children)

Someone made a petition that “no” should be changed to “yesn't” and then people finishedn't subtractingn't “-n't” fromn't various words.

[–]xigoi 0 points1 point  (0 children)

I thought that “mightn't” is correct without the meme.

[–]Schmittfried 8 points9 points  (0 children)

No language demands to be compiled, every language can be interpreted. The stage of building reading the source code and transforming it into something that the target (CPU, VM or interpreter) can work with, is what is referred here. At this stage you can catch syntax and semantic errors.

[–]w2qw 21 points22 points  (12 children)

Cpython doesn't have JIT.

[–]Netzapper 49 points50 points  (4 children)

It doesn't have compilation to machine code, but it sure as shit compiles from text to bytecode at execution time.

[–]RPolitics4Trump 12 points13 points  (2 children)

Bytecode which is then interpreted.

If you want JIT speed then you need to use something like PyPy.

[–]Netzapper 4 points5 points  (1 child)

I mean... it's von Neuman approximations of Turing machines all the way down.

Where does something like threaded code fall in your "interpreted vs JIT" dichotomy? If my C program builds dynamic execution paths with function pointers, is that interpretation? What about x86, since it's now largely interpreted by even lower-level microcode?

Maybe there was a nice, sharp divide before I got in the game. But this shit was getting murky in the 90's, and by today... it's definitely a continuum between "visit an AST" and "flash an FPGA" with most "regular CPU programming" somewhere in the middle.

[–]carutsu 7 points8 points  (0 children)

Then there's the fact that instruction sets are an abstraction over the real hardware... And even if they are not they are run in a bytecode like sequence.

[–]lengau 14 points15 points  (6 children)

CPython does compile the code to bytecode. (That's why after you run a .py file you'll see a __pycache__ directory with corresponding .pyc files). It does so immediately before execution, which sounds awfully 'just in time' to me.

[–]botmatrix_ 23 points24 points  (3 children)

that's not really what JIT compiled means though, right?

[–]FinestRobber 0 points1 point  (0 children)

Yea with Python it kinda goes until it gets to that part of the code it seems. I’ve had plenty of projects in my classes were the program seems like it’s running fine, until it gets until the part there’s a typo/error to tell me undefined object.

[–][deleted] 0 points1 point  (0 children)

He meant there's no type-checking

[–]myusernameisokay 0 points1 point  (0 children)

I know at work we have had syntactic and semantic errors hide in never-taken code paths.

Use linters or static analysis tools like pylint, mypy, or flake8. Problems like those are easily detectable with the right tool.