From 858a5e8276c452b66eb9cc147399b0fcc3c336d7 Mon Sep 17 00:00:00 2001 From: jfiat Date: Thu, 5 Jun 2014 23:42:12 +0000 Subject: [PATCH] Author:admin Date:2014-06-05T23:42:12.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@1377 abb3cda0-5349-4a8f-a601-0c33ac3a8c38 --- .../ca004-command-query-separation.wiki | 6 ++- .../ca005-useless-object-test-local.wiki | 49 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 documentation/current/eiffelstudio/eiffelstudio-reference/eiffel-inspector/eiffel-inspector-rules/ca005-useless-object-test-local.wiki diff --git a/documentation/current/eiffelstudio/eiffelstudio-reference/eiffel-inspector/eiffel-inspector-rules/ca004-command-query-separation.wiki b/documentation/current/eiffelstudio/eiffelstudio-reference/eiffel-inspector/eiffel-inspector-rules/ca004-command-query-separation.wiki index 7c72b60a..8369ce36 100644 --- a/documentation/current/eiffelstudio/eiffelstudio-reference/eiffel-inspector/eiffel-inspector-rules/ca004-command-query-separation.wiki +++ b/documentation/current/eiffelstudio/eiffelstudio-reference/eiffel-inspector/eiffel-inspector-rules/ca004-command-query-separation.wiki @@ -30,8 +30,10 @@ There are rather exceptional but sometimes useful class designs in which the ext =Example of violation= height: INTEGER + -- Height in pixel of Current. width: INTEGER + -- Width in pixel of Current. do height := height + 10 Result := 100 - height @@ -40,12 +42,14 @@ width: INTEGER =Recommendation= Ensures that no query changes the state of the current object. -In the example, one could replace the call to width by a call to update_width followed by a call to width where update_width would be: +In the example, one could replace the routine width by an attribute and calling update_width before querying width where update_width would be: update_width + -- Update `height' and `width' with .... do height := height + 10 width := 100 - height end +Or you can remove the line height := height + 10 from the body of width. diff --git a/documentation/current/eiffelstudio/eiffelstudio-reference/eiffel-inspector/eiffel-inspector-rules/ca005-useless-object-test-local.wiki b/documentation/current/eiffelstudio/eiffelstudio-reference/eiffel-inspector/eiffel-inspector-rules/ca005-useless-object-test-local.wiki new file mode 100644 index 00000000..69d7a671 --- /dev/null +++ b/documentation/current/eiffelstudio/eiffelstudio-reference/eiffel-inspector/eiffel-inspector-rules/ca005-useless-object-test-local.wiki @@ -0,0 +1,49 @@ +[[Property:title|CA005 - Useless object test local]] +[[Property:link_title|CA005]] +[[Property:weight|0]] +[[Property:uuid|56a54ef0-48e8-b58f-ac2c-09074782b9f7]] +__NOTOC__ +=Description= +For local variables and feature arguments it is unnecessary to use an object test to check their attachment status. + +:{| class="doctable" +|- +| '''Scope''' +| feature +|- +| '''Status''' +| Enabled +|- +| '''Severity''' +| Suggestion +|- +| '''Applicability''' +| All +|- +| '''Score''' +| 40 +|} + + +=Example of violation= +if attached a_local as another_local then + another_local.do_something +end + + +=Recommendation= +Remove the object test local, or replace the object test and use a comparison to Void. + +In the example, it can simply be: +if attached a_local then + a_local.do_something +end + + +or + +if a_local /= Void then + a_local.do_something +end + +