Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Perl Functionality in Java

by samtregar (Abbot)
on Nov 07, 2002 at 19:52 UTC ( #211204=note: print w/ replies, xml ) Need Help??


in reply to Perl Functionality in Java

I think you're making a mistake trying to program in Java like you program in Perl. Each language has its own set of metaphors and idioms. To reach optimal coding velocity you will need to learn a new way of doing things. Trying to import one language's metaphors and idioms into another is only going to impede your progress.

Case in point: C programmers that program Perl as though it were C with scalars. Of course they'd be twice as efficient if they realized they could replace all their for(;;) loops with foreach, map and grep, but they concentrate so hard on making Perl feel like C that they miss them completely.

-sam


Comment on Re: Perl Functionality in Java
Re: Re: Perl Functionality in Java
by djantzen (Priest) on Nov 07, 2002 at 20:12 UTC

    Trying to import one language's metaphors and idioms into another is only going to impede your progress.

    If this were strictly true Perl would not exist. It is commonly recognized that the strength our beloved language is that it freely borrows from other languages those idioms, constructs, methodologies that have proved effective and expressive.

    You are correct in saying that often people new to Perl attempt to write in the form of their favorite language -- I did this in moving from Java to Perl -- and thereby risk severely limiting their command of Perl. However, the importation of powerful idioms such as map, grep, foreach, et al, in no way restricts the expressiveness of Java. Quite the contrary, they have the chance to cut through the verbosity and rigidity of standard Java, thereby making the language more usable.

      If this were strictly true Perl would not exist.

      Hogwash. The problem presented is one of an experienced programmer in language X starting a new project in language Y. This is entirely different from the problem of a language designer, expert in both languages X and Y, creating a new language Z.

      However, the importation of powerful idioms such as map, grep, foreach, et al, in no way restricts the expressiveness of Java. Quite the contrary, they have the chance to cut through the verbosity and rigidity of standard Java, thereby making the language more usable.

      It's a possiblity, but I think the risk outweighs the potential gain. This might work out well for an experienced Java hacker that already has all the standard Java idioms at his fingertips. Mixing in some Perl might be a big help. However, for a Perl geek trying to swim in the Java swamp, these imported idioms will essentially act as a crutch. Worse, they will render his code unmaintainable by normal Java programmers. All in all, I think this is best avoided.

      -sam

        Hogwash. The problem presented is one of an experienced programmer in language X starting a new project in language Y. This is entirely different from the problem of a language designer, expert in both languages X and Y, creating a new language Z.

        Neither of us know how many languages the querent is familiar with (as opposed to fluent). If he has already written programs in 10+ languages (like me), it is fully legitimate to consider starting a new project in language Y to be a variant of creating a new language Z based in both languages X and Y. Besides, he needs something to analogize from. Since he's Perl-dominant, he should analogize from Perl.

        ... However, for a Perl geek trying to swim in the Java swamp, these imported idioms will essentially act as a crutch. Worse, they will render his code unmaintainable by normal Java programmers. All in all, I think this is best avoided.

        After learning Java. Not now: don't "put the cart before the horse". It might be wise for the querent to review the Java and C/C++ sections of the perltrap doc "in reverse".

        Since his employers dragged him into a Java project, they implicitly asked for these imported idioms. Furthermore, the project may be assumed to either be very well planned (in which case this should be anticipated), or very behind schedule (in which case they won't care).

        Assuming both adequate comments and compliance to corporate style guidelines, Java programmers that cannot maintain the resulting code probably can't write code, either. Interpreting Perl idioms in Java is easy, compared to interpreting them in ML. (Ever try emulating a grep or map with no loop control structures, only recursion and branching?)

        He will have to Java-ize these idioms for performance reasons, anyway. Think of it as rapid code prototyping followed by conversion of performance bottlenecks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2014-07-25 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (171 votes), past polls