Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Perl Pro but Java Newbie: Need nudge in proper direction for myfavorite Perl routine in Java

Reply
Thread Tools

Perl Pro but Java Newbie: Need nudge in proper direction for myfavorite Perl routine in Java

 
 
/usr/ceo
Guest
Posts: n/a
 
      09-14-2008
Okay, unforeseen circumstances have necessitated that I learn Java.
I'll refrain from providing my opinion of Java and extremely high
overhead compared to Perl, but... whatever.

Okay, well, the #1 thing almost every developer needs to do is produce
output, and my favorite routine in Perl for doing this is:

sub puts { for (@_) { print "$_\n" } } # Modeled after Ruby's puts()
routine (mostly).

In Perl, that means I can:

puts( "This is a single line" );

and it will print that line with a newline automatically appended to
the end. But even better, I can:

puts(
"This is line 1",
"This is line 2",
"This is line 3",
"You get the picture..."
);

And all those lines are printed with no adjustments needed to the
puts() routine in Perl. It also allows me to do things like:

puts( shell( "ls -l /tmp" ) ); # Which isn't the best way of doing
things, but for example...

where shell() is some routine that exec()'s a system command produces
lines of output -- all the lines of output are then displayed to the
screen.

How can I do this in Java? I am assuming I can write a puts() routine
that is overloaded in some way so I can pass a single string or an
array of strings and either way it does what I want. I tried this and
it seems to be proper syntax (inside a class with a main()):

Display.java:
package com.myorg.utils;

pubic class Display {

public static void puts( String[] args ) {
for (int i=0; i<args.length; i++)
__puts( arg[i] );
}

public static void puts( String arg ) {
__puts( arg );
}

private static void __puts( String arg )
{ System.out.println( arg ); }

}

TestPuts.java
import com.myorg.utils.Display;

public class TestPuts {

public static void main( String[] args ) {
puts( "A single string test." );
// This is specifically where I seem to be having trouble
passing a
// String[] array to the puts( String[] args ) call
implementation.
// But maybe the implementation itself in the Display class
isn't
// the way to go?
puts( {
"This is line 1",
"This is line 2",
"This is line 3"
} );
}

private static void puts( String[] args ) { Display.puts( args ); }
private static void puts( String arg ) { Display.puts( arg ); }

}

Everything seems fine as far has the implementation goes in the
Display class. But maybe that's the wrong way to go about it? I
can't believe I have to use a fifty letter package name class method
to print a line to the console. (This is one of the things I hate
about Java, but anyway...)

So... Someone who knows Perl and Java both... Maybe you can help me
out. Or someone who knows Java can at least see what I am attempting
to do. Again, this seems extremely bogus to even have to do. Look
how elegant the Perl solution is... But I should get off my soapbox I
guess and just ask for help. (Can you tell I'm irritated that I have
to learn Java???!!! )

/usr/ceo
 
Reply With Quote
 
 
 
 
/usr/ceo
Guest
Posts: n/a
 
      09-14-2008
On Sep 13, 11:40*pm, "/usr/ceo" <news...@cox.net> wrote:

[snipage]

> Display.java:
> package com.myorg.utils;
>
> pubic class Display {
>
> * *public static void puts( String[] args ) {
> * * * for (int i=0; i<args.length; i++)
> * * * * *__puts( arg[i] );
> * *}
>
> * *public static void puts( String arg ) {
> * * * __puts( arg );
> * *}
>
> * *private static void __puts( String arg )
> { System.out.println( arg ); }
>
> }


Okay... ha, ha... Trust me. There is nothing "pubic" about
Display. It was defined properly as "public". Yes, I retyped it
and didn't cut and paste. My private __puts() routine was slightly
different, but it has no bearing, I don't feel, on the question and
simplifies things a little.

/usr/ceo
 
Reply With Quote
 
 
 
 
tomaszewski.p
Guest
Posts: n/a
 
      09-14-2008
On 14 Wrz, 06:40, "/usr/ceo" <news...@cox.net> wrote:
> Okay, unforeseen circumstances have necessitated that I learn Java.
> I'll refrain from providing my opinion of Java and extremely high
> overhead compared to Perl, but... whatever.
>
> Okay, well, the #1 thing almost every developer needs to do is produce
> output, and my favorite routine in Perl for doing this is:
>
> sub puts { for (@_) { print "$_\n" } } # Modeled after Ruby's puts()
> routine (mostly).
>
> In Perl, that means I can:
>
> puts( "This is a single line" );
>
> and it will print that line with a newline automatically appended to
> the end. *But even better, I can:
>
> puts(
> * *"This is line 1",
> * *"This is line 2",
> * *"This is line 3",
> * *"You get the picture..."
> );
>
> And all those lines are printed with no adjustments needed to the
> puts() routine in Perl. *It also allows me to do things like:
>
> puts( shell( "ls -l /tmp" ) ); *# Which isn't the best way of doing
> things, but for example...
>
> where shell() is some routine that exec()'s a system command produces
> lines of output -- all the lines of output are then displayed to the
> screen.
>
> How can I do this in Java? *I am assuming I can write a puts() routine
> that is overloaded in some way so I can pass a single string or an
> array of strings and either way it does what I want. *I tried this and
> it seems to be proper syntax (inside a class with a main()):
>
> Display.java:
> package com.myorg.utils;
>
> pubic class Display {
>
> * *public static void puts( String[] args ) {
> * * * for (int i=0; i<args.length; i++)
> * * * * *__puts( arg[i] );
> * *}
>
> * *public static void puts( String arg ) {
> * * * __puts( arg );
> * *}
>
> * *private static void __puts( String arg )
> { System.out.println( arg ); }
>
> }
>
> TestPuts.java
> import com.myorg.utils.Display;
>
> public class TestPuts {
>
> * *public static void main( String[] args ) {
> * * * puts( "A single string test." );
> * * * // This is specifically where I seem to be having trouble
> passing a
> * * * // String[] array to the puts( String[] args ) call
> implementation.
> * * * // But maybe the implementation itself in the Display class
> isn't
> * * * // the way to go?
> * * * puts( {
> * * * * *"This is line 1",
> * * * * *"This is line 2",
> * * * * *"This is line 3"
> * * * } );
> * *}
>
> * *private static void puts( String[] args ) { Display.puts( args ); }
> * *private static void puts( String arg ) { Display.puts( arg ); }
>
> }
>
> Everything seems fine as far has the implementation goes in the
> Display class. *But maybe that's the wrong way to go about it? *I
> can't believe I have to use a fifty letter package name class method
> to print a line to the console. *(This is one of the things I hate
> about Java, but anyway...)
>
> So... *Someone who knows Perl and Java both... *Maybe you can help me
> out. *Or someone who knows Java can at least see what I am attempting
> to do. *Again, this seems extremely bogus to even have to do. *Look
> how elegant the Perl solution is... *But I should get off my soapbox I
> guess and just ask for help. *(Can you tell I'm irritated that I have
> to learn Java???!!! )
>
> /usr/ceo


Probably you are searching for 'static imports':
http://java.sun.com/j2se/1.5.0/docs/...ic-import.html

Przemek
 
Reply With Quote
 
/usr/ceo
Guest
Posts: n/a
 
      09-14-2008
On Sep 14, 12:50*am, "tomaszewski.p" <kssw...@gmail.com> wrote:
> On 14 Wrz, 06:40, "/usr/ceo" <news...@cox.net> wrote:
>
> > TestPuts.java
> > import static com.myorg.utils.Display.*;

>
> > public class TestPuts {

>
> > * *public static void main( String[] args ) {
> > * * * puts( "A single string test." );
> > * * * // This is specifically where I seem to be having trouble
> > passing a
> > * * * // String[] array to the puts( String[] args ) call
> > implementation.
> > * * * // But maybe the implementation itself in the Display class
> > isn't
> > * * * // the way to go?
> > * * * puts( {
> > * * * * *"This is line 1",
> > * * * * *"This is line 2",
> > * * * * *"This is line 3"
> > * * * } );
> > * *}

>
> > * *// Don't need these any more with static imports...
> > // private static void puts( String[] args ) { Display.puts( args ); }
> > * *// private static void puts( String arg ) { Display.puts( arg ); }

>
> > }

>
> > Everything seems fine as far has the implementation goes in the
> > Display class. *But maybe that's the wrong way to go about it? *I
> > can't believe I have to use a fifty letter package name class method
> > to print a line to the console. *(This is one of the things I hate
> > about Java, but anyway...)

>
> > So... *Someone who knows Perl and Java both... *Maybe you can help me
> > out. *Or someone who knows Java can at least see what I am attempting
> > to do. *Again, this seems extremely bogus to even have to do. *Look
> > how elegant the Perl solution is... *But I should get off my soapbox I
> > guess and just ask for help. *(Can you tell I'm irritated that I have
> > to learn Java???!!! )

>
> > /usr/ceo

>
> Probably you are searching for 'static imports':http://java.sun.com/j2se/1.5.0/docs/...ic-import.html
>
> Przemek


Alright, boss... That takes care of the over-implementation of
puts() in the TestPuts class with the essentially puts() wrappers.
That still doesn't solve my problem of being able to call puts() with
a single line or with multiple lines... How do I do that? I want to
be able to do this:

puts( "This is a line" );

and this:

// How do I even specify multiple lines??
// I'm using some kind of "anonymous array" notation
// below, that looks "made up." Eclipse doesn't
// like the following:

puts( {
"This is line 1",
"This is line 2",
"This is line 3"
} );

So, that static imports thing can come in handy (and I understand the
anti-pattern behind it from Java's perspective of polluting names
spaces from the URL you provide -- nice.) But the main thing I want,
I'm still not getting...

We need to concentrate on the Display class now. Is that right?
Doesn't seem like it...

/usr/ceo
 
Reply With Quote
 
/usr/ceo
Guest
Posts: n/a
 
      09-14-2008
On Sep 14, 1:34*am, "/usr/ceo" <news...@cox.net> wrote:
> On Sep 14, 12:50*am, "tomaszewski.p" <kssw...@gmail.com> wrote:
>
>
>
> > On 14 Wrz, 06:40, "/usr/ceo" <news...@cox.net> wrote:

>
> > > TestPuts.java
> > > import static com.myorg.utils.Display.*;

>
> > > public class TestPuts {

>
> > > * *public static void main( String[] args ) {
> > > * * * puts( "A single string test." );
> > > * * * // This is specifically where I seem to be having trouble
> > > passing a
> > > * * * // String[] array to the puts( String[] args ) call
> > > implementation.
> > > * * * // But maybe the implementation itself in the Display class
> > > isn't
> > > * * * // the way to go?
> > > * * * puts( {
> > > * * * * *"This is line 1",
> > > * * * * *"This is line 2",
> > > * * * * *"This is line 3"
> > > * * * } );
> > > * *}

>
> > > * *// Don't need these any more with static imports...
> > > * *// private static void puts( String[] args ) { Display.puts( args ); }
> > > * *// private static void puts( String arg ) { Display.puts( arg ); }

>
> > > }

>
> > > Everything seems fine as far has the implementation goes in the
> > > Display class. *But maybe that's the wrong way to go about it? *I
> > > can't believe I have to use a fifty letter package name class method
> > > to print a line to the console. *(This is one of the things I hate
> > > about Java, but anyway...)

>
> > > So... *Someone who knows Perl and Java both... *Maybe you can help me
> > > out. *Or someone who knows Java can at least see what I am attempting
> > > to do. *Again, this seems extremely bogus to even have to do. *Look
> > > how elegant the Perl solution is... *But I should get off my soapbox I
> > > guess and just ask for help. *(Can you tell I'm irritated that I have
> > > to learn Java???!!! )

>
> > > /usr/ceo

>
> > Probably you are searching for 'static imports':http://java.sun.com/j2se/1.5.0/docs/...ic-import.html

>
> > Przemek

>
> Alright, boss... *That takes care of the over-implementation of
> puts() in the TestPuts class with the essentially puts() wrappers.
> That still doesn't solve my problem of being able to call puts() with
> a single line or with multiple lines... *How do I do that? *I want to
> be able to do this:
>
> puts( "This is a line" );
>
> and this:
>
> // How do I even specify multiple lines??
> // I'm using some kind of "anonymous array" notation
> // below, that looks "made up." *Eclipse doesn't
> // like the following:
>
> puts( {
> * *"This is line 1",
> * *"This is line 2",
> * *"This is line 3"
>
> } );
>
> So, that static imports thing can come in handy (and I understand the
> anti-pattern behind it from Java's perspective of polluting names
> spaces from the URL you provide -- nice.) *But the main thing I want,
> I'm still not getting...
>
> We need to concentrate on the Display class now. *Is that right?
> Doesn't seem like it...
>
> /usr/ceo


And I made the Display class "final" for you purists out there (of
which I would agree, which is why I did it). That's just a purist
thing. The implementation is still the open question.

Thanks all!
/usr/ceo
 
Reply With Quote
 
M@hdeTo
Guest
Posts: n/a
 
      09-14-2008
On Sep 14, 8:36*am, "/usr/ceo" <news...@cox.net> wrote:
> On Sep 14, 1:34*am, "/usr/ceo" <news...@cox.net> wrote:
>
>
>
> > On Sep 14, 12:50*am, "tomaszewski.p" <kssw...@gmail.com> wrote:

>
> > > On 14 Wrz, 06:40, "/usr/ceo" <news...@cox.net> wrote:

>
> > > > TestPuts.java
> > > > import static com.myorg.utils.Display.*;

>
> > > > public class TestPuts {

>
> > > > * *public static void main( String[] args ) {
> > > > * * * puts( "A single string test." );
> > > > * * * // This is specifically where I seem to be having trouble
> > > > passing a
> > > > * * * // String[] array to the puts( String[] args ) call
> > > > implementation.
> > > > * * * // But maybe the implementation itself in the Display class
> > > > isn't
> > > > * * * // the way to go?
> > > > * * * puts( {
> > > > * * * * *"This is line 1",
> > > > * * * * *"This is line 2",
> > > > * * * * *"This is line 3"
> > > > * * * } );
> > > > * *}

>
> > > > * *// Don't need these any more with static imports...
> > > > * *// private static void puts( String[] args ) { Display.puts( args ); }
> > > > * *// private static void puts( String arg ) { Display.puts( arg ); }

>
> > > > }

>
> > > > Everything seems fine as far has the implementation goes in the
> > > > Display class. *But maybe that's the wrong way to go about it? *I
> > > > can't believe I have to use a fifty letter package name class method
> > > > to print a line to the console. *(This is one of the things I hate
> > > > about Java, but anyway...)

>
> > > > So... *Someone who knows Perl and Java both... *Maybe you can help me
> > > > out. *Or someone who knows Java can at least see what I am attempting
> > > > to do. *Again, this seems extremely bogus to even have to do. *Look
> > > > how elegant the Perl solution is... *But I should get off my soapbox I
> > > > guess and just ask for help. *(Can you tell I'm irritated that I have
> > > > to learn Java???!!! )

>
> > > > /usr/ceo

>
> > > Probably you are searching for 'static imports':http://java.sun.com/j2se/1.5.0/docs/...ic-import.html

>
> > > Przemek

>
> > Alright, boss... *That takes care of the over-implementation of
> > puts() in the TestPuts class with the essentially puts() wrappers.
> > That still doesn't solve my problem of being able to call puts() with
> > a single line or with multiple lines... *How do I do that? *I want to
> > be able to do this:

>
> > puts( "This is a line" );

>
> > and this:

>
> > // How do I even specify multiple lines??
> > // I'm using some kind of "anonymous array" notation
> > // below, that looks "made up." *Eclipse doesn't
> > // like the following:

>
> > puts( {
> > * *"This is line 1",
> > * *"This is line 2",
> > * *"This is line 3"

>
> > } );

>
> > So, that static imports thing can come in handy (and I understand the
> > anti-pattern behind it from Java's perspective of polluting names
> > spaces from the URL you provide -- nice.) *But the main thing I want,
> > I'm still not getting...

>
> > We need to concentrate on the Display class now. *Is that right?
> > Doesn't seem like it...

>
> > /usr/ceo

>
> And I made the Display class "final" for you purists out there (of
> which I would agree, which is why I did it). *That's just a purist
> thing. *The implementation is still the open question.
>
> Thanks all!
> /usr/ceo


if you are using java >= 5

you can do varargs like this:

public static void puts(String... args){
for(String arg:args)
System.out.println(arg);
}

you can call this the same way you call the perl version and using
static imports will make your code look prettier:

puts("this is just one line");
puts(
"this is line one",
"this is line two",
"this is line three"
);

you can even call it with an array:

String[] someResults = {"res1","res2","res3"};
puts(someResults);
 
Reply With Quote
 
Stanimir Stamenkov
Guest
Posts: n/a
 
      09-14-2008
Sat, 13 Sep 2008 21:40:55 -0700 (PDT), //usr/ceo/:

> puts( "This is a single line" );
>
> and it will print that line with a newline automatically appended to
> the end. But even better, I can:
>
> puts(
> "This is line 1",
> "This is line 2",
> "This is line 3",
> "You get the picture..."
> );
>
> And all those lines are printed with no adjustments needed to the
> puts() routine in Perl.


With Java 5 ant later you can use the the Varargs syntax
<http://java.sun.com/j2se/1.5.0/docs/guide/language/varargs.html>:

public static void puts(String... lines) {
for (String s : lines) {
System.out.println(s);
}
}

> It also allows me to do things like:
>
> puts( shell( "ls -l /tmp" ) ); # Which isn't the best way of doing
> things, but for example...


public static void main(String[] args) {
puts("This is a single line");

String[] lines = {
"This is line 1",
"This is line 2",
"This is line 3",
"You get the picture..."
};
puts(lines);

// This one requires Java 5 and the Varargs variant.
puts("This is line 1",
"This is line 2",
"This is line 3",
"You get the picture...");
}

> public class TestPuts {
>
> public static void main( String[] args ) {
> puts( "A single string test." );
> // This is specifically where I seem to be having trouble
> passing a
> // String[] array to the puts( String[] args ) call
> implementation.
> // But maybe the implementation itself in the Display class
> isn't
> // the way to go?
> puts( {
> "This is line 1",
> "This is line 2",
> "This is line 3"
> } );


puts(new String[] {
"This is line 1",
"This is line 2",
"This is line 3"
});

> }
>
> private static void puts( String[] args ) { Display.puts( args ); }
> private static void puts( String arg ) { Display.puts( arg ); }
>
> }


--
Stanimir
 
Reply With Quote
 
RedGrittyBrick
Guest
Posts: n/a
 
      09-14-2008

You can do this in Java:
puts( "A single string test." );

puts( myStringArray );

puts( new String[] {
"This is line 1",
"This is line 2",
"This is line 3"
});

puts(exec("cmd /c dir"));

/usr/ceo wrote:
> Okay, unforeseen circumstances have necessitated that I learn Java.
> I'll refrain from providing my opinion of Java and extremely high
> overhead compared to Perl, but... whatever.


You failed to refrain!

>
> Okay, well, the #1 thing almost every developer needs to do is produce
> output, and my favorite routine in Perl for doing this is:
>
> sub puts { for (@_) { print "$_\n" } } # Modeled after Ruby's puts()
> routine (mostly).
>
> In Perl, that means I can:
>
> puts( "This is a single line" );
>
> and it will print that line with a newline automatically appended to
> the end. But even better, I can:
>
> puts(
> "This is line 1",
> "This is line 2",
> "This is line 3",
> "You get the picture..."
> );
>
> And all those lines are printed with no adjustments needed to the
> puts() routine in Perl. It also allows me to do things like:
>
> puts( shell( "ls -l /tmp" ) ); # Which isn't the best way of doing
> things, but for example...
>
> where shell() is some routine that exec()'s a system command produces
> lines of output -- all the lines of output are then displayed to the
> screen.
>
> How can I do this in Java? I am assuming I can write a puts() routine
> that is overloaded in some way so I can pass a single string or an
> array of strings and either way it does what I want.


You can.

> I tried this and
> it seems to be proper syntax (inside a class with a main()):


It isn't the best way to achieve what you want.

>
> Display.java:
> package com.myorg.utils;
>
> pubic class Display {
>
> public static void puts( String[] args ) {
> for (int i=0; i<args.length; i++)
> __puts( arg[i] );
> }
>
> public static void puts( String arg ) {
> __puts( arg );
> }
>
> private static void __puts( String arg )
> { System.out.println( arg ); }


Ick. You save ~24 chars at the expense of ~70. Poor tradeoff.


>
> }
>
> TestPuts.java
> import com.myorg.utils.Display;
>
> public class TestPuts {
>
> public static void main( String[] args ) {
> puts( "A single string test." );
> // This is specifically where I seem to be having trouble
> passing a
> // String[] array to the puts( String[] args ) call
> implementation.
> // But maybe the implementation itself in the Display class
> isn't
> // the way to go?


It isn't.

> puts( {
> "This is line 1",
> "This is line 2",
> "This is line 3"
> } );
> }
>
> private static void puts( String[] args ) { Display.puts( args ); }
> private static void puts( String arg ) { Display.puts( arg ); }


Ick! In most languages, when I find myself writing ugly code, I'm
certain there is a better way to write it. Occasionally there isn't of
course.


>
> }
>
> Everything seems fine as far has the implementation goes in the
> Display class. But maybe that's the wrong way to go about it?


Yes.


> I
> can't believe I have to use a fifty letter package name class method
> to print a line to the console.


You don't, though Java I/O is overly complex IMHO.


> (This is one of the things I hate about Java, but anyway...)


There's things I hate about Perl, that doesn't stop me loving Perl!
Generally I try not to rant about language X in a language Y forum.
It antagonises potential helpers.


> So... Someone who knows Perl and Java both... Maybe you can help me
> out. Or someone who knows Java can at least see what I am attempting
> to do. Again, this seems extremely bogus to even have to do. Look
> how elegant the Perl solution is...


Stop pining for Perl. You'll feel better.


> But I should get off my soapbox I guess and just ask for help.


You really should have.


> (Can you tell I'm irritated that I have to learn Java???!!! )


You're the only one who will be harmed by having that attitude. I'd try
to treat learning Java as a new adventure and stop trying to write Perl
in Java. They are very different languages - I'd try to accept that.
YMMV


------------------------------8<----------------------------------
package org.redgrittybrick.test;

import static org.redgrittybrick.test.PutUtils.*;

import java.io.IOException;

public class PutsTest {
public static void main(String[] args) throws IOException {
puts( "A single string test." );
puts( new String[] {
"This is line 1",
"This is line 2",
"This is line 3"
});
puts(exec("cmd /c dir"));
}
}
------------------------------8<----------------------------------
package org.redgrittybrick.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PutUtils {

public static void puts(String... args) {
for (String arg : args)
System.out.println("["+arg+"]");
}

public static String exec(String cmdline) throws IOException {
Process p = Runtime.getRuntime().exec(cmdline);
BufferedReader input = new BufferedReader( //
new InputStreamReader(p.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = input.readLine()) != null)
sb.append(line+"\n");
input.close();
return sb.toString();
}
}
------------------------------8<----------------------------------

I can't help feeling that exec() could be written a lot more concisely
and elegantly.

--
RGB
 
Reply With Quote
 
Joshua Cranmer
Guest
Posts: n/a
 
      09-14-2008
/usr/ceo wrote:
> pubic class Display {
>
> public static void puts( String[] args ) {
> for (int i=0; i<args.length; i++)
> __puts( arg[i] );
> }
>
> public static void puts( String arg ) {
> __puts( arg );
> }
>
> private static void __puts( String arg )
> { System.out.println( arg ); }
>
> }


This can be reduced to:

public class Display {
public static void puts(String... args) {
for (String arg : args)
System.out.println(arg);
}
}

(Uses variable arguments and the for-each loop, both features of Java 5
and above).

> import com.myorg.utils.Display;
>
> public class TestPuts {
>
> public static void main( String[] args ) {
> puts( "A single string test." );
> // This is specifically where I seem to be having trouble
> passing a
> // String[] array to the puts( String[] args ) call
> implementation.
> // But maybe the implementation itself in the Display class
> isn't
> // the way to go?
> puts( {
> "This is line 1",
> "This is line 2",
> "This is line 3"
> } );
> }
>
> private static void puts( String[] args ) { Display.puts( args ); }
> private static void puts( String arg ) { Display.puts( arg ); }
>
> }


As others have said, this can be reduced to this:
// No need for the general import if all you have is the static function
import static com.myorg.utils.Display.puts;

public class TestPuts {
public static void main(String... args) {
puts("A single string test.");
puts("This is line 1",
"This is line 2",
"This is line 3");
}
}

> Everything seems fine as far has the implementation goes in the
> Display class. But maybe that's the wrong way to go about it? I
> can't believe I have to use a fifty letter package name class method
> to print a line to the console. (This is one of the things I hate
> about Java, but anyway...)


Perl tends more towards a procedural programming paradigm, while Java is
more OOP. The act of printing to the console is theoretically rare in a
Java app, over the act of printing to an unspecified stream, e.g. it
could be a log or a console. So the console output stream is but one
stream among many, that would only be set at some configuration time.


--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      09-14-2008
/usr/ceo wrote:

> Display class. But maybe that's the wrong way to go about it? I
> can't believe I have to use a fifty letter package name class method
> to print a line to the console. (This is one of the things I hate


I think the right way to go about it would be to get an IDE that handles
abbreviations and macros efficiently. I use NetBeans. It will
substitute the string "sout" followed by a tab to
"System.out.println("");" and put the cursor in the center of the inner
quotes. So I type 5 characters, not 23.

Programmers who come after you aren't going to be terribly excited about
your attempts to custom re-wire the IO classes. They're fine the way
they are.

And "puts" as-is won't handle objects besides string literals, or
primitives, without a lot of work which will duplicate what System.out
does now anyway. So the path you are going down is pretty much lose-lose.


BTW:

System.out.println(
"This is line 1\n" +
"This is line 2\n" +
"This is line 3\n" +
"You get the picture..."
);

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nudge needed for rst to html Tim Golden Python 0 09-06-2007 11:16 AM
"Nudge" in Microsoft Publisher 2002 John Computer Support 1 02-21-2006 08:55 PM
Can share files one direction but not the other =?Utf-8?B?Q2FybEs=?= Wireless Networking 0 12-04-2004 03:15 AM
Wireless LAN works great one direction, but not the other Thomas J. Computer Support 3 05-03-2004 02:52 AM
passion for programming but need a little direction jqpdev MCAD 4 12-01-2003 02:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57