
In some cases, the `rule.adoc` at root of a rule is never included anywhere and thus is dead code. It's a maintenance cost by itself, but also it misses opportunities to inline code that seems used by two documents when in fact only one document is actually rendered. And this missed opportunity, in turn, stops us from applying the correct language tag on the code samples.
59 lines
1.5 KiB
Plaintext
59 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
It can be expensive to instantiate a new object, and doing so inside a loop is typically an error. Instead, create the object once, before the loop.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,flex]
|
|
----
|
|
for (var i:int = 0; i < 10; i++) {
|
|
var temp:MyObj = new MyObject(); // Noncompliant
|
|
//...
|
|
}
|
|
----
|
|
|
|
=== Compliant solution
|
|
|
|
[source,flex]
|
|
----
|
|
var temp:MyObj = new MyObject();
|
|
for (var i:int = 0; i < 10; i++) {
|
|
//...
|
|
}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Move the instantiation of this "xxx" outside the loop.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 7 Apr 2015, 23:24:31 Evgeny Mandrikov wrote:
|
|
I'm wondering if this rule is really relevant for C# , Java , C/{cpp}?
|
|
|
|
\[~dinesh.bolkensteyn], [~nicolas.peru], [~samuel.mercier], [~massimo.paladin], [~pierre-yves.nicolas], [~linda.martin] any thoughts?
|
|
|
|
=== on 8 Apr 2015, 05:14:57 Dinesh Bolkensteyn wrote:
|
|
I don't think it is [~evgeny.mandrikov]
|
|
|
|
=== on 9 Apr 2015, 13:00:35 Nicolas Peru wrote:
|
|
Neither for java. this one is a deprecation of a pmd rule which was already controversial : \http://stackoverflow.com/questions/17340421/pmd-avoid-instantiating-new-objects-inside-loops
|
|
|
|
So, [~evgeny.mandrikov] I agree with [~dinesh.bolkensteyn] I don't think it is worth to implement in Java.
|
|
|
|
=== on 29 Mar 2016, 23:48:20 Evgeny Mandrikov wrote:
|
|
This case is mentioned in "Google {cpp} Style Guide", so CPP-1448.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|