32

Can anyone point to programming language which has python-like syntax, but from the very beginning was designed to generate native code? I'm aware of Boo only, but it uses .net, not native code generation. Well, if nothing else than python-like languages which generate .net/java bytecode are fine too.

1
  • 2
    Nim fits this description well. Commented Dec 5, 2020 at 18:47

12 Answers 12

14

Cython might do -- the C code it generates is for Python extensions, but the whole thing can be packaged up and you'll be running native code throughout (after the 'import';-).

Sign up to request clarification or add additional context in comments.

Comments

8

I must admit that I don't quite understand your question, for two reasons:

  1. You are asking for a language with native code generation, but native code generation has nothing to do with the language, it is a trait of the implementation. Every language can have an implementation with native code generation. Several Python implementations have native code generation. There are C compilers that compile to JVM bytecode, CIL bytecode or even ECMAScript sourcecode. There are even C interpreters. There are also compilers that compile Java sourcecode or JVM bytecode to native code.

  2. Why do you care about the syntax? It is probably the least important factor about choosing a programming language.

Anyway, Nim is a programming language which has an implementation which supports native code generation (or more precisely an implementation which supports C source code generation) and whose syntax is a hybrid between Wirthian style (by the looks of it the most important influences are Oberon and Delphi) and Python.

However, the fact that it has Pythonic syntax isn't going to help you at all if you don't like European style language design or Wirthian style OOP.

5 Comments

Not really. A programming language as a whole is: The language syntax + the core libraries + the environment where it runs. Think about it a OO programming language whose root class is not java.lang.Object but System.Object is not Java but C# :P
I agree. A programming language with great performance but tedious syntax is like a knife that's incredibly sharp but has needles on the handle. Also, there is no such thing as "european style language design".
The OP want's something that "from the very beginning was designed to generate native code". Plenty of languages, eg Python, make native code generation very difficult because of certain dynamic features. Whereas many others are only slightly different, but can be compiled to native code very easily (eg Nimrod). So I disagree with your first point.
What? If the implementations were equally good at producing native code, then the syntax would be the most important factor about choosing a programming language.
@endolith: Personally, I find the semantics, type system, typing discipline, supported paradigms, and so on much more important than the syntax. The syntax can be easily fixed with a simple preprocessor, fixing the semantics needs a full-blown compiler. (See e.g. early versions of CoffeeScript vs. the current version of Babel.) There are pretty important distinctions between C, ECMAScript, C♯, and Dart, even though they share almost the same syntax. If I want static types, it doesn't matter how beautiful Ruby's syntax is. If I want OO, it doesn't matter how beautiful Haskell's syntax is.
7

Also found today Delight applying Python syntax on a D back-end.

And Converge too.

Comments

7

Check out Cobra

It is strongly influenced by Python, C#, Eiffel, Objective-C and other programming languages. It supports both static and dynamic typing. It has first class support for unit tests and contracts. Cobra provides both rapid development and performance in the same language.

2 Comments

Cobra looks decent. I particularly like the CORRECT real numbers by default: although it's safe reasonably often, "lossy" floating point should only ever be an optimisation used when it's safe, never the default. However, Cobra does NOT generate native code, sadly. It runs on .NET, which is a virtual machine. That can make a BIG difference, when you're writing code that processes gigabytes of data each item of which has some overhead in a VM, for example. Nimrod is the way to go here, with D being a reasonable alternative.
Cobra does generate native code if you want to. Running it on the VM is not a requirement. There is no need to go with D or Nim
6

shedskin compiles Python to C++

From shedskin project page

Shed Skin is an experimental compiler, that can translate pure, but implicitly statically typed Python programs into optimized C++. It can generate stand-alone programs or extension modules that can be imported and used in larger Python programs.

Comments

5

Genie which is part of the gnome project: http://live.gnome.org/Genie

I think it's exactly what you're looking for.

Comments

3

If you are happy with something that compiles down to Java bytecode you could have a look at Jython. Quoting from their FAQ:

JPython is an implementation of the Python programming language which is designed to run on the Java(tm) Platform. It consists of a compiler to compile Python source code down to Java bytecodes which can run directly on a JVM, a set of support libraries which are used by the compiled Java bytecodes, and extra support to make it trivial to use Java packages from within JPython.

I've not actually used it yet but am considering it on some projects where I have to integrate with existing an Java codebase.

HTH

1 Comment

@Ed - read the question. He said "Well, if nothing else than python-like languages which generate .net/java bytecode are fine too."
3

PyPy is a project to re-implement Python in Python. One of it's goals is to allow the use of multiple back-ends, including C. So you can take a pure Python program, convert it to C and compile it to native code. It is still a work in progress, so probably not suitable for production code.

Comments

2

You can find all of the previously mentioned languages, plus some more, here: http://wiki.python.org/moin/PythonImplementations

Comments

2

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula.

https://nim-lang.org/

Comments

1

You can also investigate IronPython - a python inplementation on the .NET framework

1 Comment

sigh .NET is NOT native code. At least, not by default, anyway. It's a virtual machine, like Java.
1

You can try Genie. It's the same like Vala, but with Python-like syntax. If you want to develop apps for Linux with GTK, and you want to compile it to native app, Vala or Genie is really good choice.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.