From: mathew Date: 2005-07-26T03:40:59+09:00 Subject: Re: Ruby/Rails as a starter language? Trey Campbell wrote: > Put either of your examples in a different package and it (name) is no > longer visible. Right, because the whole point of packaging is to override the regular visibility of objects and methods, just like explicitly declaring the method private overrides its regular visibility. > Java doesn't have global variables. Java does provide for sharing among > classes in the same package if you choose not to specify more > restricted access. You can implement a class that's a singleton, but > there's no keyword to make it so. Again, I think you're playing semantic games. I don't really understand why Java programmers are so adamantly against admitting that their language supports global variables: Global.java: package my.globals; public class Global { public static String name = "John"; } Test.java: import my.globals.*; public class Test { public static void main(String[] argv) { System.out.println(my.globals.Global.name); my.globals.Global.name = "Oops"; System.out.println(my.globals.Global.name); } } Hey, look, it's a global variable. Any piece of code anywhere can read and write its value, all you need to do is stick import my.globals.* at the top of your code's source file to say you want to use global variables. Sure, this global variable has a long name with a bunch of dots in, and it's implemented via a class. But nevertheless, quack quack, it's a global variable. > In Java, static > means that there's a single copy shared by all instances of the class. > Nothing more. It has nothing at all to do with the variable's > visibility outside the owning class. ^^^^^^^^^^^^^^^^^^^^^^^^ Caveat noted. I guess ultimately I'm not really convinced of the rightness of the "classes are objects too, and their code can be executed even if no objects of that class exist" philosophy. I'm not going to let it stop me from writing Ruby, though. (For what it's worth, I used to think 'call by value' was the right way of doing things, and that 'call by reference' should be specially flagged. Ruby made me change my mind on that.) mathew -- WE HAVE TACOS