Skip to main content

All Questions

64 votes
10 answers
31k views

Why would a program use a closure?

After reading many posts explaining closures here I'm still missing a key concept: Why write a closure? What specific task would a programmer be performing that might be best served by a closure? ...
1 vote
3 answers
442 views

Scala Option vs. conditional branches

If I'm writing Scala functions and have to check for nulls in situations where I can't avoid it (say, working with Spark UDFs and some legacy Java types), is it better to turn things into Option or to ...
63 votes
4 answers
22k views

What are combinators and how are they applied to programming projects? (practical explanation)

What are combinators? I'm looking for: a practical explanation examples of how they are used examples of how combinators improve the quality/generality of code I'm not looking for: explanations of ...
4 votes
2 answers
1k views

How to organize a chain of functions that share parameters, functional programming

When trying to follow a functional programming paradigm, I often find myself in a situation where I have a chain of functions that I would want to combine/compose somehow, but they all also take in a ...
7 votes
1 answer
6k views

Is there a UML diagram for functional programming?

For modelling software implemented with the imperative or procedural programming paradigm we have Flowcharts, process diagrams, etc. For object oriented we have UML class diagrams, object diagrams, ...
9 votes
7 answers
4k 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 ...
12 votes
6 answers
2k views

Best Practice - Wrapping if around function call vs Adding early exit if guard in function

I know this can be very use-case specific, but I find myself wondering this far too often. Is there a generally preferred syntax. I'm not asking what is the best approach when in a function, I am ...
-1 votes
3 answers
175 views

How do you enforce rules for the members of a collection in a non-OOP way?

When everything seems to be a collection, how do you enforce rules for members of said collection without the use of an interface? As far as I am aware, in languages that don't fully support OOP ...
1 vote
3 answers
246 views

What is a good method/practice I can employ to keep identical code snippits in two places in sync? Also, help documenting functionals

If I could get some input on the design of this, I would be grateful as well. Note that I'm programming in python. There's a function F that takes lots of data, runs some analysis on it (taking ...
5 votes
3 answers
2k 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 ...
6 votes
3 answers
383 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 ...
54 votes
11 answers
12k views

"Easy to reason about" - what does that mean? [closed]

I have heard a lot of times when other developers use that phrase to "advertise" some patterns or developing best practices. Most of the time this phrase is used when you are talking about benefits of ...
12 votes
2 answers
1k views

Haskell ways to the 3n+1 problem

Here is a simple programming problem from SPOJ: http://www.spoj.com/problems/PROBTRES/. Basically, you are asked to output the biggest Collatz cycle for numbers between i and j. (Collatz cycle of a ...
2 votes
1 answer
639 views

Should all functions be fully self-contained (is it bad practice to share a variable between functions)?

There are two ways to do the same thing (pseudo code) Define databaseHandle in the parent function, and use it as a global in this scope: function API() { function openDatabase() { return ...
0 votes
2 answers
1k views

I cannot understand the application of oops How can I develop the understanding of application of oops? [closed]

I am a developer in PHP technology, I am aware of almost all the basics of OOPS, but still cannot find out the way to apply these concepts over a procedural programming. I do it in very orthodox way, ...

15 30 50 per page