[Promotion of Ruby comprehension (1)] When switching from Java to Ruby, first understand the difference.

――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.

Common point

--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.

Summary

――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.

reference

Recommended Posts

[Promotion of Ruby comprehension (1)] When switching from Java to Ruby, first understand the difference.
From Java to Ruby !!
[Java] I want to calculate the difference from the date
How to write Scala from the perspective of Java
Get to the abbreviations from 5 examples of iterating Java lists
[java8] To understand the Stream API
The road from JavaScript to Java
From fledgling Java (3 years) to Node.js (4 years). And the impression of returning to Java
Easy to understand the difference between Ruby instance method and class method.
I want to judge the necessity of testing by comparing the difference of class files when refactoring Java
Update JAVA to the latest version to 1.8.0_144 (when downloading from the web and updating)
Java reference to understand in the figure
Introduction to java for the first time # 2
[Java Servlet] The road of Senri is also the fifth step from the first step
[Java Servlet] The road of Senri is also one step to the first
[Ruby] From the basics to the inject method
The story of switching from Amazon RDS for MySQL to Amazon Aurora Serverless
[Java Servlet] The road of Senri is also the third step from the first step
Ruby from the perspective of other languages
How to find the total number of pages when paging in Java
Iterative processing of Ruby using each method (find the sum from 1 to 10)
Output of the book "Introduction to Java"
Precautions when migrating from VB6.0 to JAVA
From Java9, the constructor of the class corresponding to primitive types is deprecated.
I translated the grammar of R and Java [Updated from time to time]
[Java Servlet] The road of Senri is also the fourth step from the first step
Find the difference from a multiple of 10
Java engineers now compare to learn the basic grammar of Ruby Part 1 (Basic, Variables)
Summary of points I was worried about when migrating from java to kotlin
[Ruby] Meaning of &. How to avoid the error when the receiver (object) is nil
The first year of working people summarized how to take the Java Bronze exam
[Ruby] What is the slice method? Let's solve the example and understand the difference from slice!
How to find the cause of the Ruby error
Things to be aware of when writing Java
[Delete the first letter of the character string] Ruby
The story of learning Java in the first programming
The story of introducing Ajax communication to ruby
Summary of moss when updating from JMockit 1.4 to 1.30
[Ruby] Code to display the day of the week
[Java] How to get the authority of the folder
First touch of the Files class (or Java 8)
Java Welcome to the Swamp of 2D Arrays
[Words spelled to me when I was in the first grade ⑩] Please understand the minimum Java coding method. (1st: Naming)
Java engineers now compare to learn the basic grammar of Ruby Part 2 (classes, methods)
How to get the class name of the argument of LoggerFactory.getLogger when using SLF4J in Java
When inserting from Java to MySQL, get Auto_Increment_ID (automatic numbering value) as the return value
Library not loaded when trying to upgrade the version of ruby and rails s
[Ruby on rails + Mysql] Data migration procedure memo when switching from heroku to AWS
[Android studio / Java] What you don't understand when you touch it for the first time
Summary of how to use the proxy set in IE when connecting with Java
From the introduction of devise to the creation of the users table
When the hover of Eclipse is hard to see
[Words spelled to me when I was in the first grade ⑪] Please understand the minimum Java coding method. (2nd: Javadoc edition)
[For beginners] Quickly understand the basics of Java 8 Lambda
[Java] How to extract the file name from the path
[Ruby] How to find the sum of each digit
The story of migrating from Paperclip to Active Storage
Understand the characteristics of Scala in 5 minutes (Introduction to Scala)
Java language from the perspective of Kotlin and C #
[Java] How to get the maximum value of HashMap
[Java] When writing the source ... A memorandum of understanding ①