――As the words "It's good to do Java first." "The first training you will learn after joining the company is Java.", I just went straight on that track. ――As an experienced and pretentious Java young writer, I finally decided to cry at Ruby, which is "easy and popular", a mirror of a spoiled engineer. ――However, even though it is "easy and popular," there may be some ridiculous tricks, and there is a lot of negligence. ――So, we will work on it with the two main objectives of “relieving anxiety” and “efficient learning” to get dressed.
--Platform independent
--Access specification → Public, protected, private can be used.
--Single inheritance → A class can only have one direct parent class.
--The parent class of all classes is the Object class
--Typed. → Java requires variable and method type declarations, whereas Ruby requires them. → Java is a statically typed language, while Ruby is a dynamically typed language.
→ For Java
String name = "nanashi";
int number = 50;
→ For Ruby
name = "nanashi"
number = 50
--The parentheses for the method call can be omitted.
String message = "hello";
System.out.println(message.length());
→ For Ruby
message = "hello"
puts message.length
--Constant change → In Java, constants cannot be changed, but in Ruby, they can be changed.
→ For Java
static final String MESSAGE = "Hello";
static final String MESSAGE = "Hello World"; //error. Not changed.
→ For Ruby
MESSAGE = "Hello"
MESSAGE = "Hello World" #Warning only
--There is no basic data type. → Since everything is expressed as an object, methods can be executed for ordinary numerical values.
→ For Java
String number = new String(100);
→ For Ruby
number = 100.to_s
--Presence or absence of minimum class definition. → In Ruby, it can be executed without a class.
→ For Java
public class Test {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
→ For Ruby
puts "Hello World"
--Symbols can be used in method names →! And? Can be used.
→ For Java
public class Main {
public static void main(String[] args) throws Exception {
//An error will occur.
sayHello!();
}
public static void sayHello!(){
System.out.println("Hello");
}
}
→ For Ruby
class UserNumberCheck
def userNumber?
true
end
end
number = UserNumberCheck.new
if number.userNumber?
puts "that's correct."
end
--Abundance of libraries and development speed → Abundant convenient library called gem → The flow of version update is fast.
――This time, because of the difference between Java and Ruby, we used Java, which we have taken care of so far, as a starting point, and let ourselves instill the "easiness and ease of writing" of Ruby. ――I'm doing the unskilled "unpopular typical behavior" of "Is this not possible with Ruby?", And I will be distanced from all languages in the future. ――I find the light of hope in such a realization certain future and live a cheerful life, so I will continue to work on simple learning today.
Recommended Posts