Today I learned - Programming languages can be brought together

andrewp

Andew

Posted on November 3, 2023

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

💖 💪 🙅 🚩
andrewp
Andew

Posted on November 3, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related