Friday, November 12, 2010

OO Hello World - Gosu



The Hello World version of the program in Gosu!

A new OO programming language targeting the JVM with a Java-like syntax and compatible with java code. This looks like a promising language that deserves to be in the list of the ~20 languages I'm writing on here.

So, let's see how it looks like and how it compares to the other langs in a minimal OO program :D 


By the way, you can see my previous post here: http://carlosqt.blogspot.com/2010/06/oo-hello-world.html
where I give some details on WHY these "OO Hello World series" samples. 


Version 1 (Minimal):
The minimum you need to type to get your program compiled and running.

class Greet {
    var _name: String
    construct(name: String) {
        _name = name.capitalize()  
    }
    function salute() {
        print("Hello ${_name}!")
    }
}

// Greet Program
var g = new Greet("world")
g.salute()

Version 2 (Verbose):
Explicitly adding instructions and keywords that are optional to the compiler.

//classpath "."
//package greetprogram
uses java.util.*

public class Greet {
    private var _name: String
    public construct(name: String) {
        this._name = name.capitalize()  
    }
    public function salute() {
        print("Hello ${this._name}!")
    }
}

// Greet Program
var g = new Greet("world")
g.salute()

The Program Output:









Gosu Info:
“Gosu is an imperative statically-typed object-oriented programming language that is designed to be expressive, easy-to-read, and reasonably fast. Gosu supports several resource types” Taken from: (http://gosu-lang.org/intro.shtml)

Appeared:
2010
Current Version:
Developed by:
Guidewire Software
Creator:

Influenced by:
Java (James Gosling)
Predecessor Language

Predecessor Appeared

Predecessor Creator

Runtime Target:
JVM
Latest Framework Target:
JDK 6
Mono Target:
No
Allows Unmanaged Code:
No
Source Code Extension:
“.gsp”
Keywords:
53
Case Sensitive:
Yes
Free Version Available:
Yes
Open Source:
Yes
Standard:

Latest IDE Support:
Eclipse
IntelliJ IDEA
Language Reference:
Extra Info:


3 comments:

  1. Some suggested edits:

    You can drop 'private' from the var. Vars default to private.

    Also, string has an enhancement method on it, capitalize() that does what you want:

    class Greet {
    var _name: String
    construct(name: String) {
    _name = name.capitalize()
    }
    function salute() {
    print("Hello ${_name}!")
    }
    }

    // Greet Program
    var g = new Greet("world")
    g.salute()

    ReplyDelete
  2. @Carson

    Thanks for your suggestion, updating code :)

    ReplyDelete
  3. i saw this article on The Hello World version of the program in Gosu. it's really informative for me. thanks for sharing this.

    ReplyDelete