4 ms·
As someone who is more familiar with OOP, I would love to see examples/hear more alternative approaches to organising code. Let's say that you want to design a
by insertion 12y ago
As someone who is more familiar with OOP, I would love to see examples/hear more alternative approaches to organising code.
Let's say that you want to design a CRUD app, but you're not going to use OOP. What are some of the ways you could choose to structure your code? Would you still use a pattern like MVC?
- yogthos 12y agoYou can take a look at how apps are structured in Clojure with the [Luminus](http://www.luminusweb.net/docs http://www.luminusweb.net/docs) microframework as an example.
- chriswarbo 12y agoMy main issue with OOP is that classes/objects conflate a whole bunch of notions, and end up not being very good at any of them. Modularity and design-by-contract are better implemented by module systems ( http://en.wikipedia.org/wiki/Standard_ML#Module_system http://en.wikipedia.org/wiki/Standard_ML#Module_system ) Encapsulation is better served by lexical scope ( http://en.wikipedia.org/wiki/Scope_(computer_science)#Lexical_scoping http://en.wikipedia.org/wiki/Scope_(computer_science)#Lexica... ) Data is better modelled by algebraic datatypes ( http://en.wikipedia.org/wiki/Algebraic_data_type http://en.wikipedia.org/wiki/Algebraic_data_type ) Type-checking is better performed structurally ( http://en.wikipedia.org/wiki/Structural_type_system http://en.wikipedia.org/wiki/Structural_type_system ) Polymorphism is better handled by first-class functions ( http://en.wikipedia.org/wiki/First-class_function http://en.wikipedia.org/wiki/First-class_function ) and parametricity ( http://en.wikipedia.org/wiki/Parametric_polymorphism http://en.wikipedia.org/wiki/Parametric_polymorphism ) As for an alternative to "CRUD app using MVC", I'd probably recommend Functional Reactive Programming ( http://en.wikipedia.org/wiki/Functional_reactive_programming http://en.wikipedia.org/wiki/Functional_reactive_programming ). MVC is a way to architect interactive simulations and games, developed in the live environment provided by SmallTalk. However, I imagine your intention was for something closer to the server-side code of a form wizard on a Web page, rather than a game. In which case, I'd avoid MVC-style approaches completely, since they're inappropriate. It's much more straightforward to model servers as UNIX pipelines turning HTTP requests into HTTP responses ( http://en.wikipedia.org/wiki/Pipeline_(Unix) http://en.wikipedia.org/wiki/Pipeline_(Unix) ) Pipelines turn out to be a great fit for functional programming: lots of small, single-purpose pieces, composed together into a server which requests flow into and responses flow out.