6 ms·
Well, what I don't understand is the SW engineering propensity towards cargo culting and doing things the harder way than mathematicians do. I see it with OOP,
by js8 17d ago
Well, what I don't understand is the SW engineering propensity towards cargo culting and doing things the harder way than mathematicians do.
I see it with OOP, XML, design patterns, and other things, now with LLMs. (LLMs - you really want to build complex systems in badly specified natural language, compiled or interpreted with an inscrutable algorithm and possibly indeterministic?)
Is it the excitement from a new analogy? Or are engineers naturally empiricists, while the rationalism/empiricism distinction doesn't work in computer science?
I think we would be better off if we just learned functional programming and few abstract concepts (categories, monads). Simpler than OOP.
- mickeyp 17d agoBut functional programming and OOP are intrinsically the same, but expressed using different primitives. The thing that empowers first-class functions and closures (lexical binding) is the exact same method by which encapsulation works, even if the latter opts for heap vs stack. The fundamentals are the same. Here's a simple one in Emacs Lisp: (defmacro send (object method &rest args) "Sends a METHOD to an OBJECT with ARGS." `(funcall ,object ',method ,@args)) (defun make-animal (name) ;; 'hunger' is entirely private (encapsulated) (let ((hunger 5)) ;; here's our lambda using lexical binding (lambda (method &rest args) (cond ((eq method 'get-name) name) ((eq method 'feed) (setq hunger (max 0 (1- hunger))) "Yum!") (t (error "Animal does not understand: %s" method)))))) (let ((good-boy (make-animal "Rex"))) ;; "call" (via our macro) the "get-name" method; then feed. hunger does down 1. (send good-boy get-name) (send good-boy feed) ;; pretty-print the "object" good-boy (pp good-boy)) ;; this is the state of it after the two calls. #[(method &rest args) ((cond ((eq method 'get-name) name) ((eq method 'feed) (setq hunger (max 0 (1- hunger))) "Yum!") (t (error "Animal does not understand: %s" method)))) ((hunger . 4) (name . "Rex"))]
- js8 17d agoYes, you can express everything using lambda calculus. Kinda.. so why not use a thing that already exists? Why invent a new language (encapsulation) when previous (binding) suffices?
- ivan_gammel 17d agoOOP is not about doing things harder, it‘s about doing them efficiently. The key elements of software engineering are abstraction and encapsulation: we, humans, cannot load the entire domain into our memory and reason about it at all levels of detail at once. We need to zoom in and zoom out, decompose problems into smaller pieces, then reassemble, treating those pieces at surface value. OOP isn‘t rocket science, it just adds one more piece — the hierarchy of concepts with inheritance and polymorphism. And it‘s just a technique: most programs are written in a mix of styles anyway. The foundational style is procedural, because that‘s how computers work. FP and OOP just build on top of it and translate to it.