Website Hosting for Just 20 ForumCoin ~ Advertise on ForumCoin
52 Life Tips Banner
Talk hardware, software, computer gaming, mobile devices, the Internet, social networking and other technology

Random programming question

Postby smithy » 27 Jan 2018, 11:29

Just wondering, is there a software (or will there ever be) that converts higher level languages into other higher level languages? Like say I wanted to use Python for simplicity, but wanted to convert it to C. Is it possible to create a software that does that (if it hasn't been done already)?
  • 1

User avatar
smithy
 
Posts: 97
ForumCoin: 106

Re: Random programming question

Postby solidcodes » 28 Jan 2018, 12:09

I think there are converter that can do that.
just google it.
  • 0

User avatar
solidcodes
 
Posts: 15
ForumCoin: 17

Re: Random programming question

Postby Sam » 29 Jan 2018, 07:10

Good question!

An interesting aside: I had to code a basic disassembler going from machine code -> assembly instructions (i.e. from low level to higher level).

There are some caveats within your code (namely you should treat variables as being of one type) but you should be able to compile Python to C. Here's an abandoned Python- C++ compiler project: https://github.com/pradyun/Py2C. IS there a current project that converts Python to C? Not really.. But take a look at Cython. It requires that you statically type variables (define ints strings etc.). It them compiles the Python code into C for C-Like performance. Here's a tutorial: https://pythonprogramming.net/introduct ... -tutorial/.

Does a software exist to convert a higher level language to a lower level target? YES! :D It's called HAXE and it compiles to C++ , JavaScript, Python, others and C(through Hashlink) https://haxe.org/documentation/introduc ... rgets.html.
  • 1

User avatar
Sam
 
Posts: 2,079
Location: New Zealand
Referrals: 16
ForumCoin: 229

Re: Random programming question

Postby smithy » 31 Jan 2018, 07:46

nice @sam would check it out asap, what about from high levels to low level?
  • 0

User avatar
smithy
 
Posts: 97
ForumCoin: 106

Re: Random programming question

Postby cmoneyspinner » 31 Jan 2018, 16:52

Oh my! @Sam and @smithy. The only word that sounded familiar to me was JavaScript. :lol:

What project are you working on??
I'm curious to see the finished product. Hope you accomplish what you have set out to do.
  • 0

User avatar
cmoneyspinner
 
Posts: 19,014
Location: Texas USA
Referrals: 10
ForumCoin: 1,807

Re: Random programming question

Postby Sam » 01 Feb 2018, 02:08

smithy wrote:nice @sam would check it out asap, what about from high levels to low level?


Cython for Python and Haxe do just that.

Here's a couple of other examples that compile to lower or higher level langauges or native machine code:
- Kotlin (compiles to machine code). It's a popular Java - like language that can run on JVM or natively or via JavaScript.
- Nim-Lang. Python - like syntax but built for speed. Compiles to C++, JavaScript and C.

Some languages make use of LLVM to produce binary machine code. See: https://stackoverflow.com/questions/235 ... ly-is-llvm.

I think a good question to ask is if it is worth it? If you're looking to speed up Python you should ask the following:
1. Do I really need extra speed? Is my application that time critical?
2. Have I coded this in good form? Can I replace lists with dictionaries or sets? Am I using bulky libraries and can I use ones which are Cython optimized? How am I storing and searching? (think Big(O)).
3. What's worth more: my developer time or code completion time? (if it's code completion you should start looking at faster languages like C, Java, Nim etc. Java is actually really fast if you look at benchmarks... I even coded something in python and java and shaved 1s off the completion time. Obviously you aren't going to get C-speeds on Java but Java is just a nicer language to code in).
4. Would PyPy (for JIT) speed up my code enough?
5. What are my time critical functions? Should I be using Cython?

Just remember, making a language switch is kind of a big deal. It's often best to stick with something you know. I only code for fun with Python because I don't code enough to keep up with other languages on top f that (including ones I learned at uni like R, Java, C, C#, F#). My next language that I fully learn will probably be C because that works nicely with Python. Python + C and you can accomplish anything.
  • 1

User avatar
Sam
 
Posts: 2,079
Location: New Zealand
Referrals: 16
ForumCoin: 229

Re: Random programming question

Postby Sam » 04 Feb 2018, 02:32

Further to ^ - Here's a cool project which compiles Python to Javascript so you can run it in a browser: https://www.transcrypt.org/.
  • 1

User avatar
Sam
 
Posts: 2,079
Location: New Zealand
Referrals: 16
ForumCoin: 229



Your Ad Here.

Return to CGT - Computers, Gaming & Technology



Who is online

Users browsing this forum: Claude [Bot] and 6 guests

Reputation System ©'