Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8504601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:04:51+00:00 2026-06-11T02:04:51+00:00

Summary What are the pros and cons of splitting pure functions into passive objects

  • 0

Summary

What are the pros and cons of splitting pure functions into passive objects that describe the algorithms and active objects that can execute those algorithms? Note that the situation is greatly simplified by the fact that the functions have no side effects.

Detail

The portion of the code I’m writing (in Python 3) will largely adhere to functional programming.

There is some (immutable) data. There are some algorithms. And I need to apply those algorithms to the data, and get the result.

The algorithms could be represented as regular functions, which will be transformed using standard operations (e.g., I may compose two functions, then freeze some parameters using functools.partial, then passed the resulting function to another function as an argument). Many of the lower-level functions would be memoized for performance reasons.

But an idea occurred to me that perhaps I should instead represent algorithms as passive objects. Such objects wouldn’t be able to execute anything themselves. When I’m ready to execute, I’ll feed the algorithm object and all the inputs it expects into a special “computation” object. This would match my mental model of an algorithms far better, but I’m concerned that I might be missing some problems with this approach.

Algorithm objects could be implemented in a variety of ways; perhaps even multiple implementations could be allowed. Let’s say my algorithms are instances of an abstract class Algorithm; then its subclasses could represent:

  • strings of text in a domain-specific language that I’ll create
  • some kind of execution trees that I’ll construct
  • even regular Python functions

I have never done this before, so I wanted to get some feedback on this idea. Does it offer any real design advantages, apart from my subjective feeling that it’s more “natural”? Does it lead to any problems?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:04:53+00:00Added an answer on June 11, 2026 at 2:04 am

    I don’t think the design offers any major advantage or disadvantage.

    Assuming that any computation object can run any Algorithm, then your class Algorithm presumably is going to have a function called something like execute that knows how to run the algorithm. Name that function __call__, and now your Algorithm class is exactly like a Python callable object (including functions).

    For your strings of DSL code: under your design you’d represent them as a subclass of Algorithm that overrides execute to run an interpreter. Under the other design you’d just do something like:

    def createDSLAlgorithm(code):
        def coderunner(*args, **kwargs):
            DSLInterpreter().interpret(code, *args, **kwargs)
        return coderunner
    

    And similar to create a function that when called will execute a specified expression tree.

    Of course I might be missing something that you’re planning to put into your Algorithm design that’s not possible for functions. Not all Python functions have mutable attributes, for example. But since user-defined functions can be closures, can have attributes, and any object can “behave like a function” just by implementing __call__, I suspect it’s different names for the same thing.

    Choosing your own names, of course, is a small advantage if it aids code readability. And it might feel a bit more natural to attach attributes to “objects” than it does to attach them to “functions”, if your computation objects are going to interrogate certain known attributes of Algorithms in order to help decide what to do when computing them (for example whether or not to memoize).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like this thread to be some kind of summary of pros/cons for overriding
Summary: I have passed the name of the id select tag into an Array.
SUMMARY How can I make my GUI application run on windows startup on a
Summary I'm repurposing Apple's Page Control project. In loadScrollViewWithPage:, the view controllers that I'm
Summary: I've run into an interesting problem, and I'm not quite sure how to
Summary When I execute a very simple program using Perl's Benchmark utility. I get
In Oracle, what are the pros and cons of using materialized views, and of
Summary: I have a bunch of C functions I have to call from C#.
Summary: Can I program a thick client game in C without reinventing wheels ,
Can I get some constructive feedback about the following architecture? Simplified Architecture Summary: Return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.