(Standards)

Programming in Perl is choices all the way down. [...] object-orientation in Perl is difficult because the concept and mechanisms were bolted onto the language as an afterthought, and because it's optional, so one has to oscillate between this paradigm and others, i.e. some things are objects, most things are not [...]

I don't mind that at all. In fact, being able to choose how I want to implement $stuff is a strength of Perl, not a weakness. Forcing everything to be OO is a waste of time, because some things can be done easier and/or better without OO.

This?

my @stuff=getSomeList(); for my $thing (sort @stuff) { say "$thing"; # quoted to force stringifcation }

Or this?

say "$_" for sort getSomeList(); # quoted to force stringifcation

Or this?

SomeGlobal::StdLib::Class->getFactoryInstance()->getSomeList()->sort() +->forEach(SomeOtherGlobal::StdLib::Class->getInstance()->createStdout +WriterFunction());

Yes, all are made up. I don't like the last one. It is everything but readable, and it is everything but obvious. The second one is ok if it does not get longer.

How much the last one sucks can be seen by looking at LINQ. Microsoft invented a whole new syntax for C#, somewhat similar to SQL, so that coders no longer have to write that ugly chained method calls. Yes, it's mostly syntactic sugar plus Lambda expressions plus yet another standard library plus a way to inject methods into other classes. The result is that you can write this:

// Copied from Wikipedia var results = from c in SomeCollection where c.SomeProperty < 10 select new {c.SomeProperty, c.OtherProperty}; foreach (var result in results) { Console.WriteLine(result); }

Instead of this:

// Copied from Wikipedia var results = SomeCollection .Where(c => c.SomeProperty < 10) .Select(c => new {c.SomeProperty, c.OtherProperty}); results.ForEach(x => {Console.WriteLine(x.ToString());})

... which is what happens behind the scenes, as far as I understand C#. But the point here is: You don't see those OO chains, you see a much more convienent syntax that hides the ugly OO stuff.

And this is how it could be written in perl, completely without OO:

my @results=map { [ $_->{'SomeProperty'}, $_->{'OtherProperty'} ] } grep { $_->{'SomeProperty'} < 10 } @SomeCollection; say join(' ',@$_) for @results;

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re: What if Perl had an OO standard library? by afoken
in thread What if Perl had an OO standard library? by awncorp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.