7 ms·
I made a Phoenix webapp as a veteran Rails dev
- apeacox 9y agoA rails veteran that still heavily relies on ActiveRecord's callbacks sounds a bit weird to me...
- cageface 9y agoWhat would you use instead?
- apeacox 9y agoCommands (or Service Objects) are a better approach. Isolating business logic and actions let you keep the control of what's going on.
- Lockyy 9y agoDo you have any resources to expand on the issues with AR callbacks? I'm interested to read up on this.
- apeacox 9y agoIn short: you lose control of what is happening, especially when you expand/inherit other classes. These kind of problems arise after few months of development, when the codebase is grown enough and starts becoming even more difficult to change or extend. Try to check Trailblazer for a different approach.
- jmcgough 9y agoAR callbacks can also make it harder to write tests.
- Exuma 9y agoYeah... that immediately was a red flag for inexperience. Not to mention when hes "not sure" if things were cleaned up. How have you been programming for 10 years and don't know how to properly clean up records, whether its through the database, ORM, or manually in a transaction. It sounds like this guy has sucked on the rails teet for far too long, instead of challenging himself with other approaches and paradigms.
- jaequery 9y agoI'd like to see him try crystal next and how that compares
- hartator 9y agoCrystal? What was your experience?
- CrystalLangUser 9y agoI originally started as a ruby / rails dev and while I still do that, Crystal is phenomenal to work with. https://crystal-lang.org/ https://crystal-lang.org/ It's still a smaller community so frameworks and such are still being developed. Currently there's a Sinatra inspired library, Kemal: https://github.com/kemalcr/kemal https://github.com/kemalcr/kemal and then there's Kemalyst, which handles MVC and the like: https://github.com/kemalyst/kemalyst https://github.com/kemalyst/kemalyst
- dcwca 9y agoIs it merely coincidence that every time I hear about Phoenix it's from the Rails community? Is it popular with people who haven't come to it from Rails?
- tsukaisute 9y agoA never-Rails dev here using Elixir/Phoenix, easily the best choice I've made after hearing positive things here on HN. The Elixir community may be an amalgamation of Rails folks looking for better runtime performance and cool new tech, and Erlang folks looking for syntactic sugar and a growing developer community. (I'm neither.) Elixir's author was one of Rails core contributors, which probably also helps in bringing the Rails crowd over. One could think of Elixir as a "better" version of Rails rewritten on top of the Erlang stack, even if Rails and Elixir are apples and oranges under the hood. See also: the inverse of OP's article, the creator of Erlang trying out Elixir (2013) [1] [1] http://joearms.github.io/2013/05/31/a-week-with-elixir.html#head_1 http://joearms.github.io/2013/05/31/a-week-with-elixir.html#...
- bananaoomarang 9y agoPhoenix is heavily inspired by Rails, and I also think some of the core contributors are the same. No reason people unfamiliar with Rails can't use/learn it, but if they are previously familiar with Rails it can be easier.
- danpalmer 9y agoAs a Django dev, who has done bits of Rails, I felt it suffered from some of the same problems with Rails that cause me to prefer Django. I'd love to see what something inspired by the Django/Python community could be.
- preordained 9y agoWhat did he gain? Some performance? Did he need it, and was there no simpler way to get it? I get the premise, just trying things and having fun. But I get the impression that in a lot (most?) scenarios this would be a lateral move at best. His last comment about going with Phoenix instead of Rails for new projects, if he's not just being kind, that seems like a major case of throwing out the baby with the bath water. Goodbye 10 years of experience, knowledge of pitfalls, etc...hello 1 month of promise and years of gotchas and relearnings for small benefit?
- apeacox 9y agoI used my ~9 years experience in ruby/rails and invested 100% in elixiR/phoenix. I've found elixir way more simpler and elegant for my tasks, to the point that I start my new projects in phoenix (and ported some rails app to it too). I still respect and use ruby/rails, but it's not my first choice anymore.
- preordained 9y agoI 100% respect that. It sounds like you didn't jump to that conclusion in 1 Phoenix project over a month, though...and when you say "my tasks" the situation may have been that you weren't churning out "normal" CRUD apps that Rails is so good at? For sure its a lack of careful thinking and consideration of trade offs I'd take any issue with...it sounds like you didnt come to those conclusions out of emotion or a deep yearning for something new.
- apeacox 9y agoYes, I approached elixir/phoenix (well, my very first project on it was a sort of ecommerce library), btw it's true that I didn't choose in only one month. Moreover, I tried other languages/techs during the years (Go and NodeJS/Express, for example). And yes, sometimes my tasks go beyond the simple CRUD, but as of today, I'd choose Phoenix anyway because I find mysef more comfortable with it rather than with Rails. Even the fact that I can think to use a 512mb DigitalOcean droplet without fear is a plus, but not the main reason :-P
- hartator 9y agoI am currently learning Elixir. Weirdly the thing I am blocking the most is the functional aspect. I don't fully get why `List.get_elem list, 1` is superior to `list[1]`? (I know it seems a pretty obvious question, but I can't find satisfactory answers that make sense to me at least.)
- tsukaisute 9y agoBecause with more expressive constructs, you may find not having to write list[ix] very often. For example, a traditional "for" loop may be replaced more succinctly with an operation such as "Enum.map" or "Enum.filter" [1]. Data transformations made more obvious. Coming from imperative languages especially (speaking for myself), have to re-think/re-learn how you write code, but it does end up being a worthwhile investment [1] https://hexdocs.pm/elixir/Enum.html https://hexdocs.pm/elixir/Enum.html
- hartator 9y agoI want to beleive that, but I don't know. For example, in Elixir, you would write something like this to square a list: 'Enum.map [1,2,3], $($1 * $1)'. In Ruby: '[1,2,3].map {|e| e * e}'. The Ruby seems more natural to me, but maybe it's the years of OOP speaking and not reason.
- pryelluw 9y agoIve been studying functional languages for the most part of 2017 and the first example makes more sense to me.
- tsukaisute 9y agoBtw, there are a number of ways to write that expression depending on the complexity of the function Short syntax: Enum.map [1,2,3], &(&1 * &1) Long syntax: Enum.map [1,2,3], (fn num -> num * num end) Or even: square_me = &(&1 * &1) Enum.map [1,2,3], square_me square_me_too = fn(num) -> num * num end Enum.map [1,2,3], square_me_too Defining a function separately (e.g. even in another module) and referencing it: def square(num) do num * num end def doing_something() do ... Enum.map [1,2,3], &square/1 Enum.map [1,2,3], &SomeOtherModule.square/1 ... end
- wgjordan 9y ago> Just the fact that app can utilize all cpu cores without you doing anything special is pretty damn awesome. Rails apps can utilize all cpu cores without you doing anything special as well (Since Rails 5 its default web-server is Puma, which is multi-process and multi-threaded). I agree this fact is pretty damn awesome, but what (if any) are the significant differences between Phoenix and Rails in this respect?
- rlander 9y agoNo it can't. It's technically impossible for a Rails app to utilize all cpu cores because of the GIL. You're confusing two different things: the web server and the actual Ruby app. The rails app is still limited by the GIL and, therefore, runs within a single process.
- wgjordan 9y agoSo you're saying that when the OP talks about 'app can utilize all cpu cores', he's specifically referring to individual requests spawning multiple concurrent threads and therefore utilizing all CPU cores in isolation, as opposed to the web server utilizing all CPU cores across multiple concurrent requests by serving them on separate processes/threads? I would be interested if the former was the case (and would be interested in practical examples), but I highly doubt it.
- deleted 9y ago[deleted]
- rlander 9y agoYes, the former. He's saying that his Elixir app should scale linearly to N times faster on N cores processors (up to ~20 cores).
- wgjordan 9y agoRails can scale in this way too, by serving concurrent requests across multiple forked worker-processes (note that the GIL doesn't prevent multiple _processes_ from running Ruby code concurrently across multiple cores, only multiple threads in a single process). At first, it sounded like you were implying (by distinguishing between the web server and 'the actual Ruby app') that Phoenix automatically parallelizes portions of an _individual_ request across multiple threads/cores using some special asynchronous dataflow-paradigm primitives or something. It would be unique and truly awesome if that were true, but I still highly doubt it. I don't doubt that Phoenix probably delivers orders-of-magnitude better performance than Rails in many other respects, but 'utilizing all cpu cores without you doing anything special' is nothing unique to Phoenix over Rails as I understand it.
- mempko 9y agoWe are using Phoenix and elixir in a small service. Loving it so far. Super fast and organized nicely.