Re: Perl Pro but Java Newbie: Need nudge in proper direction for my
favorite Perl routine in Java
On Sep 14, 12:24 pm, Mark Space <marksp...@sbcglobal.net> wrote:
/usr/ceo wrote:
I'm using Eclipse (Ganymede) on Mac OS X. I'll have to try that. =
In
general, I'm also learning about the Eclipse-type editing platform,
I'm sure Eclipse has some abbreviation system, but the one is not based
on the other, and I don't know what the key sequence is for Eclipse.
NetBeans = Sun, Eclipse = IBM. IBM also makes it's own GUI (SWT) v=
s.
Sun's Swing, IBM has their own web container (JBoss), etc. While
competition is good for us programmers, in terms of market I think they
get on like cats and dogs.
This is mainly for
my own use for now.
To be a bit less obtuse, there's still problems with your puts() method.
You can define it to take a variable number of Objects (which include=
s
Strings), or you can make it take primitives, but you can't mix the two.
void puts( Object ... o ) {}
void puts( int ... i ) {}
These are two overloaded puts() methods, but you still can't put ints in
an array of Objects. Java is more strongly typed than Perl, so it
doesn't allow you to mix the two. However, with concatenation, you can
mix them.
class TestOut {
public static void main ( Strings ... args ) {
int i = 5;
Object o = new Object();
javax.swing.JLabel label = new javax.swing.JLabel( "Hi" );
System.out.println( "I have " + i + " ints and I have " +
"\nthis " + o + " thin=
g here and " +
"\nI have a JLabel " +=
label + "." +
"\nHave a nice day!"
);
}
}
This is more the Java idiom, and it works pretty well. You're basicall=
y
substituting a + for a , which is not any different in typing imo. With
puts(), you still have to type all the parameters, and put a comma after
each one instead of the plus sign I have.
In Java, this is also faster, since calls to the IO system tend to be
slow. The above code creates one single buffer, and send the whole
thing to the println() method in one call. If you use a for loop in
puts(), you have to make multiple calls, and if you call "new" to make
integers into objects (to pass the ints as parameters with Object[]),
then you're getting even more inefficient.
So I think you should just get used to using the abbreviation (whatever
Eclipse uses instead of "sout") and type a + instead of a comma. It'll
help you learn Java, and it's no real extra work. (Note: no code in
this post was tested or compiled.)
All very good things to point out, thanks. I'm becoming more and more
convinced although the exercise has been helpful on more than on
level.
It's not just Java, but all languages that don't allow instring
substitution that I've never really liked. It drives me buts to have
to write plus signs (+) inbetween static strings to concat variables.
I know JavaScript quite well, and I've always disliked this about
JavaScript as well as Visual Basic and VB.Net and others. I just have
an aversion to it and it's not just Perl-influenced. It goes back
farther for me with VMS DCL which allowed the same thing, as does Perl
as does Ruby.
But it's all starting to get OT and philosophical. I believe it may
be better to just acquiesce to it all. The mixed objects example and
all makes it obvious I'm trying to super-impose a methodology from
another language that works quite well into a language that goes about
things a little differently, and it's not necessarily a bad thing.
I'm thinking that the "compile"-phase of Java is what resolves the
different objects in your example above. My "approach" moves it from
compile to runtime. So it seems.
/usr/ceo