Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I like Perl. I know Perl to a reasonably good extent. I have worked with Perl for a number of years. I am trying to learn Java. What it can add to my Perl experience? I am sure, there are people here who have learned both languages and worked with them. I am seeking the invaluable feedback.

Thank you.

Replies are listed 'Best First'.
Re: Perl "with" Java
by moritz (Cardinal) on Nov 23, 2009 at 13:57 UTC
    I think the best advise is Don't try to write Perl code in Java, and also applies to any programming language you might learn.

    What it means is that with Perl you not only learn the language, but also idioms (usage patterns) and usage of basic libraries.

    So you shouldn't try too hard to apply Perl idioms in Java (or the other way round, for that matter) -- that would be very ugly code. Instead you should learn the Java idioms along with the Java language.

    That said Java is very different from Perl in many ways; it might be best to forget much of what you've learned, except about the importance of consistent code layout, consistent naming and automated unit tests.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Perl "with" Java
by BioLion (Curate) on Nov 23, 2009 at 14:24 UTC

    I am going through similar stresses at the moment, and to reiterate moritz's advice, Java and Perl really don't bear much similarity, and aren't really learned in the same way. However, I do really think it is worth while, because I feel ( and this is just, like, my opinion man, and i am sure a lot of differing opinions exist... ) that Perl and Java, in combination, give you the skills to approach a huge diversity of problems.

    Perl, for me, has the benefit of short development time, a great support community and a vast library of public code. Which makes it superb for getting things done.

    However for larger applications, especially graphical ones, Java comes into it's own. Being fully OO, and with strict typing, development (in terms of bug-fixing especially) and leaving a lasting legacy (rather than a maintainers nightmare) becomes much more feasible, at the cost of being much more wordy and all the other usual complaints. Also, because people tend to rely most heavily on the core libraries, it is a little bit easier to make applications that work 'out of the box'.

    I am still getting the hang of Java, and my knowledge is much worse than for Perl (which even then isn't anything to boast about!), but one lesson i have learned already is better project management. Java makes you think and plan in advance a lot more, which has certainly imporved my coding in Perl, and it has helped me understand OO concepts better ( like abstraction and encapsulation ) which again has improved my Perl.

    Also in general, I find myself thinking which language would best suit the project, whether this is something i just need to get done, or something which i will build on for years to come and make into a huge 1000's of lines project.

    Big projects seemed to me to be Perl's weakness, which was why i looked into Java ( and to improve *job* options... ) and i think the two complement each other well, as opposed to Python / Ruby etc... which seem to also be very popular, but in my mind stand a bit in the middle ground and are neither as good at the swiss-army-chainsaw stuff as Perl, or as good as Java for bigger applications. I hear very good things about Ruby though, especially the Rails stuff, but i am not really a web-person, so i haven't put too much time into it.

    Anyway, I guess my point is that Java and Perl are very different, but that is a good thing. As moritz said, you shouldn't try to combine the two, but really try to understand their respective strengths and weaknesses and apply them to each problem in the best way.

    Just a something something...
      My take on large projects in Perl is that they can be done well and elegantly, but often aren't. I think part of the problem is just how fast you can develop in Perl, a lot of things start out small and grow big. People don't always take the time to fix the old code up to prepare it to move to the big time, and you end up with something more organic than structured. Perl can make great large systems with proper attention spent. :) Java being more rigid forces that mindset more, but takes forever to work with compared to Perl (and has the ugliest errors in the world)

                      - Ant
                      - Some of my best work - (1 2 3)

        I agree - i guess that was the point i was trying to make! I didn't mean to say that big projects are *never* any good in Perl, just that Java makes it a lot easier for you. I think your point about the speed of Perl development almost being the problem in this case is a very good one!

        Just a something something...
Re: Perl "with" Java
by dHarry (Abbot) on Nov 23, 2009 at 14:50 UTC

    I use both languages a lot. They are completely different and it's best not to mix them. When I use a lot of Perl my Java becomes weak and vice-versa. IMO Java can add a lot to your Perl experience. Sure, nothing beats the expressive power of Perl, take as an example a one line regexp in Perl, redo it in Java and compare... But, Java is a reasonably clean, simple and usable general purpose OO language. Nowadays it has excellent performance. Good support for web based stuff and rich clients as well. It has a huge install base which means that there is always work:)

    An excellent place to start is a friendly place for Java greenhorns!. A bit of a monastery for Java folks;) After you have some experience with standard Java you definitely have to check out JEE, the Java Enterprise Edition. You can use the glasfish Application Server to play with it.

    Cheers,

    Harry

Re: Perl "with" Java
by gwadej (Chaplain) on Nov 23, 2009 at 15:05 UTC

    To expand on the comments from BioLion and moritz, learning different kinds of programming languages expand the number of techniques you have at your disposal, if you actually learn the other languages.

    Different languages provide different tools, idioms, and approaches to solving problems. Even though you should be able to write any program in any language, some solutions are more natural in some languages. When you really learn a new language, and come back to Perl you will often find techniques that are available to you that may not have been obvious before. (Just learning to translate syntax is not enough.)

    I also think that the more different the languages you learn, the larger the benefit you gain. Java has a very different view of the world than Perl does. This different viewpoint can help your later programming by reducing the tendency to applying one solution to every problem.

    Probably the biggest benefit of learning multiple programming languages is increasing the approaches you can consider.

    G. Wade
Re: Perl "with" Java
by clp (Friar) on Nov 24, 2009 at 07:24 UTC
Re: Perl "with" Java
by 7stud (Deacon) on Nov 23, 2009 at 15:56 UTC

    Dear Monks,

    Excuse me for questioning some of your wisdom.

    Perl, for me, has the benefit of short development time, a great support community and a vast library of public code. Which makes it superb for getting things done.

    Java has all that too--except for the short development time.

    well, as opposed to Python / Ruby etc... which seem to also be very popular, but in my mind stand a bit in the middle ground and are neither as good at the swiss-army-chainsaw stuff as Perl

    On what basis do you make that claim? Personal experience? Studies comparing the two languages? Popularity?

    I think the best advise is Don't try to write Perl code in Java

    I think that is one of those statements that might sound insightful to some people, but in fact it's really hollow to the core. First of all, java doesn't let you write perl. Second, a programmer is the sum of their experience. They write code how they write it--within the confines of a given syntax and the libraries that are available. Third, if you learned the Decorator pattern in perl, it is still good programming practice to use the Decorator pattern in Java. As you learn a language, you naturally start assimilating the idioms employed by that language's community, so you don't have to try to do anything--except write lots of practice programs and ask questions on forums like these.

    Nay, I think the best advice is to write Java programs anyway you can. You'll get the hang of it, and I think your perl experience will help you immensely. Every language you learn will help you become a better programer. And every language you learn, will make learning the next language easier.

    I just have to warn you, though: Java's I/0 system is a complete nightmare, and in the past it was the biggest barrier to entry. Doing anything more than printing some output to the screen was nearly impossible for a beginner to figure out. In recent times, they've added some classes to make I/O easier for beginners, which makes learning java much easier than it used to be. Oh, and compiling and executing programs isn't easy either--unless you use an IDE that does all that for you. There are probably two people in the world that can compile their programs using the command line, and I've never seen any evidence that they post on the internet.

      Nay, I think the best advice is to write Java programs anyway you can. You'll get the hang of it, and I think your perl experience will help you immensely. Every language you learn will help you become a better programer.

      This is much like saying learning French will make you a better writer in German. It's only true if you are a decent writer already. It gives you more vocabulary and tools and the opportunity to think a bit more but sheer practice and experience don't necessarily make you better at anything. The opposite can be true. It can dig you deeper into bad habits and make you highly resistant--consciously or unconsciously--to knowledge outside the scope of those habits. Someone who writes terrible Java is likely, I'd say guaranteed, to write terrible Perl.

      I think the best advise is Don't try to write Perl code in Java

      I think that is one of those statements that might sound insightful to some people, but in fact it's really hollow to the core.

      I really have to disagree with this statement, for two reasons.

      First, it is quite possible to try to write code using inappropriate idioms from another language. Over the years I have maintained Fortran code written in C, Java written in Perl, C written in Perl, and even Fortran written in Forth. A particularly stubborn programmer can often force idioms from another language into a different language. It is usually especially painful for any poor soul who must maintain this code.

      The second issue is the frustration caused by trying to write Perl in Java. Learning a new language by trying to translate the syntax explicitly will often result in much frustration. So the advice to not write Perl in Java could be considered as a reminder that you should keep the target language's idioms and syntax in mind rather than trying to use Perl's idioms.

      G. Wade

      well, as opposed to Python / Ruby etc... which seem to also be very popular, but in my mind stand a bit in the middle ground and are neither as good at the swiss-army-chainsaw stuff as Perl

      On what basis do you make that claim? Personal experience? Studies comparing the two languages? Popularity?

      Bit of each, although Benchmarks game doesn't really back up what I am saying - so i guess it is mainly personal experience. The main point everyone seems to be making is that learning more languages, gaining experience and forming your own opinions and finding what works for you is the key lesson. This is the opinion i have formed (so far), that's all.

      Just a something something...
        I don't see what the execution speed measured on the benchmark website has to do with whether Python and Ruby occupy the middle ground. Except that that cleary shows that neither Python, Ruby or Perl are fast enough to be a substitute for C++ (or Java) in time critical code.

        My (nearly uninformed) guess is that Python and Ruby can't compete with Perl on the low level aka sysadmin stuff but have the same limitations as Perl in really big projects