TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: OOP in Functional Programming Language

3 pointsby mollerhojover 3 years ago
I find that my ruby code more and more resembles functional programming:<p>Instance variables are always set in the constructor, and almost never mutated.<p>The thing I like about OOP is really just that the methods of an object don&#x27;t have to take a bunch of parameters, but that it instead can rely on the instance variables. I guess in functional programming, this would be something like having a (constructor) function that returns a hash of methods that have been given what in OOP would be instance variables as their first parameters, and then only need non-instance variables through currying. My question is, is there a functional programming language that not only supports, but `encourages` this OOP style programming?

5 comments

PaulHouleover 3 years ago
Back in the day (finishing up my PhD thesis in 1998) I would write C code with functions like<p><pre><code> some_method(Object* this, ...) </code></pre> that was effectively &quot;object based&quot; even if there was no support for inheritance. Ultimately this style reifies data structures as objects and provides a systematic approach to many problems such as how you allocate memory. The one area where I feel it falls short is that there ought to be some way of switching from struct-of-arrays to arrays-of-struct representations.<p>This is not too different from how many real object-oriented systems are implemented.<p>There is a quite a bit of overlap between &quot;using functional programming techniques to implement an object-oriented style&quot; and &quot;using object-oriented techniques to implement a functional programming style.&quot;<p>There&#x27;s nothing more annoying in the lower teachings of programming that circulate than the &quot;FUNCT10NS RULE, 0BJECTS DR001&quot; sentiment you see so much of.
评论 #29996696 未加载
schwartzworldover 3 years ago
JS doesn&#x27;t have true classes, but I use the class keyword often to do what you&#x27;re describing: creating immutable OOP style models that i can pass around as function arguments.
nagasadhuover 3 years ago
F#. It&#x27;s functional first. Supports currying, HoF, maybe types, composition, pipelining and most of the functional goodies. It offers a neat indented syntax for OOPs.<p>You can also do function calls with optional arguments with defaults.
dave4420over 3 years ago
Case classes in Scala? (Although traditional imperative classes are also available, so maybe this doesn’t count as encouraging your desired style.)
评论 #29996684 未加载
srivathsaharishover 3 years ago
pony is the word