To require "sketchup.rb", or not to ... that is the question

And I disagreed in the other thread. Write your comments to mean what they should mean. Most especially if it is a example or tutorial that is going to teach the knowledgeable.

I always teach what I learned from the Ruby docs and the Pick-Axe book…

Require only what you need. (Requirements are listed by YARD and other documentation generators.)

How about:

exit unless $0 == "SketchUp"

I actually used this form in a plugin that I did not want to run in DoubleCAD Ruby (although I don’t think I ever released it into the wild.) DoubleCAD had implemented (badly,) a clone of the SketchUp API, so it also had a Sketchup module defined.

EDIT: Another couple might be:

exit unless defined?(Sketchup) == "constant"

or

raise(NotImplementedError,"Runs in SketchUp Ruby ONLY!") unless defined?(Sketchup)

:bulb:

IF …this is a hypothetical situation that does not exist.

Do we teach new coders based upon possible future scenarios ? … or what exists now ?

But this is YOUR workflow!

We don’t tell the whole world to mimic you, if they do not have that same workflow.

Besides, I find it more likely that a mock API would be loaded via the command line, or a "load 'api'" statement typed into the IRB shell.

That is what I would do. I’d set up the “outside” Ruby environment to be exactly like the internal one, just after SketchUp startup. And in that “mock up” the “sketchup.rb” file should be the very same, and implement the same functions as it does in the internal environment.

In conclusion, because you (and maybe others,) are using this statement as a “marker” and in a way that it was never intended,… does not mean we should tell everyone else to put meaningless statement in all their files.

You don’t have to comply nor agree, because you have a workflow that uses the statements in two ways.

But I am a purist. I respect ya’ Andreas, but I must disagree with ya’.

IF, in the future, there does happen some external Ruby API, that runs outside of SketchUp,… then it isn’t SketchUp,… and it shouldn’t be named “sketchup”.

It should have it’s own name, like “skpapi” or whatever.