AlexMcConnell
Contexts - a barrier too high for newbies?
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done. Is that work a poorly designed mess? Yes, yes it is. And so what? That’s just the nature of the beast at the moment. It doesn’t reflect on Rails, it’s just the current state of software development. The demand for developers is such that someone fresh out of a code school with no college can be making six figures within a year or two, even outside of Silicon Valley. Their work is going to be a poorly designed mess no matter how you slice it.
But even if it’s a mess, companies would rather have apps that are poorly designed, buggy, and going to be difficult to expand later than no apps at all. It’s a nice idea to encourage people to build better apps, but it’s horribly impractical to expect it in the current ecosystem. We live in a world where developers with 4 years of experience and a poor understanding of design patterns are considered ‘senior,’ and that’s not changing in the next 5 years.
In another thread, Chris McCord said, “we are asking folks to isolate functionality behind modules and functions.” And I say, no, you’re asking folks to understand the concepts and importance of isolating functionality before being allowed to build a Phoenix app. You’re making it so that someone who doesn’t have a solid foundation in design patterns is going to run into a brick wall of confusion before they can even make a Hello World app. Anyone who understands and appreciates the values of these concepts is going to implement them without needing to be steered into it. All you’re really accomplishing is to doom Phoenix to being a niche framework. Maybe that’s what the community wants. If it is, I can only hope that someone builds another framework in elixir that I can use.
I’ve seen a lot of people saying, “Phoenix is not your application.” Well, stop it! Who are you to tell someone what their application is or isn’t. If they don’t understand the concept, repeating a catch phrase over and over isn’t going to fix the problem, it’s just going to encourage them to move on to something else with a community where people are being helpful rather than condescending.
Most Liked
josevalim
So between learning programming, databases, html, css, and javascript, where developers will really have trouble and struggle is in organizing functions into modules? I recommend folks to stop making contexts more than they are. Why are design patterns even being brought into the discussion?
If you tell me PHP is easier to get started because I can just print something in the page, I will definitely agree with you. But saying contexts is what is going to block users from progressing with Phoenix has no basis in reality.
It reminds me when Rails 1.2 came with REST and everyone started screaming that it would be the downfall of Rails because oh-the-complexity. Once the details were ironed out, everyone just moved forward happily.
Kham
Dude, it’s just files being in different directories. People will get it.
sasajuric
About a year ago, my team started working on a Phoenix app. We all had experience with Erlang, building web servers, and software development in general. None of us had experience with Phoenix, though, so we followed patterns encouraged by the official docs, generators, and other independent blogs. We started with Phoenix 1.1, so there were no context, and there were still models. We moved quickly, and produced a lot of code in the next few months. Unfortunately, that lead us to a quite interleaved code with unclear boundaries and responsibilities. It became increasingly harder to maintain and extend such code. Some six months after we started, we agreed to clean up our controllers, and move other concerns to “service” modules (which I feel resemble the official contexts being introduced with 1.3). To this date, our code is still not completely there.
My takeaways from this experience are:
- Framework plays an important role in determining the code organization. Even as experienced devs, we simply stuck to defaults promoted by Phoenix at the time.
- It’s much harder to refactor the code post-fact. Having worked on some terrible legacy (and sadly produced some of my own), I strongly feel that your only chance of keeping the control of your code is to pay attention to it from the very start.
- Keeping the Phoenix part of the code (controllers, sockets) focused only on HTTP related tasks, basically making it just the interface to the rest of the system is a very good way to structure any production app.
Therefore, there’s no doubt for me that contexts are a very good idea which will push developers in good direction, promoting better code organization patterns. I agree that this will make things slightly more confusing for newcomers, because it’ another idea they have to grasp. However, I think that this is a good trade-off. A bit of approachability is sacrificed to get much better code organization.
I’m somewhat worried about this mantra myself. I have a feeling that for some people it means “Phoenix is not your OTP application”, and that we should always organize our system as umbrella apps. I definitely don’t share that view. For me, the core idea here is that Phoenix is an http/ws interface to your system. You take the input, validate it, and then invoke some other part of your system (i.e. some function from some module in some other namespace), and finally convert the result of that function into desired output (html, json, …). That’s a clear separation of responsibilities, and can lead to much more readable code. And a readable code is a win for everyone, especially for newcomers.
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








