In my understanding, each project would be written using only one programming language; however, today I learned that it is possible to combine different languages in one project.
For example:
Let's say we have a script written in Ruby*:
# my_ruby_script.rb
puts "Hello from Ruby!"
We can execute this Ruby script in a Python script*:
import subprocess
# Execute the Ruby script from Python
result = subprocess.run(['ruby', 'my_ruby_script.rb'], capture_output=True, text=True)
# Print the output of the Ruby script
print(result.stdout)
Although programming languages can be used together, mixing languages can make it more difficult to read and modify code; it must be done cautiously.
*Code examples from ChatGpt
Top comments (2)
Welcome to DEV, and congratulations on your first post! Many Python packages are actually written in C/C++ for performance benefits, but I didn't know you could run Ruby code! I suppose any language that can kick off a shell command can invoke a program written in another language, so long as the interpreter is installed, or the program is precompiled.
From your comment, I was wondering how a programming language is written, my guess is it must be written by at least one available language, and at the end everything is interpreted to 0 and 1. So I wonder if there is a way for any language could be used together. I'm only 1 year into coding, I still have a long way to figure out how things in programming work.
Thank you for your comment and welcoming.