Remix.run Logo
bhouston 3 hours ago

I used to struggle with abstractions back in my OOP days but since moving pretty much to a purely functional approach I find that code duplication is rare. Just have a function and call it in two parts. The main abstraction issue is then data structures but with TypeScript interfaces being duck typing essentially I run into few problems there as well.

So code duplication because of abstraction issues is rare. Code duplication because of siloed developers is so much more common.

ikety 3 hours ago | parent | next [-]

For hobby, I use functional languages, and I find the techniques are the important bits to remember. Most modern languages let you easily stand on functional programming theory. You don't need to know Haskell. Everyone's brain works differently, but the idea of small, simple and occasionally flexible parts building a whole works for me. As opposed to the large complex do it all shape shifting machine.

kccqzy 2 hours ago | parent | prev | next [-]

Developers do not really have to be siloed to experience code duplication. When the team size grows past a certain point such that each person is not aware of what every one else is working on, code duplication is quite inevitable. This is the case even if everyone writes functional style code. In fact this just happened last month at work: I wrote a new functional and pure helper function and placed it at the beginning of the file; a week later a colleague told me a similar helper function with substantially the same functionality with a different signature had been written and placed near the end of the same file.

platz 3 hours ago | parent | prev [-]

what exactly is 'calling a function in two parts'

Akronymus 12 minutes ago | parent | next [-]

I assume to split the overall behaviour (loop through all elements, transform some value, etc) and the specific one (apply this function to all elements, transform it in this way, etc) into multiple functions and combine those to achieve the actual intended behaviour.

At least that's my interpretation

tosh 9 minutes ago | parent | prev | next [-]

apparently it is not what the author meant but:

using projection you can "call a function in two parts"

  add: {x+y}
  add4: add[4] / gives {4+x} by fixing 4 as first argument to {x+y}
  add4[2]      / gives 6
this is a useful pattern that you can use to first 'fix' data or behaviour to produce another function

https://en.wikipedia.org/wiki/Partial_application

saghm 3 hours ago | parent | prev | next [-]

I assume they mean to call the function from two (or more) parts of the code (i.e locations). It's not immediately apparent why this is meaningfully different than what would be possible in Java though, since ostensibly a function is the same as a method by just moving the callee to the list of parameters. (There are some things in a Java method that you can do that don't translate to most functional languages, like invoking the version of the method from a superclass, but there's nothing forcing you to do any of those from the language perspective, so it seems a bit strange to claim that the language itself is the issue rather than maybe the specific patterns that were chosen, maybe by their coworkers or just not common in the ecosystem).

bhouston 2 hours ago | parent [-]

You can do functional in any language. I haven’t designed a new class in years in TypeScript and I’ve been more productive as a result.

lysium 3 hours ago | parent | prev | next [-]

I read it as „calling it from two places“

bhouston 2 hours ago | parent | prev | next [-]

Calling a function from two locations is what I meant.

Basically since moving to a functional approach in typescript I find I do not fight abstractions as I used to when I used classes and inheritance.

odo1242 3 hours ago | parent | prev [-]

I believe they’re referring to callbacks / dependency injection / higher order functions to customize the behavior of a function?

bhouston 2 hours ago | parent [-]

Mostly just function calling to reduce duplicate code. Dependency injection does start to get abstraction costs again. I use it when necessary but it is annoying and costly when I do.