in reply to What if Perl had an OO standard library?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: What if Perl had an OO standard library?
by awncorp (Acolyte) on Aug 24, 2022 at 03:51 UTC | |
by hippo (Archbishop) on Aug 24, 2022 at 08:30 UTC |