Live data from Hacker News

Ask HN: Where did you first come across functional programming?

news.ycombinator.com

11–18 of 18 posts

Re: Ask HN: Where did you first come across functional programming?

#11
OOP programmer lives inside the GoF design pattern and the result is AbstractSingletonFactoryBeanProxyAdapter class you love !

Nowdays, my programm is mostly the composition of some functions. Want inheritance and polymorphism ? Just use object composition and multi dispatch functions.

The way to go forward is abandon any of `class` keyword.

Protected, public, private is a lie and also a trap. It didn't prove anything.

Your encapsulation rule is inside your interfaces, not inside your class keyword.

Now you can say: But OOP served me well, i can get shit done fast !

Absolutely, any tools can serve you enough. The issue is, once you use the bad tools, you get into a rabbit hole to slow down everything else eventually.

Re: Ask HN: Where did you first come across functional programming?

#12

OOP programmer lives inside the GoF design pattern and the result is AbstractSingletonFactoryBeanProxyAdapter class you love ! Nowdays, my programm is mostly the composition of some functions. Want inheritance and polymorphism ? Just use object composition and multi dispatch functions. The way to go forward is abandon any of `class` keyword. Protected, public, private is a lie and also a trap. It didn't prove anythin…

> Your encapsulation rule is inside your interfaces, not inside your class keyword.

Could you please expand to this?

Re: Ask HN: Where did you first come across functional programming?

#14
I've came across Haskell in my computer science class at High school/Sixth Form. It's in the AQA Computer Science specification [1] and you are expected to know the basic concepts of functional programming as well as interpret code in the written exam.

[1] https://www.aqa.org.uk/subjects/computer-science-and-it/as-a...

Re: Ask HN: Where did you first come across functional programming?

#15
FP didn't really start to "click" until I found "Functional Core, Imperative Shell"[1] last year (2022). The HN comments from that thread were very helpful, too.

I didn't really grok FP until 2022, but I learned Scheme as early as 1999 for programming 101 (comp sci degree). We used the SICP textbook; looking back it seems SICP used an FP language to teach programming, but didn't explore some important FP concepts like Option/Either (a.k.a. Monads. Perhaps our class just didn't cover that part of the book?)

Between 1999 and 2022, I dabbled in FP because I heard good things about it. But I think many FP practitioners could improve their marketing/teaching skills. Most FP texts seem to dive into mathematical jargon (monads, functors, etc) without even explaining why knowing these would be useful.

So I'm writing a series of articles on FP. The first one is on why FP is worth learning: "More Performant, Testable Code with Functional Programming. (FP language optional!)"[2]

The next article will be a curated list of articles/videos that I feel explain FP better than most; the ones I wish I had found way back when starting to dabble in FP.

Also there's an argument many of FP's useful features have been copied by more imperative languages[3]. So people may be unwittingly doing FP even if they aren't using an FP language. For example, anonymous first class functions have been added to C++ and even Excel. JS has always had anonymous first class functions.

[1]: https://hw.leftium.com/#/item/18043058

[2]: https://blog.leftium.com/2023/04/more-performant-testable-co...

[3]: https://youtu.be/QyJZzq0v7Z4

Re: Ask HN: Where did you first come across functional programming?

#16
University (like a lot of CS students I'd assume). I always saw it as an academic thing and didn't give it much use until my compiler course. My professor for the course maintains a somewhat well known SML compiler and our course was writing a very formal functional programming language in SML. A lot of the power starting falling into place at that point. ADTs especially were eye opening.

I don't write in pure FP languages now, but I do use the concepts I learned all the time, especially as their fantastic concepts are leaking into other languages, like Rust.

I don't think pure FP languages will ever be real industry winners, but I think they're great experiment and research grounds for features that the broader community eventually adopts, which is such an important thing for improving the expressibility of our code.

Re: Ask HN: Where did you first come across functional programming?

#17
Haskell course at university. Had fun doing all the exercises in the curriculum, and couldn't stop. Explored on my own how to implement in Haskell the more advanced programming patterns that weren't covered in the course. Had fun with lazily evaluated infinite lists where you evaluate the second element of the lazy list that was passed as an argument, and at the end of the same lower order function you return the lazy list but with its head chopped off, to have the algorithm run in constant space.

I have come to regard lazily evaluated infinite lists as a must-have before you can call something a functional programming language.

In trying to build more complex systems, I noticed that you really have to know what you're doing with Haskell, otherwise you end up with leaks that are very difficult to trace back.

What really solidified FP for me was taking an elective category theory for computer scientists course.

Today I'm building stuff in Scala, which is the closest you can get to being able to pay the bills while doing principled FP.

Re: Ask HN: Where did you first come across functional programming?

#18
post #3

My first programming course was CS 61A at Berkeley, taught with the textbook Structure and Interpretation of Computer Programs. I had tinkered around a bit with other languages before that, but hadn't got seriously into programming until that time. I consider myself very fortunate not to have been previously indoctrinated into imperative / stateful programming.

What language do you work in now? If it is an imperative language do you avoid state as much as possible?

Mostly Python. I do try to avoid mutable state as much as possible, and generally keep things functional (in the sense of functions used for the return values, not their effects). When there is mutable state, keep it as local as possible (within functions or classes).
Post reply on HN