Created
January 12, 2011 09:22
-
-
Save mrdaemon/775922 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HelloWorld : Object { | |
public string name { get ; set; default = "World"; } | |
public HelloWorld() { | |
/* Huh. With properties accessed like fields, | |
and able to have default values, turns out I don't | |
actually have to do this. At all. Sweet shorthand, | |
Vala. Your syntactic sugar is growing on me. */ | |
//this.with_name("World"); | |
} | |
/** | |
* By the way: | |
* I'm doing this to toy with the language. Just so you know, | |
* I could very well forfeit all of this bullshit and write | |
* stdout.printf("Hello, %s!\n", name ?? "World"); | |
* I'm starting to like this language. | |
*/ | |
public HelloWorld.with_name(string name) { | |
this.name = name; | |
} | |
public void run() { | |
stdout.printf("Hello, %s\n", this.name); | |
} | |
public bool hasname() { | |
return this.name != "World"; | |
} | |
} | |
int main(string[] args) { | |
HelloWorld world_hello = new HelloWorld(); | |
HelloWorld named_hello = new HelloWorld.with_name("Alex"); | |
world_hello.run(); // Greet the world | |
named_hello.run(); // Greet me :) | |
/* SUDDENDLY, CHANGING PUBLIC PROPERTIES! Fuck off, accessors. */ | |
named_hello.name = "Bob McBoberton"; | |
named_hello.run(); // Greet BobMcBoberton. | |
if(!world_hello.hasname()){ | |
stdout.printf("Hey, the world greeting has no name.\n" + | |
"That's kinda boring, no? Let's use it to greet " + | |
"some unpleasant person instead.\n"); | |
world_hello.name = "you nasty gormless git"; | |
} | |
world_hello.run(); // Greet the nasty person. | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment