Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Procedural vs OOP modules

by Bod (Parson)
on Oct 29, 2021 at 20:18 UTC ( [id://11138241]=note: print w/replies, xml ) Need Help??


in reply to Re: Procedural vs OOP modules
in thread Procedural vs OOP modules

great to see you thinking about this important topic so early in your programming career!

Haha! Thanks eyepopslikeamosquito

I suppose the second part of the original question was the more significant part for me...is there ever a case in the current day to write a module that isn't OOP. The discussion has certainly answered that there is.

To keep writing style consistent across our company, we use a style guide which, among other things, sets a minimum Flesch Kincaid Grade Score. We mostly use Hemingway to check our copy. However, we have internal editors for blogs, emails, etc. so I thought it would be helpful to have a real time Grade Score on these. To that end, I found an existing Javascript Flesch Kincaid module. I wanted Javascript to avoid lots of AJAX calls.

To my surprise, I found that the Grade Score from this was vastly different from Hemingway for the same piece of text. I was surprised because Flesch Kincaid is a well-defined mathematical formula. After some investigation, it seems the difference comes from the difficulties in programatically counting syllables.

So I thought I'd write my own module to obtain a Grade Score. I know there are Text::Info and Lingua::EN::Fathom. The latter I am using to create a copy checker that also includes a ratio of first person to second person pronouns. Both these modules count syllables using Lingua::EN::Syllable which the author notes is not entirely accurate although this is not especially important for my application.

Far more important to me is consistency. I need a Perl module and a Javascript module that function the same way and obtain the same result for a given block of text...any block of text over a dozen or so words. Hence looking at writing my own. That way I can create the syllable counting regexp in Javascript and Perl in a way that should produce consistent results in both languages.

My instincts tell me that this is best not done using an OOP module. But I couldn't explain why. Now, given the helpful and informative discussing, I understand some of why my instincts were right. I guess my judgement was also clouded by having only written OOP modules recently. I also think that the choice was mostly right for those too.

Replies are listed 'Best First'.
Re^3: Procedural vs OOP modules
by eyepopslikeamosquito (Archbishop) on Oct 30, 2021 at 07:11 UTC

    > Is there ever a case in the current day to write a module that isn't OOP. The discussion has certainly answered that there is.

    Yes! Not everything has to be OO. That's why I enjoy Perl and C++; their designers appreciated that OO is not necessarily the best solution to all problems.

    As an aside, I was once hired as a Java programmer but its emphasis on OO felt oppressive and I quit soon after (as mentioned here). Though I managed to hold down a C job without resigning, I didn't enjoy its primitive abstractions (for example, compare this rosetta C function with the other languages!) nor its flawed standard library, such as strtok, singled out for a dishonourable mention at On Interfaces and APIs. I suppose that's the main reason I gravitated towards C++ and (later) Perl. (BTW, Stroustrup describes here why he designed C++ as a multiparadigm programming language).

    > I know there are Text::Info and Lingua::EN::Fathom. The latter I am using to create a copy checker that also includes a ratio of first person to second person pronouns. Both these modules count syllables using Lingua::EN::Syllable.

    Rather than starting from scratch, you might like to model your new module on your favourite from these three (they all seem to have decent authors):

    • Lingua::EN::Syllable by Neil Bowers. I see Neil (aka neilb) is from Marlow UK, a short scenic drive from your (more working class?) Coventry UK. Neil is a prolific CPAN author ... and a PAUSE Admin, PSC member, and White Camel award recipient!
    • Lingua::EN::Fathom by Kim Ryan. I've actually met Kim - he's an excellent programmer, a gentleman (and a gentle man) ... and the founder of Sydney.pm.
    • Text::Info by Tore Aursand. I'd never heard of Tore before, but I see he's published nine CPAN distributions. Though the name suggests Scandinavia, I trust you're willing to forgive and forget the Norman Conquests. ;-)

      Not everything has to be OO. That's why I enjoy Perl and C++; their designers appreciated that OO is not necessarily the best solution to all problems.

      Yes! The more I reflect on this, the more I realise the folly of the question.
      However, asking a question that perhaps didn't need asking has elicited lots of insightful information and opinions. A useful bi-product 😊

      Rather than starting from scratch, you might like to model your new module on your favourite from these three

      I wasn't so much thinking of starting entirely from scratch as the methodology of calculating the Grade Score will be the same. I was thinking of just changing the regexp and copying the rest of the module. But I shall reach out to the other authors.

      Rather than starting from scratch...

      Looking at the source for Lingua::EN::Syllable I might not have to anyway... There doesn't seem to be much in there which cannot be replicated in Javascript. So it should be relatively easy for me to write a Javascript module that gives results consistent with Lingua::EN::Fathom which I already use.

      Marlow UK, a short scenic drive from your (more working class?) Coventry UK

      Considering we reside on opposite sides of this planet, you seem to have an impressive knowledge of my locality. Far more than I do of yours! Although, you seem to have an impressive knowledge of quite a lot of subjects...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-16 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found