DEV Community

Andew
Andew

Posted on

Today I learned - Programming languages can be brought together

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!"
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
sethcalebweeks profile image
Caleb Weeks

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.

Collapse
 
andrewp profile image
Andew

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.