Author Topic: To share or not to share!  (Read 301 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16618
  • Superior Stupidity at its best
To share or not to share!
« 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?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Keith Brown

  • Swamp Rat
  • Posts: 585
Re: To share or not to share!
« Reply #1 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
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16618
  • Superior Stupidity at its best
Re: To share or not to share!
« Reply #2 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

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.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

nullptr

  • BricsCAD
  • Needs a day job
  • Posts: 6736
  • AKA Daniel
Re: To share or not to share!
« Reply #3 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

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16618
  • Superior Stupidity at its best
Re: To share or not to share!
« Reply #4 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.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal