2022 Developer Survey is open! Take survey.

New answers tagged

0 votes

Would Injecting dependencies in C# as default parameters be a bad practice?

In any reasonably sized codebase, the nested DI parameters are going to explode, which is going to bite you when you want to write those concrete constructors like that. Even if reasonable on a ...
user avatar
  • 37.3k
0 votes

Would Injecting dependencies in C# as default parameters be a bad practice?

There's no singleton in your example, but what you are doing isn't bad per se. Its fairly common practice to provide default implementations where there is going to be tight coupling regardless. ...
user avatar
  • 64.1k
2 votes

Using two different languages where one would suffice for the task (microservices)

In general I would recommend keeping the number of languages in a solution to a minimum when you are working with a team. Mainly because you minimize the likelihood that the one person who introduced ...
user avatar
3 votes

Should we abandon the "if not null" pattern?

This has been around since the early days of .Net - e.g., TryParse(string). In that particular case, it was, among other things, a way for the dev to indicate that an exception shouldn't be thrown. ...
user avatar
-1 votes

Should we abandon the "if not null" pattern?

Another downside is that if later on you want to adopt asynchronous programming into your code base, you can't convert your TryABC(out int i) into TryABCAsync(out int i) because async method can't ...
user avatar
  • 107
10 votes

Should we abandon the "if not null" pattern?

The bool TryXXX() pattern is not designed to avoid nulls. A method could assign null to an out parameter so technically you would still have to check. It's needed in locking situations, say where you ...
user avatar
  • 64.1k
1 vote

State machine using SOLID principles. Connecting to real devices

I think you are still missing the point. A device would not need to know about its manager. The manager would create some devices and put them to work when it is time to do so. Devices can be just ...
user avatar
  • 15.4k
17 votes

Should we abandon the "if not null" pattern?

There are a few reasons this has fallen out of favor. Out parameters require mutability, because you have to create a variable in the calling code that the function mutates. Out parameters are better ...
user avatar
  • 13k
1 vote
Accepted

Calculate operation time and setuptime or costprice based on a variable set of parameters - Design Pattern?

There are a couple of approaches possible here. To name a few: create dependency network: the parameters of your excel sheet would be nodes. The transformations that use these parameters to determine ...
user avatar
  • 66.9k
1 vote

Calculate operation time and setuptime or costprice based on a variable set of parameters - Design Pattern?

The decorator pattern may be of help here. The idea being that optional behaviors can be mixed and matched arbitrarily with construction code rather than a forest of if branches. This can end up ...
user avatar
1 vote
Accepted

Blazor Application separation of concerns

I'm going to focus on Blazor WebAssembly here, not Blazor Server-Side, because you're trying to compare it to an Angular frontend. However, I am not so sure how I could separate the front-end and ...
user avatar
  • 37.3k
2 votes

How to implement automatic SemVer from code changes

In the comments, amon is absolutely right that just changing the interfaces is insufficient to determine if behavior is backwards compatible. I find it highly unlikely that you would be able to build ...
user avatar
  • 75.6k
-1 votes
Accepted

Can be logic around `List<T>.Enumerator._version` considered control flow exploitation?

As I see the case, there was no best one options for authors than to exploit control flow constructs in List<T> methods in order to preserve common contract of foreaching. I mean mostly that not ...
user avatar
  • 268
1 vote

Are there any named principles, best practices, etc, that are being violated here?

It is bad foremost because it makes no sense and is confusing all the way. ParseAppendValue. What does it mean? Is AppendValue a thing that is to be parsed? (my first assumption). It turns out the ...
user avatar
  • 15.4k
0 votes

Are there any named principles, best practices, etc, that are being violated here?

With what I see in your question, the conception/ architecture might not have been done correctly (or not have been done at all). There might be reasons for that (I'm pretty sure most of those reasons ...
user avatar
  • 944
0 votes
Accepted

How Should I Go About Refactoring My Code With Dependency Injection?

I believe DI would help I expect it's more than mere "help", it's the key. But you already use DI if using parameters in constructors and other methods because that's all DI is. Fortunately ...
user avatar
  • 5,641
1 vote

Do i still need to use fixed point to guarantee computers get the same result for math operations anymore?

You still need to be careful. Conversion between floating point and decimal may give different results in very rare cases (depending on the quality of the compiler and standard library). Standard ...
user avatar
  • 37.4k
1 vote

Do i still need to use fixed point to guarantee computers get the same result for math operations anymore?

The answers given are light on relevant specifics (sadly a common problem with C# discussion). The problem isn't a trivial one, and much is written about it (it's often called "floating point ...
user avatar
1 vote

Unsupported concurrent calls, throw exception or log a warning?

I don't think there is a one-size-fits-all answer for this. If there is the risk of data corruption - as in one call may make a bad decision or return a bad value because the other call was ongoing, ...
user avatar
  • 343
2 votes

Unsupported concurrent calls, throw exception or log a warning?

You should look at it from a user's / caller's point of view. And I doubt that your approach "I would like my service to discard concurrent calls, allowing only the first one to execute" ...
user avatar

Top 50 recent answers are included