Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Perl and C# - how I use both

by jdrago_999 (Hermit)
on Mar 09, 2009 at 18:35 UTC ( #749382=perlmeditation: print w/ replies, xml ) Need Help??

Monks,

I am not ashamed to tell you that I use both Perl and .Net (specifically, C#).

"But how to know which one to use, and when?"

My rule of thumb is: When on Windows, use .Net. When on Linux, use Perl

"But why not use Perl on Windows?"

I do use Perl on Windows, but only in a pinch. You see, C# is to Windows as Perl is to Linux. I run Ubuntu Linux as my desktop and do most of my software development on CentOS using Apache/MySQL/Perl. Perl just fits in so nicely with what I do on a daily basis it's difficult to imagine getting by without it.

However when the $client makes Windows a requirement, C# is my tool of choice. With new gadgetry like LINQ to SQL I get an Object-Relational Mapper (ORM) along the lines of DBIx::Class or Class::DBI, plus a hackneyed equivalent of sort/map/grep. IIS 7 feels to me like what Apache httpd will one day become. ASP.Net MasterPages + ASP.Net MVC + ASP.Net generic handlers feel very much like the environment provided by Apache2::ASP.

Aside from the fact that it is Windows and I have to put up with Windows' problems, shortcomings and arbitrary limits, it's better than it was before recent advances in C# and .Net.

"Isn't C# hard to learn?"

I feel that C# and Perl are very similar. Perl6 will include some ideas that C# already has implemented, so it could actually help by learning some C#. Specifically, the regular experessions in C# have named placeholders - something Perl6 Rules will have as well. C# also provides partial classes, first-class Delegates (analogous to Perl5 subroutine references) and lambda expressions (though not nearly as nice as Perl6 will offer).

After years of Perl-only or Perl-centric coding, C# offered a great way for me to get used to strict typing and true object-oriented design. This discipline improved my software architecture skills in general, and the way I design Perl software in particular. The result is that my Perl is much easier to write useful unit tests for, and is better suited to scale out.

"What about Moose?"

Moose is another option, but without compile-time type checking or runtime casting. Moose is a solution to another kind of problem - a good one at that.

"So what's your point?"

My point is that "Fivers" who could use a head-start on true OO could benefit from taking a good look at C# (use Mono if you like).

Comment on Perl and C# - how I use both
Re: Perl and C# - how I use both
by Tanktalus (Canon) on Mar 09, 2009 at 19:17 UTC

    My rule of thumb is a bit different: when on Windows, upgrade to Linux.</tongue-in-cheek>

    Ok, not really. (Well, not entirely anyway...) My rule of thumb is to use perl anyway, just because then portability is an easier goal. And it should (generally) be a goal, even if it's not required yet. Exceptions obviously apply (e.g., if the program is only supposed to interact with very OS-specific situations, though those should be fairly rare, I'd hope). Why learn multiple toolkits when you can learn a good multi-purpose toolkit deeper? My big project at $work where I basically started with Perl works on Windows, Linux, AIX, Sun, and, as of fairly recently, Mac OS X (with almost no changes) (heck, for the most part, I can run the application on Linux and tell it to pretend I'm on Sun or Windows, and it still works properly). I find I can be more productive by keeping focused on good all-purpose, cross-platform languages than delving into monoculture (no pun intended) languages.

Re: Perl and C# - how I use both
by Jenda (Abbot) on Mar 10, 2009 at 02:07 UTC

    Delegates, also known as dumbed down closures with stupid syntax.

    BTW, did they finally do something about the silly

    AwfullyLongClassName x = new AwfullyLongClassName();
    all over the place? I mean, yeah, sure, at times I may want to have a variable of type A containing from the very beginning a value of type B (subclass of A), but how often? There's no reason to repeat the name of the class if its the same and there never was.

    These two and quite a few more made me dislike C# back when I had to use it. Way too talkative, way too repetitive, way too low-level, way too restrict(ive|ed).

      var x = new AwfullyLongClassName();

      These two and quite a few more made me dislike C# back when I had to use it. Way too talkative, way too repetitive, way too low-level, way too restrict(ive|ed).

      It's still pretty much like that. I've been working with C# for about 9 months now (not my choice, but the job pays the bills) and C# is still frustrating me to no end. I expected it to be less frustrating as i got to learn the language, but it doesn't; I still find myself longing for the flexibility and expressiveness that perl offers.

      Yes - I agree with everything you just said.

      However, compared with the old preferred way of coding on Windows - COM (via Visual Basic or VBScript) - or worse yet, the win32api, C# and the .NET framework is much easier and more predictable.

      Also my experience of being forced to program anything on Windows has always had a single common root: *Somebody* on the team threw a hissy fit until Windows was chosen, and only because they refused to learn how to actually program. Ironically they ended up just copying and pasting code I would write for them anyways. I suppose it was better than if I had to use code that they had written ;)

        Windows has always had a single common root

        I always thought it was a single common C:\.

        And you didn't even know bears could type.

      Delegates are type-safe function pointers and they are so useful, because you can exchange them between threads, which is used heavily inside the asynchronous programming model.
      You can create an instance of delegate with a closure.
Re: Perl and C# - how I use both
by scorpio17 (Monsignor) on Mar 10, 2009 at 13:12 UTC
    But isn't C# just Micro$oft's attempt at reinventing Java? Why not just use Java? At least it's cross-platform.
      Why not just use Java?
      ...because I don't want my application to suck up 2Gb RAM just to sit there and do nothing?
        Is C# really better in this respect?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://749382]
Approved by toolic
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2014-08-27 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (237 votes), past polls