We can sort the present programming languages in two halves, i.e. Dynamically and Statically typed languages. The Static Typed Language is the language in which the variables cannot exist without any type of primitive data types – Integer, String, Boolean, Array, etc. associated with them. Below is an example of how variables are declared in Java:
int student_id = 10;
String student_name = “Java coder”;
double numbers = 3.21;
Boolean shows = true;
Whereas on the other hand, Dynamically typed languages do not have this constraint in them.
Below is an example on how variables are declared in Ruby:
name = “Anviam”
zip = 166059
cmmi_level_3 = true
While this may be a boon for Dynamically Typed Languages, this may sometimes result in disaster explained below.
For demonstration purposes we have a function which returns a number based on the parameters sent to the function in the arguments:
The output of above function when invoked would be:
But this may not result in an Error if the for some reason, the parameter “number” is changed to a string
There is a solution in Ruby to alter its nature from Dynamically type to Statically type by using some plugins, or “gems” as in Ruby.
Some popular gems are:
Servlet by Stripe
RDL by Tuft University
RBS, ruby’s in-house type safety feature
The type safety mechanism has been utilized in the Ruby for a quite long time, and since Ruby v3.0.0 RBS has been bundled with it so that the benefits of the Type Safety features can also be put to use.
Ruby 3.0 also bring some
For example, usually when we declare a class in Ruby, it code would look like this:
But when we are using RBS, the above code segment would look like:
With the above code, we can be ensured that the object declaration and it’s utilization could be free from type and nill error, which we know could result in a breakdown.