Java 1.5 adds printf functionality, saving some of the + absurdity. On Fri, 28 Jan 2005 14:19:14 +0900, Zach Dennis <zdennis / mktec.com> wrote: > Navindra Umanee wrote: > > Zach Dennis <zdennis / mktec.com> wrote: > > > >> - you can use string interpolation, ex: "x: #{@myvar}" instead of > >>having to say "x:" + myvar' > > > > > > Ruby seems to lose here. The syntax #{@myvar} is a rare case of > > ugliness. > > I don't know what the official ruling is, but when using variables you > can drop the {}. > > @a = "here i go again" > puts "#@a" > > @@a = ["here", " i", " go", " again" ] > puts "#@@a" > > Also you have to way in heredoc support, which java dont got: > > a = "interpolation" > b = "easier" > c = "You know what I'm saying" > str =<<END > i love string #{a}. > it makes my life #{b}. > #{c} > END > puts str > > The larger area of text you have to write the nicer it gets in ruby and > the more it sucks in java to have to write " + ". Especially when you > have really long strings and are dealing with newlines, spaces and tabs. > I like to neatly format my source and have it be a max of 72 to 80 > characters per line. I hate writing long text in java because I end up > having ugly source on 10-15 lines with a gazillion " + " and \n's that > is hard to visually parse out or I have 50 lines of + " ..." on it's > own line. > > No matter what you say, I prefer doing interpolation over " + " anyday. > I've writtent 15 times the amount of java code in thepast few months for > work-related reasons then i have in ruby, you would think I'd prefer the > " + " way... > > > >> - ruby doesn't force you to have 1 file per public class, you can have > >>all the public classes you want in a file (not that you have to do this, > >>but it's a nice option to have) > > > > > > On the other hand, if you *want* to put each class in a file, you end > > up having to painfully "require" each file every time you want to > > access a class. Java can automatically find classes in the current > > package and load them. Or is just me? Is there a Ruby Way? > > This totally depends on how you use your code. Most likely you won't > need to access every file from it's src file. And if you do it is best > to design a loader class: > > In main.rb you have: > require "gui/gui" > require "data/data" > > - gui/gui.rb which loads all required files for module GUI > - data/data.rb which loads all required files for module DATA > > in gui.rb you have: > require "layout" > require "fonts" > require "2dapi" > require "3dapi" > > and similar in data/data.rb. > > You don't have to require each individual file you just have to design > your program. I am not saying what you say wouldn't be nice, and someone > may already have a modification to *require* for this to work, but you > are not hindered right now in doing this, it just requires more > discipline on the design and access of your code. > > And back to a java principle...alot java code are for one or two lines > of code that use ((MyClass)getGenericObject()).setThis( true ); > > In Ruby you don't have to say "require myclass" just to do that. You > just say: > > get_obj.this = true > > Zach > > -- Nicholas Van Weerdenburg