People who code: we want your input. Take the Survey

New answers tagged

0

The top answers here are good, but I wanted to add another way of addressing this with your coworker. a colleague, specifically focused on this method, cites that, because the class calls the self.logger.warning, it violates the single responsibility principle (SRP) "Logging" is very vague, and your coworker isn't correctly distinguishing between ...


0

I agree with the answers already that you should take these principles pragmatically so I personally think your code is fine however I'd like to take a stab at where I think violates SRP just to play devil's advocate. if sc != 200: self.logger.warning(f'{self.query.id} returned with code: {sc}') I would argue this branch of your query handler will ...


0

SRP taken to its extreme isn't practical. Let's take a practical, familiar, real-life example where SRP has been successfully implemented: fast food restaurant chains. In SRP, you would define a restaurant in a chain to have a single responsibility of serving food to customers. However, implementation details include things like handling credit card payments,...


0

"Principles" in software are concepts to assist you, and make your live easier. Whenever someone argues based on a "principle" that you should make your life harder, either that someone misunderstood the principle*, or - more likely - there's a communication failure between the two of you, meaning you misunderstand what they are saying, ...


2

Actually yes, if you look strictly, the logging logic should not be a concern of a method (function) doing other things. But, then it can be applied to any method/function, so where would you put the logging statement? In the end most code you can see has logging statements somewhere in the code. Having said that, this kind of concern is called a cross ...


0

It is mostly clear from your code example that you/we are talking about debug logging, or logging for debug purposes or reasons. I think other answers already tackle the issue. Debug logging is like a separate "layer". However, for completeness' sake(1), there is also transaction logging and/or audit logging [not sure if that's the official name], ...


0

Well, you are both a bit right. SRP can certainly be applied to functions, and in fact I think it applies to functions even more than it does to classes. OTOH, logging isn’t a responsibility of the function. You are logging for debugging purposes. Notionally that means it doesn’t even exist as far as the class is concerned. But if it was a responsibility ...


9

There are already two excellent answers here that I fully support. I’d nevertheless like to add a couple of thoughts for the sake of completeness: The name “single responsibility principle” is utterly misleading. Many misunderstand it as being about the responsibility of the class. But Uncle Bob, who invented the term, explained that it is not about ...


25

People have gone mad thinking about what constitutes a "single responsibility". The principle is sound, but it is usually stated in a way which cause more confusion than clarity. The principle is about seperating independent concerns - independent at the level of requirements and stakeholders. In other words, any single thing a product owner could ...


42

Your colleague is taking the word "Single" too literally and dogmatically. SRP just means a class should have a single conceptual purpose. What constitutes a single conceptual purpose will differ between different types of software, and how the module fits in a larger program. There isn't some sort of mechanical definition you can test against in a ...


Top 50 recent answers are included