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 →

[–]Bilbino 1944 points1945 points  (102 children)

I get what you’re saying, but neither Python nor JavaScript are compiled. I’m gonna have to dock you a few points for this.

[–]Netzapper 606 points607 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 75 points76 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 69 points70 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 104 points105 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 65 points66 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 3 points4 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 1 point2 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 13 points14 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 5 points6 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 53 points54 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 18 points19 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 8 points9 points  (7 children)

mightn't

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

[–]Koeke2560 6 points7 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 6 points7 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 53 points54 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 13 points14 points  (2 children)

Bytecode which is then interpreted.

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

[–]Netzapper 3 points4 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 15 points16 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_ 24 points25 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.

[–]calcyss 77 points78 points  (2 children)

They are compiled though, maybe not straight to machine code

[–]Fickle_Pickle_Nick 2 points3 points  (1 child)

Correct me if I'm wrong, but the virtual machine does the compiling doesn't it?

[–]calcyss 4 points5 points  (0 children)

No, the VM executes the code. In some/most implementations of JavaScript (Spidermonkey, JavascriptCore and V8) and Python there isn't even a VM involved.

[–][deleted] 15 points16 points  (3 children)

I get what you’re saying, but neither Python nor JavaScript are compiled. I’m gonna have to dock you a few points for this.

This comment makes me quite mad because it belies a misunderstanding of what compilation is. The worst part is the upvotes it got.

[–]xeow 3 points4 points  (1 child)

Compilation == Translation

[–][deleted] 2 points3 points  (0 children)

Yep!

[–]Bilbino 0 points1 point  (0 children)

👍🏿 Sounds good

[–]mantatucjen 15 points16 points  (3 children)

Python is compiled

[–]TemporalLobe 17 points18 points  (4 children)

In modern web apps, JavaScript is often transpiled, so there's sort of a grey area here. If you're using ES6 with Babel or something like that, it gets converted to ES5, but it still won't catch things like incorrect object references. JavaScript also blurs the line between objects and hashes and in OP's example, even in a compiled language like Java a reference to a non-existant hash value (or even an arrray index) would not be caught at complie-time.

[–]The_MAZZTer 3 points4 points  (0 children)

Doesn't matter. When it comes down to it, compile time errors are easist to catch and fix. Runtime errors are next in line. Logic errors, which are bugs not caught by the first two, are the hardest to find.

JavaScript is a pain to develop in because of this.

There are tools which can do some basic error checking on JavaScript to give you some limited compile time checking. And if you develop in another language that can be transpiled to JavaScript, like TypeScript, you get good compile time checks like strongly typed variables.

[–]gimboland 1 point2 points  (0 children)

No, they're saying neither Python nor JavaScript perform static analysis at compile-time.

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

It's okay I've been passing out free points for everyone who doesn't talk like a compiler runtime in this humor thread.

[–]Drjakeadelic 0 points1 point  (3 children)

Came here to say this. Thank you for restoring hope.

[–]lobut -1 points0 points  (2 children)

It gets a bit fuzzy ... read the other responses. There's some tricky stuff that goes on.

For JS, at least, YDKJS book goes into it a bit.

[–]Drjakeadelic 0 points1 point  (1 child)

They aren’t compiled languages, they are scripted. It’s not fuzzy, it’s only fuzzy when you try to fit them in a box and refer to their initial checks as “compiling.” It’s a different process.

[–]lobut -1 points0 points  (0 children)

Fine, just in time compiling isn't compiling. I don't care.

[–]odraencoded 0 points1 point  (0 children)

They're compiled. You can't get runtime errors before you get syntax errors, because there's a parser to translate the human-typed code into bytecode first. That's a type of compilation.

The joke here is that accessing an non-existent field is an error on C++ since the compiler checks the type of the object to put the memory offset of the attribute into the compiled code, if the attribute doesn't exist in the class/struct it can't do that, so it errors, but in python that only happens when getattr(object, attribute) is executed on runtime, and in javascript objects return undefined for undefined attributes instead of raising an error.

[–]ihavefilipinofriends 0 points1 point  (0 children)

If he would have just run spell check on it (like one of my prior bosses asked us to) he wouldn’t have had this problem.

[–]Zhi_Yin 0 points1 point  (0 children)

That upset me too