New answers tagged

2

Let's tackle your confusion. You say subtraction is not associative: a - (b - c) != (a - b) - c Subtraction maps a pair of numbers to a single number, so the type does not match end-to-end! This is not function composition as described in the question! Let's consider three functions where they do match and so can be composed: f(a,b) = (a - b, b) g(a,b) =...


2

finding functions that are not associative You got it wrong. It's not about associativity of functions, but about associativity of function composition. And function composition is always associative.... .... as long as the functions can be composed (otherwise, there's nothing to speak about). The relevant part is their objects match end-to-end So take ...


3

You have already accepted and answer and this is a bit of a side-note but I have never been really happy with the streams API in Java. The design is very OO-centric and (ironically) somewhat procedural which can lead to very ugly (and unreadable) code IMO. It's unfortunate since the features around function references that were introduced at the same time ...


11

least LOC isn't really what I'm looking for here But, why? Least LOC is what you should be looking for here. While lines-of-code does not make for a truly reliable maintainability measure, you will be hard pressed to disagree that it takes you more time to read 20 lines over 5 lines. Programming is not only about writing. It is also about reading. Let me ...


2

As a general note, it would be incorrect to say that the "functional" code (or the code using Java streams) is always better than the "imperative" code (or the code using Java loops). In some cases it is much better, but in some cases it can make the code less readable. For a detailed analysis, see Item 45 (Use streams judiciously) in the third edition of ...


1

Most high-level programming languages provide for functions, because they facilitate functional decomposition, promote well structured code, and encourage reusing code thus avoid to repeat the same fragments over and over again. But this is not sufficient for making a functional programming language. FP requires at least that functions can be arguments to ...


1

Hey there stranger Welcome. I have been struggling to understand programming paradigms. So have I. Since the 80's. OOP is a language... No, like you said, it's a paradigm. Java is a language. ...with sole aim of modeling complex (real-world) systems Or simple systems. Like "Hello world" and "Hey there stranger". is OOP the only programming ...


7

OOP is a language with sole aim of modeling complex (real-world) systems No, sorry, no. OOP is very good at modeling reality. However, that is not its sole purpose, in fact, we often model very abstract things with OOP. All those example of “Animal” and stuff you see in OOP courses… probably only make sense in an academic context and in video games (And ...


1

Let's say you had some code like: if (done) {return result} // more calculation if (done) {return result} // some more calculation if (done) {return result} You have a fair amount of repetition here. Maybe you want to factor it out. If if and return statements were referentially transparent and composable, you could write it like: checkDone = if (done) {...


1

There's aready a nice compact answer above. However, since you ask several related questions about FP, I propose some more explanations, if deemed useful. Functional programming handles everything as either a declaration or an expression. In this paradigm, functions are the main mean of abstraction: they are combined in expression (composition), can ...


2

Composability means that components can be combined, and the combination can be used in place of its parts. Expressions are composable in the sense they can be combined with other expressions to form new expressions. And a more complex expression can be used anywhere a simple expression can be used. More importantly for your question, any expression or ...


1

Well, you are speaking in terms of a domain, referring to objects, and writing an application. You are already talking OOP, in a sense. Think about the following: Databases are concrete implementations and not abstractions. You have to specify everything. Even choosing among database storage types is a hard choice that you have to live with (well... to an ...


1

Being that these models describe a real world, physical action, it has some intinsic constraints. For instance, a driver is a human (as if 2019). A human can only drive for so long (both legally and physically). Even when the robots take our truck driving jobs a vehicle can only run for so long without refueling or breaking down. The vehicle can only carry ...


1

This question is very broad and there is no one-size-fits-all solution. I nevertheless go through the topics to help you to better narrow down the problem. Let's first have a look at the data model: Your data model is about two different entities, Routes and Services, with a one-to-many relation between them. I also understand that a Service is "owned"...


Top 50 recent answers are included