Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

65 lines
1.9 KiB
Plaintext

== Why is this an issue?
There's no point in chaining multiple ``++OrderBy++`` calls in a LINQ; only the last one will be reflected in the result because each subsequent call completely reorders the list. Thus, calling ``++OrderBy++`` multiple times is a performance issue as well, because all of the sorting will be executed, but only the result of the last sort will be kept.
Instead, use ``++ThenBy++`` for each call after the first.
=== Noncompliant code example
[source,csharp]
----
var x = personList
.OrderBy(person => person.Age)
.OrderBy(person => person.Name) // Noncompliant
.ToList(); // x is sorted by Name, not sub-sorted
----
=== Compliant solution
[source,csharp]
----
var x = personList
.OrderBy(person => person.Age)
.ThenBy(person => person.Name)
.ToList();
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Use "ThenBy" instead.
'''
== Comments And Links
(visible only on this page)
=== on 30 Jun 2015, 13:51:54 Ann Campbell wrote:
\[~tamas.vajk] I wonder if this is also an efficiency issue. The end result is a list that is sorted only by the last OrderBy argument, but doe all the previous OrderBy's take place, then get thrown away? If so, this would probably be worth adding to the description.
=== on 30 Jun 2015, 13:55:28 Tamas Vajk wrote:
\[~ann.campbell.2] I added a performance related sentence.
=== on 30 Jun 2015, 14:52:39 Ann Campbell wrote:
I shuffled the text some, [~tamas.vajk]
=== on 1 Jul 2015, 06:40:10 Tamas Vajk wrote:
\[~ann.campbell.2] Shouldn't this issue have some performance related label as well?
I simplified the message as the ordering might not happen by some property, but by some complex logic, and in this case we can't display the whole expression and ``++Comparer++`` in the message.
=== on 1 Jul 2015, 11:26:48 Ann Campbell wrote:
added [~tamas.vajk]
endif::env-github,rspecator-view[]