AlexMcConnell

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.

First Post!

DanCouper

DanCouper

I dunno, we’re busy refactoring a massive .Net application into modular contexts, and it’s 10x easier for new developers because instead of having to understand the entire application all at once, they only have to understand a small part, and can use basic C# knowledge rather than extremely domain-specific knowledge because each part is just a standard module rather than being tied into every other part of the app. Contexts gives you that.

Most Liked

josevalim

josevalim

Creator of Elixir

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.

48
Post #5
Kham

Kham

Dude, it’s just files being in different directories. People will get it.

28
Post #3
sasajuric

sasajuric

Author of Elixir In Action

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:

  1. 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.
  2. 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.
  3. 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.

Last Post!

josevalim

josevalim

Creator of Elixir

As mentioned in my first reply to this thread, I want to reiterate that I have seen all of this happening with REST and Rails 1.2. It is understandable the lack of materials about contexts, it is a new feature still on RC and we need to get feedback before we get to final. Once everything stabilizes, it will be smooth sailing.

The fact a lot of people are trying Phoenix’s release candidates is a great problem to have. But it means we also need to be more careful/responsible when those RCs come out and make sure we have at least some docs and material ready upfront.

Where Next?

Popular in Discussions Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
tmbb
This is a post to discuss the new Phoenix LiveView functionality. From Chris’s talk, it appears that they generate all HTML on the serve...
342 18634 126
New
opsb
We’re considering our architecture from a viewpoint of scaling our traffic heavily over the next 6 months. Our current deployment is runn...
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New
paulanthonywilson
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things. But I don’t think this is ...
New
matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement