4 ms·
> Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function. - John Carmack This mirrors a discussion I'
by prossercj 8y ago
> Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function. - John Carmack
This mirrors a discussion I've had with my boss a number of times. Most of our products are written in C++, and we complain about how often developers (usually coming from Java) think that everything needs to be inside a class hierarchy. The procedural parts are still there for a reason: the CPU is procedural. A procedure or function is a closer mapping to what the CPU is actually going to do when the code runs.
On the other hand, I've never done serious work with a pure functional language like OCaml. I would welcome the chance, though I wonder if one finds the same kind of dogmatism as in the OOP world...("it must be a pure function!")
- naasking 8y ago> I would welcome the chance, though I wonder if one finds the same kind of dogmatism as in the OOP world...("it must be a pure function!") Nah, OCaml is a very practical functional language, that's why it features mutable state. You just have to opt-in, so it just encourages [im]mutability as a default, as it should. Edit: fixed typo!
- badpenny 8y agoDo you mean "encourages immutability as a default"?
- p4bl0 8y agoYes, that's what he meant ;). In OCaml references are always explicit (different syntax) and mutable field in records must be declared explicitly as mutable. However, OCaml does not bother you too much (as compared to Haskell for instance) when using side effects like printing.
- hajile 8y agoHaskell is dogmatic. Everything must be lazy. Everything must be immutable. Everything must be pure. Ocaml (and SML) aren't particularly dogmatic. They are both eager, so reasoning about performance is much easier. Most things are immutable by default, but you can make mutable data structures in both. Rather than insisting on pure functions, SML and Ocaml allow side effects in functions and have the `unit` type for functions without a return. The type system is actually strong (eg, no implicit casts) and null exceptions simply do not exist. Multi-threading is the big weakness. Ocaml has been promising support for at least a decade without mainline support. Likewise, most SML variants don't have support (though PolyML does along with a couple others).
- deleted 8y ago[deleted]
- elbear 8y agoThe first one, about everything having to be lazy, isn't true. You can define strict data types or functions. The other two are though.
- sudomakeup 8y agoYou can still have mutable references and impure functions in Haskell, but its not like "path of least resistance" of other languages. The IO type marks impure functions Also one can use STRef if they want to have a pure function that is internally implemented with mutable values - that is all the side effects are self contained. http://gamasutra.com/view/news/169296/Indepth_Functional_programming_in_C.php http://gamasutra.com/view/news/169296/Indepth_Functional_pro... "a function can still be pure even if it calls impure functions, as long as the side effects don't escape the outer function"
- pjmlp 8y agoIf you are in for a surprise with how plain functions interact with ADL, versus code inside classes.
- Bizarro 8y agoSince the 90s it's driven me crazy that people don't recognize the flexibility of having data and functions separate when needed.