using System.Text.RegularExpressions;Drawing;Threading;

Class library usage, coding and language questions.
Poblarp
Posts: 7
Joined: Thu Oct 20, 2016 3:23 pm

using System.Text.RegularExpressions;Drawing;Threading;

Post by Poblarp » Mon Jan 09, 2017 6:09 pm

Hi there,

When creating a code module, Ranorex automatically includes the following namespaces.

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;

During the code review, I was asked to remove the following namespaces from my code modules:

using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;


The reviewer said that I haven't used the above functionalities in my code.

If I may remove the above 3 namespaces (Text.RegularExpressions, Drawing, Threading), would Ranorex still functions properly without compromising its reliability and efficiency ?

Thank you very much for your input.

Best regards,

Poblarp

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: using System.Text.RegularExpressions;Drawing;Threading;

Post by krstcs » Mon Jan 09, 2017 6:22 pm

Without seeing your actual code, I don't think anyone can say for sure what you need or don't need.

However, if you are using the standard, Ranorex-generated modules then you should not remove the generated using statements as they are potentially used in other places in the code, mostly by machine-generated segments that are not user-editable.

The issue is that you are editing a PARTIAL class, and if you remove items from the user-code part, that doesn't mean it is removed in the computer-generated part, and that it isn't actually needed.

Normally your peer would be correct, but in this case they are not. I would recommend that you leave the generated code alone.


Edit to add: In addition to the above, the .NET compiler will disregard any unused using directives at compile time, so having them there won't impact the compiled executable.
Shortcuts usually aren't...

Poblarp
Posts: 7
Joined: Thu Oct 20, 2016 3:23 pm

Re: using System.Text.RegularExpressions;Drawing;Threading;

Post by Poblarp » Mon Jan 09, 2017 7:01 pm

Thank you very much for your input on this issue. I will pass along this info to my co-worker who has reviewed my code. They are not working in Ranorex and C# so they may not have knowledge specific to Ranorex and C#. They mostly work with Python and Java for their automation development.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: using System.Text.RegularExpressions;Drawing;Threading;

Post by krstcs » Mon Jan 09, 2017 7:34 pm

You're welcome.

As I said, normally you want to remove unused using directives, more because it clutters the code than anything. But with Ranorex most of the code is generated, and it is best to leave it alone, especially when it's like this where it doesn't make a difference.
Shortcuts usually aren't...

User avatar
Stub
Posts: 173
Joined: Fri Jul 15, 2016 1:35 pm

Re: using System.Text.RegularExpressions;Drawing;Threading;

Post by Stub » Tue Jan 10, 2017 9:38 am

FWIW I have an option enabled in VS2015 that deletes unused Using statements upon save. I love it. So when I'm editing my Ranorex code in VS rather than the Ranorex native editor I automatically lose these unnecessary Using statements. Hasn't impacted me at all that I've noticed. So I say chuck 'em and put 'em back in if it fails to compile.