good practises null object return [closed] - c#

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have a question about c# programming language, when a method returns an object, and for example I'm forced to return null, which is not clean code, what is the best practise to handle this? I dont want to return null.
EDIT
This was a question because it started as discussion on a software engineering class after reading Clean Code - Robert C. Martin 's book and it really came to my mind that trying to avoid this added unnecesary complexity to the design.

In case to signal "failed to create object" C++ class constructs throws exceptions for this purpose.
Some languages / projects prefer to use exceptions more to keep happy-pass happier while others may not.

Related

RegEx best practices in C# [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I came across writing Regular Expressions against user input in a C# console application, here are a couple of questions:
When a RegEx becomes pretty long like below, is it smart to keep where it is in the code? Or put it with my other constants in their own class? Or even smarter to just not use it and do it some other way?
Regex regEx = new Regex(#"\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*)*");
How does RegEx affect the behavior/load of my application and what more do I have to consider when using RegEx?
You should definitely use Regular Expressions. You should however look out for the performance implications if used incorrectly. If you are using it frequently, you should look at using Compiled Regular Expressions.
For further reading on the performance & best practices there is a nice MSDN article http://blogs.msdn.com/b/bclteam/archive/2010/06/25/optimizing-regular-expression-performance-part-i-working-with-the-regex-class-and-regex-objects.aspx

When would IL-written code be faster than C#-written code? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
According to StackOverflow Update: 560M Pageviews A Month, 25 Servers, And It's All About Performance (perhaps getting its information from Marco Cecconi The Architecture of Stack Overflow at 29:00),
Some coding is in IL, not C#.
I am not asking about anything specific to Stack Overflow site, but, generally speaking, when would IL-written code be faster than C#-written code?
My understanding, from reading the posts of Eric Lippert, most of the optimizations in .NET are done when JIT'd:
We let the jitter team worry about optimizing the heck out of the code when it is actually spit into machine code; that’s the place where you can get real wins. — What does the optimize switch do?
What sort of optimizations can be made from hand-coded IL?

What is the best use of a variable when required by multiple methods [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm using XmlManager to
do xml manipulations in several methods in a class.where I should declare XmlManager variable ?
1.locally within each method and do intialization.
2 declare at globally and initiate at the method level
As it is, in this question, there's absolutely NO difference whatsoever because there's neither performance gain nor significant design issues.
Maybe if the question is put into context there could be reason to choose one approach over the other, but as it stands now. None of the approach is better than the other one

Pros and cons of async/await [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
In 2013, Microsoft added new feature to the .NET framework to help handling asynchronous tasks: async/await.
How does this feature affect the readability of the code?
Here are few disadvantages that I found:
It is the same as using return in the middle of the method: it makes it hard to catch the flow of the code.
It reminds of GOTO in C: it makes it hard to catch the flow of the code.
async/await are not easy to understand, but once you get the principle of synchonization context capture/restore, it's relatively easy to follow the code flow.
The main issue with this feature IMO is the async all the way problem, i.e. once you're writing an asynchronous piece of code, all your code tends to become asynchronous too.
I recommend this excellent article on MSDN Magazine for a good understanding of the whole async topic.

Is "massive" usage of #region considered a bad practice? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
My MainViewModel has to deal with a lot of commands with complex actions inside, therefore its extension has grown inevitable. For keep the code organized I tend to use #region to group similar o related tasks.Does this considered an overuse of this feature or it's perfectly normal? You may say that it depends on me, if I feel right about it. I think that it helps a lot but I would like to know what do others. Here is a screenshot of how the code look like:
The bad practice is a massive single class. #region is simply hiding / coping with it.
If there are groups of methods, delegate them to another class.

Categories

Resources