What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

When to use interfaces, and when to use higher order functions?came up in the review queue for reopening, under the pretense that it had been closed as primarily opinion based.

Edit: Based on some confusion that came to light in the comments, please note that this appeared as an audit in the reopen queue. The question was not actually closed. To me the question seemed on the borderline of being primarily opinion based. While I probably wouldn't have cast a close vote had I come across it, my vote to “leave closed” was based on the idea that “well, it's borderline, and if five people have already been convinced that it's opinion-based, I'll let that decision stand.”

The end of the question is:

Obviously the interface implementation has much less code, but it doesn't really feel like functional code anymore. If I start using interfaces throughout my web app, when do I know when to use higher order functions instead? - else I'll just end up with a plain old OOP solution.

So in short: When should interfaces be used, and when to use higher order functions? - some line has to be drawn, or it will all be types and interfaces, whereof the beauty of FP disappears.

The question text suggests that the question is about where a line should be drawn, based on how things feel, which seems primarily opinion based. A comment on the question links to a blog posting containing someone's thoughts on the matter, which suggests that it's opinion based. The accepted answer contains text that suggests it's largely an opinion as well:

I think using an interface is a good idea if you have more than 2 functions that are often passed to some other function together - this way, you avoid having too many parameters.

F# is a multi-paradigm language that combines functional and OO style, so I think using classes in this way is perfectly fine. (You can still benefit from the functional style when defining data types to represent the domain etc.)

One thing to keep in mind is that functional programming is all about composition. This might not be as useful in this case, but I always prefer writing code that I can compose to add more functionality rather than code that requires me to provide something when I want to use it.

I think your approach using a class that takes ICacheProvider is perfectly fine

This seems like a question that very well could have been closed as being primarily opinion based. It's not a bad question at all, and might seem at home on programmers.se or codereview.se, but what about it isn't too opinion based for SO? According to the closing reasons:

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.

I suppose this might be classified under “specific expertise,” but since the both the question and the accepted answer admit that the problem can be solved in either way, it seems like it would largely be a matter of taste. I could see this being answered along the lines of “this is where this coding conventions guide says to draw the line,” or “book X usually does it here, while book Y does it here,“ so that specific expertise or references might be pulled in.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

This particular question is not opinion based. It may be too conceptual for this particular site, as you rightfully remarked, but a true opinion based question would be off topic on a site like Programmers as well.

The author is using a very polite language, but if the answer is read in entirety, there is not even that much of such polite language in comparison to the technical content. To "objectivize" the answer, you could just replace each "I think that X" by just "X". Which, if written by Tomas Petricek about F#, amounts to about the same thing.

The best proof of the question not being opinion based is that it is a very clear and attractive question and yet it has attracted exactly one answer over several days.

share|improve this answer
    
That's an interesting point about it being a clear and attractive question, yet getting only one answer. I'm not active in the F# area, and wasn't aware of Tomas Petricek's authority in it, so those didn't trigger any flags (and because in the review queue, only the question is shown, not the answers). I think, though, that those aspects might be more important for the closing queue, but this wasn't a review for whether to close the question as opinion based, but about whether to reopen in, assuming that it had already been closed as opinion based. I wouldn't have voted to close, but… –  Joshua Taylor Sep 3 '13 at 19:52
    
…would probably be willing (well, was willing, actually) to leave it closed, given that five SO users had already judged it opinion based. –  Joshua Taylor Sep 3 '13 at 19:52
1  
@JoshuaTaylor - I think I understand the context. I am looking at the question as well and not disagreeing with a close or migration. I was just arguing against a particular close reason. I just wonder if the review queue takes the close reason into account... Anyway, 5 people voted for a close, then 5 people for reopen, then 2 to close again. So it's time to think about other available actions as well, such as migration. –  Jirka Hanika Sep 3 '13 at 20:08
    
Just to be clear, the question wasn't actually closed; it was a review audit, so it was presented as though it were closed and was being considered for reopening. –  Joshua Taylor Sep 3 '13 at 20:21
    
@JoshuaTaylor - Ah, I missed that, thank you. I think that Undo is probably right about why the algorithm selected it (upvotes and no close votes; code and all) and that now that it has a close vote, it is just no longer eligible for the reopen queue. No way to do anything about it; there are tons of non-controversially great questions in the system, so why to care about this one being ineligible now. –  Jirka Hanika Sep 3 '13 at 20:49
    
"I think using an interface is a good idea if you have more than 2 functions that are often passed to some other function together - this way, you avoid having too many parameters." Why 2 and not 3? What does often mean? This smells very opinion-y. –  JDB Sep 3 '13 at 21:28
    
@Cyborgx37 - Correct. But it's quite non-opiniony, in my opinion, that for "exactly 1 function" of this kind, the interface would be no more than a redundant wrapper, while with several such functions and any potential for adding more to the club, adding a well named interface is essential for readability and maintainability. The opiniony add-on is the thresholds for number and frequency of use together, and whether to teach them as vague or quantified. Now, there's not the smallest hint of calling for even such minimal "opinioniness" in the formulation of the question. –  Jirka Hanika Sep 4 '13 at 7:09

It's a bad review item - they are selected by the system based on what the system thinks are good things for the post to have. However, posts like these sometimes get through (computers don't have a good reading comprehension score).

When this happens, swallow the failure (complain here if you want), and go cast a close vote on the post. This ensures it won't ever be used as a reopen question again.

share|improve this answer
    
To be fair, I don't think the question is bad; just that it seems a bit too close to "opinion based" to use as a review audit for opinion based closing. If it had been for, say, not demonstrating a minimal understanding, it would be fine (since it clearly demonstrates a minimal understanding). I wouldn't want to cast a close vote for it, because it is a valuable question; is there a way to make sure it's not used as a reopen question just for "opinion based"? –  Joshua Taylor Sep 3 '13 at 19:46

I do not think this question is opinion based, which happens to be my honest opinion. Let me explain what lead me to that belief.

First off, my opinion is biased. F# is a newer environment and I believe it should have a little leniency as a result of that. For example, it has 1% the coverage that C# has on SO. This person is just trying to get a theoretical grasp of functional versus OOP.

Secondly, although poorly worded, this question is really about the aforementioned theory. It should probably be titled "Will too many interfaces make functional programming into object oriented programming?" To which the answer may be more appropriate.

The answer contains this line, "The benefit of using interfaces is that you give the type a name (you would get that with records too) and you are more clearly expressing your intention (other components can implement the interface).", which to me answers the theoretical question posed.

I would argue that because of the large amount of content and context in both the question and answer, there is more fact than opinion here. I will also agree that opinion does exist in the post, but will take the stance that opinion is not in the majority.

share|improve this answer
1  
+1 I think you make a good point that the amount of opinion appropriate in a question or answer depends, to some extent, on the newness of the field. In a very new, developing technology, there simply won't be as many references to cite, yet at the same time, some of the important players in the area may be answering the questions. –  Joshua Taylor Sep 4 '13 at 2:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .