Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: A Perl vs. Java fight brews

by ikegami (Patriarch)
on Jul 24, 2006 at 17:45 UTC ( [id://563332]=note: print w/replies, xml ) Need Help??


in reply to Re: A Perl vs. Java fight brews
in thread A Perl vs. Java fight brews

Sorry, Java is OO only.

I keep hearing this, but it makes no sense. A class filled with static members and methods is no different than a package filled with global variables and functions. Perl uses a methods as subs approach. Java uses a subs as methods approach. The syntax is different, but both are capable of procedural and OO programming.

Replies are listed 'Best First'.
Re^3: A Perl vs. Java fight brews
by philcrow (Priest) on Jul 24, 2006 at 17:54 UTC
    Yes, you can make all static classes and put a driving script in a main method in Java. But, not matter what, you must put all of that in a class. Hence the charge: Java is Object Oriented Only. We say this, because every single line of operative code must be in a method and every single method must be explicityly placed into a class. You can't just write a driver:
    print "driver starting\n"; `call_system_util1`; `call_system_util2`; print "driver finished\n";
    The equivalent code in Java must be in a method of some class. That's overkill in this case and it buys nothing except tedious typing, which is why we make the charge and it sticks.

    There are two subtle bits of syntatic sugar here. First, Perl puts things in the main package by default. Second, code does not have to appear in a method/sub/function/whatever. It can just go in a driving script. Perhaps these differences seem small, but they are real.

    Phil

      But, not matter what, you must put all of that in a class. Hence the charge: Java is Object Oriented Only.

      Same in Perl. If one is not specified explicitely, main is used.

      You can't just write a driver

      You can't have driver code in C either, but that doesn't stop you from coding procedurally in C. That Java can't have drive code does not preclude programmers from writting procedural Java programs.

      Perhaps these differences seem small, but they are real.

      I didn't say there weren't differences. (Quite the opposite.) I said programmers code procedurally in Java, so it's not only OO.

        I think you're both talking past each other here. What I believe he's trying to emphasize may be that while with perl you've got this:

        #!/usr/bin/perl print "Hello, world\n";

        In Java you're going to have to break out:

        public class HelloWorld { public static void main( String args[] ) { System.out.println( "Hello, world\n" ); } }

        Perl makes it dead simple to whip out call-this-call-this-call-this-boom-done style code, whereas to get the same thing in Java you've got to write a whole lot more overhead explicitly (i.e. you'd have a whole lot of static methods in some class rather than just a couple of subs hiding at the bottom of your quick, declarative Perl).

        Update: Upon reflection, that's probably not what they mean by OO only. Maybe someone's thinking "pure OO", but then Java's not (c.f. int and other primitive, non-object types). Never mind me.

        But maybe my last paragraph will be of some use to the OP.

        Or not. Meh.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://563332]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-16 19:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found