Skip to main content

All Questions

0 votes
0 answers
32 views

API design for precomputation cache [closed]

In my numeric code library I have a function totient_sum that depends on an expensive one-time precomputation totsum_range = [...], then different calls to totient_sum(n) are quick. There are several ...
qwr's user avatar
  • 342
4 votes
5 answers
368 views

Anemic Models vs. Rich Models: When to Use?

I'm working on an application and have encountered two different approaches for organizing business logic. There's a general consensus that application rules should be handled in higher layers, so I ...
Azuos's user avatar
  • 49
2 votes
1 answer
288 views

Did the term "decorator" originate with OOP design patterns?

The Decorator pattern allows behaviour to be dynamically added to an existing object, effectively "decorating" it with new behaviour. While the pattern as formalised and named seems to have ...
Iain Galloway's user avatar
2 votes
1 answer
130 views

OO vs FP: What is a good approach to understanding if heavy wrapper classes should be used?

Consider a processing system which ingests objects from an external source and performs extensive processing. One example could be objects detected by a computer vision system which are then fed into ...
panlex's user avatar
  • 265
1 vote
3 answers
2k views

Are "Distributed Enums" an Anti-pattern in non-OOP like they seem to be considered in OOP?

I have recently read about the so-called "distributed enum anti-pattern." In particular, as it relates to using enums in conditional statements. (The idea is apparently that if you were to ...
user1713450's user avatar
-2 votes
1 answer
170 views

Which paradigm(between OOP and Functional) should be chosen for a given task?

Which paradigm(between OOP and Functional) should be chosen for a given task ? What are the tradeoffs between these two styles ? In which case using Functional makes sense and vice versa,in which case ...
Dennis's user avatar
  • 25
1 vote
2 answers
196 views

Should I add functionality by adding a new method to a class - or should I "register" the new functionality into a data structure?

I have one large class that computes ~50 different metrics (each metric has no side effects). My code is similar to this: class ReportingMetrics: def __init__(self, data:pd.DataFrame, config:dict)...
MYK's user avatar
  • 343
4 votes
2 answers
308 views

Should I use classes instead of functions with a state needed for computation?

I have implemented the cows and bulls game in C++. The code: #include <cstdio> #include <cstdlib> #include <ctime> struct DigitMatches { int matches_in_right_positions; int ...
sshd's user avatar
  • 51
79 votes
10 answers
17k views

How functional programming achieves "No runtime exceptions"

How does a functional programming language, such as Elm, achieve "No runtime exceptions"? Coming from an OOP background, runtime exceptions have been part of whatever framework that is based ...
Fireburn's user avatar
  • 889
5 votes
3 answers
707 views

How could a computer program do anything if everything is immutable?

I feel this is a bad question because I probably do not understand what I am talking about. In my effort to learn about functional programming, I became stumped on understanding the idea of immutable ...
Julian's user avatar
  • 77
-1 votes
1 answer
210 views

Refactoring: Pythonic way of reducing the subclasses?

background: so, I am working on an NLP problem. where I need to extract different types of features based on different types of context from text documents. and I currently have a setup where there is ...
ultron's user avatar
  • 109
1 vote
3 answers
253 views

Is it a good practice for functors to store outputs as instance attributes?

The question pretty much says all, but let's look into a simple example (I'm using C++, but the question is not strictly related to any particular language): So, let's say that we have a functor that ...
cyau's user avatar
  • 137
1 vote
4 answers
693 views

Can writing Object-Orientated Code in a Functional style improve performance?

Given a scenario where you have consecutive setters or a series of events where an object is modified, can it be more performant to instead write code in a way where a new state is returned rather ...
artman41's user avatar
  • 129
1 vote
4 answers
883 views

Design pattern for a function class

I have been experimenting with the idea of function classes as explained in this article and Composition applied to function dependencies as described in the following questions: https://stackoverflow....
user32882's user avatar
  • 267
38 votes
7 answers
9k views

Do you need to think about encapsulation if you can ensure immutability?

Encapsulation In object-oriented programming (OOP), encapsulation refers to the bundling of data with the methods that operate on that data, or the restricting of direct access to some of an ...
Christopher Trotter's user avatar

15 30 50 per page
1
2 3 4 5
7