Repository navigation
Fixes around array.Any translation - #1556
Conversation
Closes npgsql#1554 Closes npgsql#1555
YohDeadfall
left a comment
There was a problem hiding this comment.
Looks good, except style changes.
| static readonly MethodInfo ILike2MethodInfo = | ||
| typeof(NpgsqlDbFunctionsExtensions) | ||
| static readonly MethodInfo ILike2MethodInfo | ||
| = typeof(NpgsqlDbFunctionsExtensions) |
There was a problem hiding this comment.
Any reason to change the style? As I remember we leave assignment on the first line everywhere because of indentation. Right now, instead of 4 characters offset, for such lines it's 6.
There was a problem hiding this comment.
Mainly for consistency with expression-bodied methods, where we put the => on the next line.
There was a problem hiding this comment.
I think putting => on the first line is better too for the same reason plus for sharing styling with .NET runtime.
There was a problem hiding this comment.
The EF Core standard (and this is an EF Core provider) is to put it on the next line (usually... sometimes a bit inconsistent :))
Why is a 4 char offset better than 6 char?
There was a problem hiding this comment.
Because of alignment with non-expression bodied methods. For example, prefixed commit messages (don't remember how that convention is called) is bad too due to how people read text. Monospace fonts were made to help human beings to scan files vertically without jumps vertically, but inconsistent indentation breaks that achievement.
There was a problem hiding this comment.
I really don't see any reason for expression-bodied methods to start at the same offset as non-expression-bodied methods... They're different methods...
One good argument for putting it on the next line, is that it makes it immediately clear if it's a field initialization or a property with a getter only. This crucial difference can easily get lost if it's the arrow or assignment is far to the right on the first line.
There was a problem hiding this comment.
It's not a hill I want die for. I said my opinion, but leaving it up to you.
| { | ||
| if (expression is BinaryExpression binary) | ||
| { | ||
| (left, right) = (binary.Left, binary.Right); |
There was a problem hiding this comment.
While I use tuple assignments often, I don't think they looks well outside of expression bodied methods.
There was a problem hiding this comment.
Embrace the Python style :) One line instead of two!
There was a problem hiding this comment.
Let's leave two line instead of one, really hard to read. If there is a comma operator allowing to write a single line instead of three, I will be happy.
There was a problem hiding this comment.
Even the conservative guys in EF have agreed to me doing this... Seriously though - I know it's new syntax, it just requires getting used to...
|
|
||
| if (methodCall.Method.Name == nameof(object.Equals) && methodCall.Arguments.Count == 1) | ||
| { | ||
| (left, right) = (methodCall.Object, methodCall.Arguments[0]); |
There was a problem hiding this comment.
Looks like this method produces sorted results already, so why not to determine ordering for the static equality method and for binary expressions?
There was a problem hiding this comment.
I don't understand... The only job of TryMatchEquality is to provide the two side of the equality - there's no sorting/ordering involved...
There was a problem hiding this comment.
I meant this:
var item = left == wherePredicate.Parameters[0]
? right
: right == wherePredicate.Parameters[0]
? left
: null;It can be made simpler probably if it will combined with that method.
There was a problem hiding this comment.
TryMatchEquality is just about identifying equality and returning its parameters - it could be extracted and used elsewhere too. But if you think code can be really simplified here, do you want to submit a full code proposal?
There was a problem hiding this comment.
Not today, you caught me while I was heading to bed (:
There was a problem hiding this comment.
No problem for it to come after merge too :)
| (left, right) = (null, null); | ||
| return false; |
There was a problem hiding this comment.
If there would be a way to express such a thing in one line, it would be fine, but not now. In C++ which you dislike it's possible thankfully to comma operator, so here is an idea for a proposal for C# language team:
return (left = null, right = null, false); // only the last value used as the resultIn that case you would be able to rewrite the whole method as an expression. Do you like it?
There was a problem hiding this comment.
The problem is that your expression is already legal in C#, and means something else:
public (string, string, string) Bar(ref string left, ref string right)
{
return (left = null, right = null, "hello");
}There was a problem hiding this comment.
If the left side expects less values than the right, it should work:
public string Brar(ref string left, ref string right) =>
(left = null, right = null, "hello");Otherwise, it would be cool to specify return keyword to solve the problem:
public string Brar(ref string left, ref string right) =>
(left = null, right = null, return "hello");There was a problem hiding this comment.
IMHO that is super ambiguous with the tuple syntax... There's already a (a, b, c) which means something very clear. In your first example, you cannot know the type of that expression without looking at the method return type, which I think is a no-no in language design (even if we have target-typed assignments now)...
There was a problem hiding this comment.
In case of expression based methods it could be fine since the type is nearby, and last example includes return.
Closes #1554
Closes #1555