It is refreshing to witness renown programmers program and deal with code live. It helps to hear the actual stream of consciousness and actual stream of thought. It lets me know that I am not that far off with most of my thought processes. It also lets me know the areas I need to improve upon.
Awesome videos, I've been enjoying these tremendously and seeing the concepts in use in a production application solidifies things. The only caveat I would add is that we're not talking about Ruby language globals "$blah", but globals that exist per-request in a thread-safe way in Rails with the new feature or using a library like request_store.
This reminded me of a situation I've experienced a few times as a code reviewer. A newer developer will take some story to add user_id to the logs or to some model update. The solution they come up with will often be to add a global somewhere or thread the request object down, and the inevitable response will be "this is a layer violation, you can't do this.". At the same time, I often don't have a great response for how to solve the problem in a better way. I notice that I'm applying a rule, but not helping us to a solution. It occurs to me that when using sharp knives like globals, you often have to do more than prove that they're most convenient. You have to prove that you are capable and thoughtful enough to wield a sharp knife, and that's the capacity we don't often attribute to the less experienced. I think that this episode was a great explanation of the thoughtfulness around using Current.
Thats awesome, now i have some sort of POC in the form of video to convince my CTO about refactoring our mess :) . I think its about time that we learn/implement these philosophies into our software as well. I always wanted to learn the best practices for app development using Rails but i could not find this once place where they talk about best practices for controller for model for concerns. this video has literally everything. Thank you so much for starting this series.
Thank you David for sharing the ideas expressed in Basecamp. It's too bad that the name "The Rails Way" has already been taken for a book, because I think if one was allowed to dig through all of Basecamp's source code and write a book based on the ideas and philosophies therein, it'd make for an excellent book about how to develop with Rails, as intended. That's not to diminish these videos in anyway - just an additional thought.
Thanks for sharing. So all these puzzle pieces rely on global state attributes (per request) coming from the before_action defined in SetCurrentRequestDetails. So one could say that these Current attributes are like instance methods that are available on all layers and not only to the controller scope. Did you ever run into conflicts where you were not sure if a global is not set correctly or maybe race conditions when globals being mutated as a side effect somewhere else, etc.?
David, can you explain the proliferation of libraries like interactor, active_interaction, and so on? I see a lot of developers demonizing the use of callbacks and concerns. And suggesting the implementation of business logic in service objects or command pattern. What do you think about it? Are these patterns used on BC at all? Btw, looking at this source code it doesn't seem you're fighting against all these Rails conventions at all. Thanks for sharing it!
Since Rails became mainstream, people who use it are no longer just people who want to, but also people who have to because their employer switched to it and such. They aren't coming because Rails philosophy attracts them, rather they carry their own patterns. Interactor is one of those patterns.
I'd like to know more about what a recording is. It seems like many different kinds of things can be linked to a single recording? is a single recording just one request?
The Rails implementation of the Current feature that will be shipping has a way of setting the variables for the duration of a block. The idea is then when a job runs, it would wrap any execution in a block using "Current.set(person: a_user) do; your_code() end". Code running in the block will be able to use Current without any changes.That way the same code can run in Rails during a request and in a Sidekiq job on another machine. I think it's a pretty elegant solution. edgeapi.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html#method-i-set
I think the best way to deal with this is to just pass current person id to the job as a parameter and then set Current.person using before_hooks in delayed_job/sidekiq.
It is refreshing to witness renown programmers program and deal with code live. It helps to hear the actual stream of consciousness and actual stream of thought. It lets me know that I am not that far off with most of my thought processes. It also lets me know the areas I need to improve upon.
Awesome videos, I've been enjoying these tremendously and seeing the concepts in use in a production application solidifies things. The only caveat I would add is that we're not talking about Ruby language globals "$blah", but globals that exist per-request in a thread-safe way in Rails with the new feature or using a library like request_store.
This reminded me of a situation I've experienced a few times as a code reviewer. A newer developer will take some story to add user_id to the logs or to some model update. The solution they come up with will often be to add a global somewhere or thread the request object down, and the inevitable response will be "this is a layer violation, you can't do this.". At the same time, I often don't have a great response for how to solve the problem in a better way. I notice that I'm applying a rule, but not helping us to a solution.
It occurs to me that when using sharp knives like globals, you often have to do more than prove that they're most convenient. You have to prove that you are capable and thoughtful enough to wield a sharp knife, and that's the capacity we don't often attribute to the less experienced. I think that this episode was a great explanation of the thoughtfulness around using Current.
Thats awesome, now i have some sort of POC in the form of video to convince my CTO about refactoring our mess :) . I think its about time that we learn/implement these philosophies into our software as well. I always wanted to learn the best practices for app development using Rails but i could not find this once place where they talk about best practices for controller for model for concerns. this video has literally everything. Thank you so much for starting this series.
Thank you David for sharing the ideas expressed in Basecamp. It's too bad that the name "The Rails Way" has already been taken for a book, because I think if one was allowed to dig through all of Basecamp's source code and write a book based on the ideas and philosophies therein, it'd make for an excellent book about how to develop with Rails, as intended. That's not to diminish these videos in anyway - just an additional thought.
David, thank you for this series! Please continue if you can. Cheers!
Thanks for sharing. So all these puzzle pieces rely on global state attributes (per request) coming from the before_action defined in SetCurrentRequestDetails. So one could say that these Current attributes are like instance methods that are available on all layers and not only to the controller scope. Did you ever run into conflicts where you were not sure if a global is not set correctly or maybe race conditions when globals being mutated as a side effect somewhere else, etc.?
Great videos, please keep uploading.
David, can you explain the proliferation of libraries like interactor, active_interaction, and so on? I see a lot of developers demonizing the use of callbacks and concerns. And suggesting the implementation of business logic in service objects or command pattern. What do you think about it? Are these patterns used on BC at all? Btw, looking at this source code it doesn't seem you're fighting against all these Rails conventions at all. Thanks for sharing it!
Since Rails became mainstream, people who use it are no longer just people who want to, but also people who have to because their employer switched to it and such. They aren't coming because Rails philosophy attracts them, rather they carry their own patterns. Interactor is one of those patterns.
David thanks for sharing your ideas on globals.
(BTW: are you recording this video from Alcatraz? Why don't you get yourself a nice zoom background?)
Beautiful. It is also possible in reactjs with context
I'd like to know more about what a recording is. It seems like many different kinds of things can be linked to a single recording? is a single recording just one request?
Aren't you going to lose the Global variable in a multithreaded process?
Thanks heaps for these , hope they keep coming :)
what headphones you got there?
What are your thoughts on extracting work into jobs when code may rely on thread-local per-request variables?
The Rails implementation of the Current feature that will be shipping has a way of setting the variables for the duration of a block. The idea is then when a job runs, it would wrap any execution in a block using "Current.set(person: a_user) do; your_code() end". Code running in the block will be able to use Current without any changes.That way the same code can run in Rails during a request and in a Sidekiq job on another machine. I think it's a pretty elegant solution. edgeapi.rubyonrails.org/classes/ActiveSupport/CurrentAttributes.html#method-i-set
I think the best way to deal with this is to just pass current person id to the job as a parameter and then set Current.person using before_hooks in delayed_job/sidekiq.
Very nice!!!
Thanks :)