TheSwamp

Code Red => .NET => Topic started by: Keith™ on June 11, 2017, 08:40:02 AM

Title: To share or not to share!
Post by: Keith™ on June 11, 2017, 08:40:02 AM
There seems to be some debate amongst the interwebs regarding shared/static functions and if/when you should do so.
My question is directly related to exposed commands in AutoCAD as is evidenced by the following code snippets:

Code - vb.net: [Select]
  1. <CommandMethod("MyCommand", CommandFlags.Modal)>
  2. Public Shared Sub MyCommand()
  3.         MyClass.SharedSub()
  4. End Sub

Code - C#: [Select]
  1. [CommandMethod("MyCommand", CommandFlags.Modal)]
  2. public static void MyCommand()
  3. {
  4.     MyClass.StaticSub();
  5. }

What are the advantages of declaring these static and are there issues if they are not?
Title: Re: To share or not to share!
Post by: Keith Brown on June 11, 2017, 11:14:03 AM
Norman has written a nice article about this question several years ago.


http://drive-cad-with-code.blogspot.com/2010/09/command-method-static-or-not-static.html (http://drive-cad-with-code.blogspot.com/2010/09/command-method-static-or-not-static.html)
Title: Re: To share or not to share!
Post by: Keith™ on June 11, 2017, 10:40:08 PM
Norman has written a nice article about this question several years ago.


http://drive-cad-with-code.blogspot.com/2010/09/command-method-static-or-not-static.html (http://drive-cad-with-code.blogspot.com/2010/09/command-method-static-or-not-static.html)

I was aware of what he talks about ... I guess it doesn't really matter unless I need to move data between drawings. The application I am working on only works on the current document and doesn't need to be MDI aware.
Title: Re: To share or not to share!
Post by: It's Alive! on June 12, 2017, 12:17:34 AM
Static will be slightly faster, not something a user would notice though... Instance offers more flexibility, so I’d probably prefer the later.
However, I’d probably prefer static lisp functions
Title: Re: To share or not to share!
Post by: Keith™ on June 12, 2017, 01:07:54 AM
I have multiple commands that are exposed. All of them are used to instantiate a specific class or call static code directly.