Wednesday, October 31, 2012

What is the good thing of Ruby?


This is the first time to learn Ruby for me. However, as compared with other programming language, which are Java, PHP, and so on. Ruby is much understandable programming language. Programming language of Ruby makes us simplify programming. There are many advantages of Using Ruby because it based on object-oriented. What are the advantages of Ruby?

Simple Example:
Java:

Ruby:
Output of each method shows the same result. As you see, method 3 in Java is the easiest one. However, Ruby’s one is much easier than Java’s ones to write. Ruby does not require semicolon and “System.out.println.” Of course, Ruby makes other situation of methods easier.

Simple looping Example 2:
Java:
Ruby:

In case of looping examples, both Java and Ruby show the same result. As you see, Ruby is simpler than Java. Ruby can cut unneeded part of programming language and give us extra time to work other things.


Object-oriented makes us create a data field and a method together. It means that we do not need to work them separately. The concept of object-oriented programming is “object.” We need to consider about object first, then what things should be around “object”. There is a list of benefits of object-oriented:



  •        The concept of a data class makes it possible to define subclasses of data objects that share some or all of the main class characteristics. Called inheritance, this property of OOP forces a more thorough data analysis, reduces development time, and ensures more accurate coding.

  •        Since a class defines only the data it needs to be concerned with, when an instance of that class (an object) is run, the code will not be able to accidentally access other program data. This characteristic of data hiding provides greater system security and avoids unintended data corruption.

  •        The definition of a class is reuseable not only by the program for which it is initially created but also by other object-oriented programs (and, for this reason, can be more easily distributed for use in networks).

  •        The concept of data classes allows a programmer to create any new data type that is not already defined in the language itself.



Those lists made by Margaret Rouse. She talks what is benefit of object-oriented programming easily. Here is entire article:

In case of this post, I just compare Ruby with Java. However, I found interesting article about Ruby. Its article compares Ruby with Perl and Python. I have never used and learned Python and Perl, but it shows how simple Ruby is. It shows the same program by Perl, Python, and Ruby. Unfortunately, It is in Japanese, but you can see code of them Here is article.

3 comments:

  1. Hi Yoshi, great to see you putting some code in the blog, however I think you have a few syntax errors and misunderstandings. I do recommend http://gist.github.com for code chunks that are embedded in blogs.

    Anyhow, the main thing to note about your Java examples is that they wouldn't run stand alone. Java would insist that you placed them in some method in a class in order to compile them. Also, the critical difference between your earlier examples in Java and Ruby is that you don't need to define variable types (e.g. int) in Ruby when you declare variables.

    Also note that the Ruby code you present would not run. It should be:
    puts “Total number is #{2+3}". You had the interpolated code outside the parentheses. Also, while that would run from the irb shell, if you put it in a file you would need the "puts" statement to print out the result.

    It's important to get into the habit of actually testing any code that you put in your blog. Ideally you should be comparing a Test.java and a test.rb file that can be run from the command line to make a proper comparison.

    It's nice that you added some mention of OO programming, although your example doesn't really flow with the rest of the article. It might have done if you had mentioned that in ruby **everything** is an object. Also, great link to the external article comparing Perl, Python and Ruby. I guess you already knew that the creator of Ruby is Japanese right?

    ReplyDelete
  2. Although Sam already mentioned that your codes from Ruby and Java are not compared fairly, it was interesting for me to see how the codes from Java and Ruby look different due to the fact that you necessarily have to declare variable in Java while you do not need to do so in Ruby language. Actually reading both Java and Ruby codes one another helped me clarify how different the structure and fundamental concepts of Ruby and Java. Thank you! :)

    ReplyDelete
  3. I am starting to under the Ruby concept in regards to codes, etc, Tough from the start. However moving forward, I am sure I will get the grasps of things.

    ReplyDelete