Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [functional-programming]

Functional programming is a paradigm which attempts to solve computational problems by the chained evaluation of functions whose output is determined by their inputs rather than the programme state. In this style of programming, side effects and mutable data are deprecated and usually strictly isolated.

-1
votes
2answers
103 views

Are executable requirements the most advanced form of declarative code?

The more declarative code is, the less explicit technical details it contains and the closer it gets to requirements expressed in domain language. In the extreme case, there is no more difference ...
4
votes
2answers
178 views

Should I define more methods to update necessary UI only, or less methods but update some UI unnecessarily?

For example, suppose my input data and UI is not in 1 to 1 relationship: html: <script> aChanged=function(){ }; bChanged=function(){ }; cChanged=function(){ }; </script> a:<input id=...
2
votes
2answers
269 views

How does understanding category theory help a software engineer?

This question is related but doesn't directly answer my question. I can imagine that understanding category theory helps someone who is designing a programming language, apparently in particular ...
1
vote
1answer
35 views

best practice for data.table use in “formal” code

Consider a "large-ish" data set (~2-5M rows) that goes through multiple stages of cleaning/processing: library(dplyr) largedat %>% mutate( # overwrite v1 based on others v1 = somefunc(...
0
votes
4answers
104 views

Is there a mismatch between XSL and OOP? [closed]

context and background: I prefer OOP for the most part and find it, largely, more intuitive -- this is my bias. When I read that functional language x is better than OOP language y I think to myself:...
7
votes
2answers
371 views

A real-life example of using curry function? [closed]

I was struggled to find a real-life example of using curry function and get the benefit of using curry. When I google curry function I often see the example like let add = x => y => x + y; ...
1
vote
1answer
156 views

Functional programming — changing correlating elements during list mapping

Consider I have a list. I want to iterate over it and map it's elements -- but the mapping might also require to change others than the element I'm currently iterating over. Let's say I have a switch ...
6
votes
2answers
285 views

Encapsulating moving parts in OO vs Minimizing moving parts in FP

I am from OO background just started learning FP paradigm. Came across quote by Michael Feathers - "OO makes code understandable by encapsulating moving parts. FP makes code understandable by ...
2
votes
5answers
365 views

Software design pattern for class method that only should be called once

Say I have a TypeScript class: export class TypeCreator { entities: Set<Whatever> registerEntities(e: Set<Whatever>): Set<Whatever>{ return this.entities = e; } } if ...
-1
votes
1answer
74 views

Why are ReactiveX Operators considered functional?

I'm struggling to understand how a ReactiveX operator can be considered functional. Operators are implemented as functions, but but with the exception of simple operators like map and reduce many of ...
1
vote
1answer
260 views

C++ immutable struct

I would like to be able to implement immutable data in C++. In short, given a C++ object in which I would like to modify a member variable, instead of modifying that member in place I would like to ...
9
votes
3answers
517 views

Why usage of assignment operator or loops discouraged in functional programming?

If my function meets below two requirements, I believe function Sum to return the summation of items in a list where item evaluates to true for given condition qualifies to be referred as pure ...
0
votes
1answer
124 views

What's the benefit of separating specialised data from behaviour in an algorithm?

Functional programming strongly suggests to separate data from behaviours (functions). However, I can't see the benefit of this for an algorithm's implementation intrinsically tied with particular ...
4
votes
2answers
277 views

Function that returns non parameter functions

I found a function in c# like this: private Dictionary<string, Func<string>> ObtenerExtraCfgCampo(MsgDefCamp camp) { var extra = new Dictionary<string, Func<string>&...
3
votes
1answer
92 views

REPL-based Workflow and Unit Testing

As a developer who has primarily been doing functional programming in F# for the last several years, I'm very attached to my REPL and use it run my code as I go, testing and refining each function as ...
1
vote
4answers
255 views

In Haskell, is it a “violation” of functional programming to interact with something that was not a function parameter?

I'm sure this must have been asked before, but I can't find anywhere that actually answers my question, so apologies if I have simply overlooked this. I am currently learning Haskell, and loving the ...
0
votes
1answer
110 views

In what other locations besides infinite streams and infinite lists is memoized lazyness useful?

Haskell is one of the few non-strict languages out there. In his paper Why Functional Programming Matters, John Hughes uses (memoized) lazy evaluation (as well as higher-order functions) to implement ...
3
votes
3answers
433 views

In functional programming, what it means “Order of evaluation does not matter” when function is pure?

In context of pure functions in FP, apart from several benefits mentioned like easy to reason about, testability it also says "order of evaluation does not matter" since output remains same for given ...
1
vote
1answer
285 views

How do functional programming advocates use a framework like React or Angular?

I read this blog post recently: The Two Pillars of JavaScript Part 1: How to Escape the 7th Circle of Hell, which is essentially a criticism of object oriented programming, and advocacy for funtional ...
1
vote
3answers
146 views

Is it allowed to throw a runtime exception from a java.util.Predicate

The java.util.Predicate interface contains the test(...) method, whose JavaDoc description states that it [evaluates] this predicate on the given argument and that it [returns] true if the input ...
0
votes
1answer
94 views

What is the correct granularity for events in the context of designing a rule-based decision system?

Introduction We need to design a system that, given a set of events that are happening in the source application, reacts to them and if some conditions have been met, actions can be triggered. Users ...
0
votes
0answers
27 views

Should I use “Map” or “Select” for new functor-like operators in C#?

I'm designing a type in C# that will be used as an algebraic type in a functional style, but is not a collection type and does not implement IEnumerable. If this type is a Functor, should I name its ...
2
votes
1answer
278 views

Naming conventions for pure functions

Are there 'conventions' / best practices on naming pure functions? For example: adding numbers: add or sum? calculating the square root: calcSqrt or sqrt? reversing a list: reverse or reversed? ...
1
vote
2answers
115 views

How can an iterative algorithm be controlled dynamically?

Suppose we need an iterative algorithm for mathematical optimisation. Each iteration takes a long and random time. After each iteration, a stopping condition is checked for the iterate x, based on ...
0
votes
1answer
122 views

Is the usage of flip function a smell for bad design?

Everything is in the title, is the usage of flip function a smell for bad design ? I'm coming from a JavaScript universe and used to work with lodash/fp or ramda. Recently, I've written some stuff ...
1
vote
2answers
418 views

Patterns for tracking state in recursive Haskell code

A frequent pattern in my Haskell code is element-wise recursion for transformation of a list with some carried state generated using the data in the list. Usually, this looks something like this: ...
3
votes
1answer
291 views

Are design principles of functional programming languages and current hardware (register-machines) contrary?

Functional languages seek to minimize accidental state (computationally-convenient but logically unnecessary data dependencies) by endorsing the most granularly modular, mathematically unambiguous ...
0
votes
1answer
121 views

for-loops vs x.Times(…) extension methods

Using C# as an example, extensions on IEnumerable to allow code like collection.Each(i => i.DoStuff) rather than a foreach loop are generally frowned upon, mainly because they don't follow LINQ ...
3
votes
2answers
364 views

In which programming paradigm can't code reuse be (easily) achieved?

In a video about software architecture that I'm watching, it's stated that the main program/subroutine architectural style promotes modularity and function reuse Code reuse is one of the main ...
3
votes
2answers
316 views

What is control abstraction in the context of functional programming?

I understand concept data abstraction as it is relevant to OO programming. However on contrary it seems Function Programming promotes or makes use of concept control abstraction. I tried searching ...
5
votes
4answers
393 views

Optimal Immutable Data Structure for Highly Dynamic Particle System

Trying to see if immutability is a good fit for highly dynamic objects like game entities (that constantly are moving around and changing) or particle systems, each which might have thousands or ...
9
votes
6answers
3k views

what can go wrong in context of functional programming if my object is mutable?

I can see the benefits of mutable vs immutable objects like immutable objects take away lot of hard to troubleshoot issues in multi threaded programming due to shared and writeable state. On the ...
8
votes
2answers
1k views

Do functional programming languages disallow side effects?

According to wikipedia, Functional programing languages, that are Declarative, they disallow side effects. Declarative programming in general, attempts to minimize or eliminate side effects. Also, ...
1
vote
0answers
120 views

Understanding transducers, why this is not a transducer

I'm currently learning functional programming and trying to learn a new concept : transducers. I'm actually getting the point of theory, like it's an advanced map/reduce that aims to provide better ...
4
votes
2answers
431 views

This functional programming example and what it means

I've been reading Out of the Tar Pit by Ben Moseley and Peter Marks and in section 5.2.3 they discuss state in functional languages compared to procedural languages. The procedural example is as ...
7
votes
3answers
2k views

Sample code to explain Banana Monkey Jungle problem by Joe Armstrong [closed]

In the book Coders at work Joe Armstrong stated that: I think the lack of reusability comes in object oriented languages, not in functional languages. Because the problem with object oriented ...
3
votes
2answers
629 views

Microservices with OOP and Functional Programming [closed]

After reading and using different concepts(right or wrong) questions related to modularity have appeared. I want to implement the microservice architecture in my projects the right way. As from ...
2
votes
1answer
60 views

Rendering and holding state changes in a web app with functional programming

Let's say you have a tic-tac-toe app. There's the game state which can be represented by an array of size 9. There's your "reducer" computes new state from old state and player actions. Then there's ...
8
votes
3answers
739 views

Sum Types vs Polymorphism

This past year I took the leap and learned a functional programming language (F#) and one of the more interesting things that I've found is how it affects the way I design OO software. The two things ...
1
vote
2answers
119 views

Comparing approaches of mapping data objects

Update: I added some diagrams to help understanding I had a discussion with a colleague about two different approaches in mapping data objects. I'd like to get your opinion on pros and cons between ...
0
votes
3answers
867 views

DDD: Event handlers and aggregates in functional programming

When implementing a DDD driven system (based on event sourcing) using a functional programming language (Clojure), should one separate event handler functions from aggregate functions? In my naive ...
2
votes
2answers
207 views

Functional programming: does using a generic make a function impure?

public static Func<string, Task<T>> MyMethod<T>( UserCredentials credentials, Func<string, string, string, Task<T>> func ) => async (value) ...
7
votes
2answers
902 views

Functional Programming best practices

I don't have a particular coding problem on hand this is just an excercise to improve my thought process. Few months back I started learning about functional programming( mostly in R) and I fell in ...
2
votes
1answer
106 views

Dynamic *dll substitution?

I got an architectural problem here. Let say there is an IShell. It mainly responsible to map user's commands (represented as a linux-like strings) to an appropriate IExecutable's. Those ...
45
votes
9answers
12k views

Return considered harmful? Can code be functional without it?

OK, so the title is a little clickbaity but seriously I've been on a tell, don't ask kick for a while. I like how it encourages methods to be used as messages in true object-oriented fashion. But this ...
4
votes
1answer
141 views

Is using Option#get really a bad idea here?

I'm working on a Scala project and Wartremover shows an error about Option#get usage in my code: Option#get is disabled - use Option#fold instead While I do understand how get should often be ...
3
votes
1answer
164 views

Dependencies between functions-only modules: hardcoding vs alternatives

In switching from a procedural background to "FP in the small, OO in the large" I'm grappling with the following problem. Suppose there're modules, each only containing numerical math functions ...
5
votes
3answers
260 views

Can referential transparency be assumed when dealing with floating-point arithmetic?

A pure function is assumed to produce the same outputs given the same inputs. Suppose an (otherwise) side-effects free function computes with floating-point numbers. Due to numerical error, these ...
4
votes
1answer
375 views

Should function composition and piping be tested?

Unit testing requires writing tests first then code, on the other hand in F# (and most of the functional languages) some codes are extremely short as follows: let f = getNames >> Observable....
4
votes
4answers
311 views

Why are functional-style chained map operations considered hard to read?

In the comments to an answer of another question, I proposed the following Java code as a better way of writing a more procedural-style variant of the same operation: employeeService.getEmployee() ...