I've been coding for over 20 years now! (WOAH, do I feel old)
I've touched just about every resource imaginable under the Sun (too bad they were bought out by Oracle)
Now, one reason NOT to use SOLID. It looks good from the outside 99% of the time. But take another look at your example code. You've now introduced a race condition in your code between checking if an email address is already used, and then saving the new user data.
As someone that has done enterprise software engineering for ~15 years, these are now the sorts of things I look out for and have to engineer against. So when you see some more funky code, take a step back and ask "why is it done this way with this level of complexity?" - because more often then not, there are real world problems that need to be solved that cannot entirely be met with these ideals in mind.
I don’t see a new race condition. The simple fact some code has been segregated to functions doesn’t introduce something new. That code won’t run in parallel by merely calling the methods in sequence so that one thing could get executed out of order and without waiting.
I've been coding for over 20 years now! (WOAH, do I feel old)
I've touched just about every resource imaginable under the Sun (too bad they were bought out by Oracle)
It isn't because of separating them out into individual functions. It is that there could be multiple invocations at once, for instance two users attempting to register at the same time with competing information. And its because of situations like this why some code is written in a more complex way to handle these situations.
I guess if it is put in a step-wise class; where the order is obeyed. There shouldn't be a problem. We give this user flow exclusive access to these functions. Layout like this in the article would give headache if used inappropriately.
Yeah, but that’s not because the code gets split in functions. The exact same thing applies to the original code.
That’s a whole different discussion beyond the point of illustrating a concept.
I appreciate your suggestion. I have a question and correct me if I am wrong, Does the Race Condition or Data Race also occur in single thread programs/code?
I've been coding for over 20 years now! (WOAH, do I feel old)
I've touched just about every resource imaginable under the Sun (too bad they were bought out by Oracle)
If there is truly only one invocation possible at a time, then yes, that is fine. But that simply isn't scalable. If we're looking at a web application or API for instance, multiple users would be using the site at the same time.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Now, one reason NOT to use SOLID. It looks good from the outside 99% of the time. But take another look at your example code. You've now introduced a race condition in your code between checking if an email address is already used, and then saving the new user data.
As someone that has done enterprise software engineering for ~15 years, these are now the sorts of things I look out for and have to engineer against. So when you see some more funky code, take a step back and ask "why is it done this way with this level of complexity?" - because more often then not, there are real world problems that need to be solved that cannot entirely be met with these ideals in mind.
I don’t see a new race condition. The simple fact some code has been segregated to functions doesn’t introduce something new. That code won’t run in parallel by merely calling the methods in sequence so that one thing could get executed out of order and without waiting.
It isn't because of separating them out into individual functions. It is that there could be multiple invocations at once, for instance two users attempting to register at the same time with competing information. And its because of situations like this why some code is written in a more complex way to handle these situations.
I guess if it is put in a step-wise class; where the order is obeyed. There shouldn't be a problem. We give this user flow exclusive access to these functions. Layout like this in the article would give headache if used inappropriately.
Yeah, but that’s not because the code gets split in functions. The exact same thing applies to the original code.
That’s a whole different discussion beyond the point of illustrating a concept.
I appreciate your suggestion. I have a question and correct me if I am wrong, Does the Race Condition or Data Race also occur in single thread programs/code?
If there is truly only one invocation possible at a time, then yes, that is fine. But that simply isn't scalable. If we're looking at a web application or API for instance, multiple users would be using the site at the same time.