Skip to content

Conversation

@AdamSpeight2008
Copy link
Contributor

No description provided.

In the case where the method had no params args, as not providing them
is the same as the case of method with param args but not supplying
them.
Modified CharacterInfo.cs to use it.
@mikedn
Copy link

mikedn commented Jan 25, 2015

I don't know if matters here but removing the non-params overloads leads to an unnecessary empty array allocation if no additional arguments are provided. The DiagnosticInfo class that ends up storing the args is prepared to deal with null arrays and that may be a sign that the overloads were intentional.

As for IsBetween, well, that sounds like a reasonable attempt at killing the lexer performance 😄

Minimise use of "magic strings"
More use of interpolation string.
Moved Exts to Utilities and renamed to GenericExtensions
@AdamSpeight2008
Copy link
Contributor Author

@mikedn Why would it create an array? If no parameters are passed should the value of the params be null since an array is class type.

Of all the cases (VS can find) it is passed only one argument a string, an array see like to much.

@mikedn
Copy link

mikedn commented Jan 25, 2015

It creates an array of 0 length because that's what the C# specification requires.

I searched the code a bit and there are a couple of uses of the non-params overloads. Even if there are no concerns about allocation I'd probably keep those overloads because they avoid bloating the call sites with useless code for the array allocation.

Modifying DiagnosticsInfo for the case of only one argument a string.
@AdamSpeight2008
Copy link
Contributor Author

Why not optional argument?

 protected void AddError(int position, int width, ErrorCode code, object[] args = null)

Plus an overload for the case of string

 protected void AddError(int position, int width, ErrorCode code, string arg)

See commit 65d3d0a

@mikedn
Copy link

mikedn commented Jan 25, 2015

Seems like too much trouble. Avoiding allocating an empty array at the expense of a couple of null checks and trivial overloads is one thing. Avoiding allocating an array with a single element at the expense of additional overloads and more code to deal with this special case is another thing and should only be done if there's evidence that it improves performance.

Also, your PR contains a bunch of unrelated and unnecessary formatting changes. In particular, you seem to indent the code with 2 spaces while this project is using 4.

@theoy theoy added this to the Unknown milestone Jan 25, 2015
@AdamSpeight2008
Copy link
Contributor Author

Then if that's the case why the class OneOrMany?

@mikedn
Copy link

mikedn commented Jan 25, 2015

Presumably because someone has done the necessary analysis and decided that it's worth the trouble. I've never said that one should never do such an optimization, I said that such optimizations should only be done when they're really needed.

You started your PR with the goal to cleanup some code and when I pointed out that a particular change might be a de-optimization you changed the goal from cleanup to performance improvement, even if there's no evidence that the improvement is necessary.

@paulomorgado
Copy link

Changing:

       sb.AppendFormat("Summary: {0}\n", Kind);

into:

        sb.AppendLine($"Summary: {Kind}");

might seem pretty and modern but, in reality, it's changing into:

        sb.AppendLine(string.Formt("Summary: {0}", Kind));

Behind the curtain, string.Format uses a StriungBuilder. That would mean an allocation of a new StringBuilder when one is already being used.

The same goes to almost all, if not all, uses of string interpolation.

@paulomorgado
Copy link

Is there anywhere else in the Roslyn code where optional arguments are being used on public or protected methods?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous error said it was a binary operator while this error states that it is a unary operator.

@AdamSpeight2008
Copy link
Contributor Author

I'm still trying to get used to Git. I thought that a pull request would only pull up to a specific point of time, not subsequent commits. It was only for the overloads and extensions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: blank line separator

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: double blank line

@jaredpar
Copy link
Member

jaredpar commented Feb 6, 2015

Thank you for the contribution!

A significant portion of this change is simply altering the style of the existing code. In general we are going to be reluctant to take such changes. They generally represent churn in the code base that don't provide concrete value.

Overall our code base now follows the .NET Foundation contributing guidelines including their coding style requirements. Much of the code didn't follow this when originally posted but over the last few weeks it has all been migrated to meet those guidelines. The code will continue to follow those guidelines going forward.

Style changes will generally be taken only when it:

  • Significantly improves the readability of the code in question.
  • Changes code to conform to the stated guidelines which previously did not.

@AdamSpeight2008
Copy link
Contributor Author

@jaredpar The single line if's do improve readability.
Maybe allow them if it is small ( eg with the total line width of 80 chars?)
Eg Guards

if( arg0 == null ) throw new NullArgumentException( nameof(arg0));
if( arg1 == null ) throw new NullArgumentException( nameof(arg1));

More of guards and you are talk in the region of half the screen height, before you even get to the "good stuff" of the method. not all of have huge monitors, some laptops has more horizontal space than vertical

Simple returns

if( x == 0 ) return "Zero";

SImple Cases

select ( value )
{
  case 0:  return "Zero";
  case 1:  return "One";
  case 2:  return "Two";
  case 3:  return "Three";
  case 4:  return "Four";
  case 5:  return "Five";
  case 6:  return "Six";
  case 7:  return "Seven";
  case 8:  return "Eight";
  case 9:  return "Nine";
  default:
    return "shrug";
}

15 LoC vs 25 (separate lines ) or 35 if in require the breaks.
The 4 space indentation is too wide, it should be 2. Considering the each block / scope get indented.

Now consider the case where pattern-matching is included, the code will get both wider and longer (in terms of structural layout).

@jaredpar
Copy link
Member

jaredpar commented Feb 7, 2015

@AdamSpeight2008 whether or not single line ifs, or most other style decisions, improve readability is subjective. What is preferable to one developer may not be preferable to the other. The important aspect of style is to keep it consistent across the code base.

In this specific case though single line ifs are not permitted by the coding guidelines.

@sharwell
Copy link
Contributor

sharwell commented Feb 7, 2015

@AdamSpeight2008 You submitted a pull request from your master branch. This means any subsequent commits you make to the master branch in your fork while this pull request is open will automatically appear here. To make things much easier, you should create a new branch in your fork and use it to perform one specific change (e.g. changing instances of AppendFormat to use string interpolation). You can then send a pull request to merge that branch and it can be evaluated independently of any other type of changes you want to propose.

To start working on a different proposed change, such as creating new constants for string literals that appear in code, go back to the latest master commit and create another new branch for that change.

Otherwise, when you send a bunch of different types of changes in a single pull request, it has a high likelihood of getting rejected if people disagree with one of the changes, even if they agree with the majority.

@AdamSpeight2008
Copy link
Contributor Author

Note: The original repo for this PR as been removed.

@jaredpar jaredpar removed their assignment Nov 23, 2015
@jaredpar jaredpar removed this from the Unknown milestone Nov 23, 2015
@gafter gafter added the Resolution-Won't Fix A real bug, but Triage feels that the issue is not impactful enough to spend time on. label Dec 9, 2015
dibarbet added a commit to dibarbet/roslyn that referenced this pull request Mar 1, 2023
dibarbet pushed a commit to dibarbet/roslyn that referenced this pull request Nov 21, 2025
…CodeAnalysis.FxCopAnalyzers-3.3.0

Bump Microsoft.CodeAnalysis.FxCopAnalyzers from 3.0.0 to 3.3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Feature Request Resolution-Won't Fix A real bug, but Triage feels that the issue is not impactful enough to spend time on.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants