Comparison of process interruption tool
What is binding.pry?
While debugging, the engineers sometimes want to see the variable values at that point. If your language is static and you use IDE, you can set break point by GUI tools. However, if you use a scripting language with a pure text editor, we cannot take it the same way.
Open REPL and run each line might be possible, but it's a hassle.
On Ruby, inserting binding.pry or binding.irb can launch REPL at a specific point. I share how we can do the same thing for the other languages.
Ruby
After gem install pry
require 'pry'
a = 1
b = 2
binding.pry # open REPL
puts a+b
Since Ruby 2.4, native irb supports similar feature
require 'irb'
a = 1
b = 2
binding.irb # open REPL
puts a+b
Python
pip install ipython
from IPython import embed
a = 1
b = 2
embed() # open REPL
print(a+b)
Node.js
Style is different. node inspect test.js
a = 1;
b = 2;
debugger; // breakpoint
console.log(a+b);
At launch time, the cursor is on the head of the script. Move to the breakpoint.
debug> cont // Continue to breakpoint
debug> repl // Open REPL
PHP
composer require psy/psysh
<?php
require 'vendor/autoload.php';
$a = 1;
$b = 2;
eval(\Psy\sh()); // open REPL
echo $a+$b;
echo "\n";
Impression
Node.js's style is unique.
Top comments (0)