r/learnpython • u/misterphilly • Mar 06 '15
Is python a machine level language?
I'm still learning high-level programming languages (currently C# & Ruby) but eventually want to move to something that is more directly involved with the actual processor & memory. I've seen alot of languages that claim to be compilation code & ever-so-powerful but still need a VM or some kind of translator to actually execute (COUGH COUGH JAVA). so id like to know, would python at all be considered compilation code?
12
u/ChaoticxSerenity Mar 06 '15
No, Python is definitely still a high-level programming language. It uses an interpreter instead of a compiler, but that doesn't mean it's low level. It you want something lower level, try Assembly.
3
u/ivosaurus Mar 06 '15 edited Mar 06 '15
If you're looking at Python, C#, Java, and want to go a step lower, why involve the pain of assembly immediately?
Just see how C works. Still allows wanton memory manipulation, but is actually half understandable at a glance.
0
u/ChaoticxSerenity Mar 06 '15
Wasn't sure how low he wanted to go, lol Who knows, maybe he'll love it :P
0
Mar 06 '15
[deleted]
2
u/ivosaurus Mar 06 '15
I don't believe anybody was ever arguing that point at all, nor is it really relevant.
1
u/Kerbobotat Mar 06 '15
Python is an interpreted language, at run time the code is translated to low level byte code (machine code) ad opposed to a compiled language, like c++ which is 'built' or compiled into a executable program. IIRC you can compile python using something like py2exe or Cython (compiles python to C) interpreted languages have more "steps" to execution, and can be significantly slower than compiled programs.
9
u/Rhomboid Mar 06 '15
Python's bytecode is very high level. It is nothing whatsoever like actual machine code. It executes on an abstract stack machine which has little in common with actual hardware, and its opcodes include things that perform very high level operations, like "get an attribute" or "import a module". A single one of these opcodes might require thousands (or millions) of actual machine instructions to implement.
Just because it's bytecode does not mean it's low level. Bytecode is really just a compact way of storing the result of parsing Python source code, and a technique for implementing an interpreter that has well-defined semantics and relatively good performance, all things considered.
1
1
u/ivosaurus Mar 06 '15
Really you could say that bytecode is code that's stored as a binary representation (rather than text), or code meant specifically for a machine to read, rather than a human.
What there is to draw from these two hazy definitions is that neither of them mean that the actual code/representation need be low-level, or close to assembly instructions that a CPU would execute.
4
Mar 06 '15
py2exe does not really compile the software. AFAIK it is just a packer, that extracts and runs a normal Python program.
1
u/ivosaurus Mar 06 '15 edited Mar 06 '15
Both Python and Java have a compilation step which compiles their language source into bytecode.
This bytecode is then separately, by some means, executed, to run the program.
Both bytecodes look quite different; and the details of the implementation that does the execution of them is also extremely different.
As a point of difference, C and C++ are said to be compiled languages; their compilation step typically translates their language source right down to machine instructions; which can be passed wholesale directly to a CPU to run.
Lastly, Python and Java differ in that the former usually integrates its bytecode-compilation step into its execution step. Executing a .py file first compiles the Python source, then immediately after executes the bytecode produce. Whereas Java usually separates this step - one first runs javac on Java source code, which outputs a bytecode file. You then run java on the bytecode.
The biggest difference between Java and Python is that Python is dynamically typed, and Java statically. In terms of execution environment, the default Java VM uses a JIT, while the default Python VM just uses a step-by-step interpreter.
1
-6
u/constructivCritic Mar 06 '15
Sometimes I'm shocked by the questions I see...this is one of those times...but then I give op the benefit of the doubt and assume he hasn't gone to school for computer science.
4
u/blazinghand Mar 06 '15
I have downvoted this reply for being unhelpful and unfriendly, especially relative to the other comments here, with the goal of reducing its visibility.
1
u/constructivCritic Mar 07 '15 edited Mar 07 '15
That is a perfectly well justified Downvote if there ever was one. Not mad at all. Gave you an Upvote.
1
u/misterphilly Mar 06 '15
i'm so sorry you'd rather spend your time on the internet being a pretentious asshole to people who don't feel like throwing thousands of dollars at a school to learn how to type on a keyboard.
but yeah, you're right. I don't deserve an answer to this perfectly reasonable question just like every body else has contributed, instead some holier-than-thou snide remark from someone who otherwise has nothing to give. thank you so much.
1
u/constructivCritic Mar 07 '15
Yea, no...see that's the thing that bothers me. The fact that you think being a developer is just typing on a keyboard.
I think it's great that you are spending your time learning, but too often people try to jump ahead to learn some syntax and then call themselves developers. It's a bit like those people who call themselves hackers just because they can click a link on some website.
Whatever resources you are using, are lacking, if they give you the impression that Java calls itself a "machine language". So after seeing that I couldn't help myself, seen so many questions that would've been answered by the 1st chapter of any CS book. The fundamentals are lacking in your learning resources.
10
u/PastryGood Mar 06 '15
You also might have confused a few terms :-) Not that it really matters a whole lot, but it can be good to get it cleared up!
There isn't really any "machine level languages" as such. The only way to write machine level code is to well... write machine code :-) And you really wouldn't want to do that, unless you enjoy typing out binary instructions for whatever CPU you're using!
The closest thing you can probably come while still keeping it somewhat (but just somewhat) sane would be Assembly. Not that assembly in itself is a difficult language to learn, actually it's very easy, it's just tiresome to use. However, it would give you the ability to build software using nothing but simple processor instructions, moving and copying data between registers and other memory.
What I'd really suggest is that if you feel like you want to learn more about hardware and its effect on programming, you go to C. C provides you with pretty much all the power you need to examine lower-level programming (you could even embed some assembly in there if you please) :-)