We changed our privacy policy. Read more.

Hot answers tagged

1

A common way to send error responses in Express is to use middlewares. The benefit of doing it through a middleware rather than from a specific function is mostly about code duplication. In fact, if you just started the project, your needs may be relatively basic: for instance if it's an API, you may want to send a simple HTTP 403 response with a body such ...


1

Your second example is a little weird. It's not clear why you define this as a dict when you only show using the values. If you need the key and the value, I would generally prefer the for key, value in dict.items() idiom. That aside, there's a third option here: don't declare a variable at all. You could simply do this: def some_op(): for op in [...


1

You’re well on your way to making a global. The principle of data hiding tells us to limit exposure of details. Constants are details. The wider the scope the wider the exposure. The correct scope for variables and constants is the narrowest scope that works. Having them visible to code that doesn’t need them harms readability. If there is a need to define ...


Only top voted, non community-wiki answers of a minimum length are eligible