Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> If you mean behaviours, structs, protocols, modules and maps, then I can kinda see that, although Clojure has most of these too. But if you mean actors? Well

I kind of implied all of that, but I was specifically referring to the concept of modules and all its feature-sets, which together, in my opinion, does lead to a more OO like style of programming, especially structs, processes, behaviors and use, those things I feel are really similar to classes and inheritance. And there's also the dotted syntax for both map and struct access.

While yes, it's different than your common OO, in practice, you end up using these things similarly.

In Pheonix, simply put, almost all extension points relies on the __using__ macro, __MODULE__ compile time macro and use keyword. So it ends up very similar to an OOP framework, you basically extend classes, but you do so by using `use` instead of using `extend`, and a macro that copies over code and dynamically set the module name, instead of having an inherited lookup table.

How it's achieved is very different, but as a user of Pheonix, the ergonomics end up very similar.

Look at this:

    defmodule TodoWeb.ItemsController do
      use TodoWeb, :controller
    
      alias Todo.Items
    
      def index(conn, _params) do
        items = Items.list_items()
        render(conn, "index.html", items: items)
      end
    end
Yes, this isn't exactly a class, but like:

    package TodoWeb;
    
    import Todo.Items;
    
    class ItemsController extends TodoWebController
    
      public index(conn, params) {
        var items = Items.listItems();
        this.render(conn, "index.html", items);
      }
    }
How similar is the user experience?

And TodoWebController similary uses Phoenix.Controller, etc. It gives you a very similar feel to an inheritance tree, and pluging-in behavior in the framework by class extension.

Namespaces in Clojure really don't have this feel to them at all, now maybe you could shenaningan something similar with some similar macro convention over namespaces in Clojure, but it definitely isn't encouraged by the language or community the way it is in Elixir.

So in general, I feel modules in Elixir have a much closer feel to them to classes/objects in OO languages, and you end up using them similarly, where-as that's not the case for Clojure namespaces.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: