[talk] Using Ruby Modules
-
@dan rathbun said:
Hell yeah...!
Now you're speaking my language Dan!
@dan rathbun said:
I was going to name the method ".parrot" and add it to module Kernel, that way it would be global.
Hmm, parrot is interesting. And lord knows i parrot off about Python all the time. However the word lacks an intuitive-ness for the action it implements. I don't think you'll find a better word than import.
-
I think there used to be a developer wiki - but I think I saw it when I first joined SCF. Can't remember or find it now. In any case it fell into disuse.
Jim did create an alternative to the official API docs, http://code.google.com/p/skx/wiki/ClassIndex one that we could edit ourselves. Which I find more useful than just posting comments and twiddling thumbs, waiting for it to be acknowledged.
Haven't had time to use or work on it, but it would be good if he had that, and a wiki at one joint location.It has bothered me that so many resources are wedged in between all the questions and general discussions.
The forum is great for gathering knowledge, but no good at organizing it.
-
@thomthom said:
Jim did create an alternative to the official API docs, http://code.google.com/p/skx/wiki/ClassIndex one that we could edit ourselves.
Well my hats off to Jim although i looked over the doc and not much is there. I fear it will suffer the same fate as all the other docs and resourses -- a slow and agonizing death! Multiplicity and mediocrity are very prevalent in the SketchUp Ruby world today. We mush reign in this madness! Too long have stood idle whist the castle is laid siege. We need to yelling with a united voice daily...
Google we need an official Script Repository!
Google we need and official tut that can be edited by members!
Google we need official docs that can be edited by members!... and we need all this information centralized yesterday!
@thomthom said:
Which I find more useful than just posting comments and twiddling thumbs, waiting for it to be acknowledged.
Is this comment directed at Moi?
@thomthom said:
Haven't had time to use or work on it, but it would be good if he had that, and a wiki at one joint location.
Wrong! We cannot keep up this multiplicity. We must force Google to do what is needed. You just wasting you time creating more sites that no eyes will see. If you have a suitcase full of money buried in the back yard but you forgot where you buried it then you really DON'T have a suitcase full of money do you?
@thomthom said:
It has bothered me that so many resources are wedged in between all the questions and general discussions.
Yes this too is a major deterrence to learning. Heck i was reading an announcement thread about a new script that had like 200 replies and many revisions to the script. After an hour of reading i just gave up. I could not even find the proper version in all the noise. It would be wise to allow an "announcer" to edit the very first post of his "announcement" indefinitely so he could update links to future versions or add more comments TO THE VERY FIRST POST INSTEAD STINGING INFOMATION THROUGHOUT 200 POSTS . Let the following string of thread[2..-1] answer users questions but keep the first post as an editable informational only post.
@thomthom said:
The forum is great for gathering knowledge, but no good at organizing it.
-
@jessejames said:
Is this comment directed at Moi?
No - it was directed at the current system of the API docs. We have a long thread here with comments on the API docs. Which on occasion is read by Googlers which in turn make adjustments.
That was before they added the comment system on the API pages - where it was requested me made comments there. But response to our comments has been slow.@jessejames said:
We must force Google to do what is needed.
There's a problem here - we don't have much power to force Google to do anything. If one can make Google buy into an idea - it's something that'd be a dreadfully slow process. Doing it yourself seem to be the only thing to get stuff done.
All though I agree that there's no point in yet another site/resource project falling into disarray.
However, I do believe that our previous attempts might have been a bit over-ambitious. Starting of with a too big of a task. Starting off with something smaller and evolve that could work better.@jessejames said:
Yes this too is a major deterrence to learning. Heck i was reading an announcement thread about a new script that had like 200 replies and many revisions to the script. After an hour of reading i just gave up. I could not even find the proper version in all the noise. It would be wise to allow an "announcer" to edit the very first post of his "announcement" indefinitely so he could update links to future versions or add more comments TO THE VERY FIRST POST INSTEAD STINGING INFOMATION THROUGHOUT 200 POSTS . Let the following string of thread[2..-1] answer users questions but keep the first post as an editable informational only post.
What plugin was that? People can edit their own posts.
The normal convention here at SCF is that the first post contains the updated most recent version of the script. Pretty much all topics for plugins adhere to that.
A more recent discussion has been in regard to the visibility of the download link - a Download button graphic making it easier to spot the download link. Something some authors already use and something I will be updating my posts with. -
Wow this thread is all over the place.. but interesting.
Jim's Wiki API is an experiement. I played with one of the ConstructionPoint class, and came to the conclusion, it's just way too labor intensive. It relies too much on people following a set of style rules.
I did an automtic API some years ago using CSV data and HTML Tabular Data Controls that auto generated the API page. I wasn't satisfied (although it worked.) I always wished to update it to XML. Add the entries into the xml would be via a webform (check boxes, cut&paste boxes, etc.) then later on the API doc (either web or CHM,) would be generated from the XML (however PHP, RUBY take your pick.)
Editing would be similar, the method data would be displayed in an edit form.
Anyway the style of the API pages would be controlled thru CSS, and all pages, classes, would be displayed the same.
-
@morgan74 said:
Thanks Dan for this interesting topic. I was rewriting all my plugin's code when I saw this thread.
So the only thing I need to do to follow you is adding a "TOP_LEVEL" namespace to my modules.But I have a question about adding methods to Sketchup classes :
I want to add a method to "Geom::Point3d", how can I use a special name ??Here my current code :
> class Geom;;Point3d > def myFirstMethod > return(self.z*self.z) > end > end >
-
@thomthom said:
@morgan74 said:
But I have a question about adding methods to Sketchup classes :
I want to add a method to "Geom::Point3d", how can I use a special name ??Here my current code :
> > class Geom;;Point3d > > def myFirstMethod > > return(self.z*self.z) > > end > > end > >
It's impossible to be 100% sure no one else implements a method of the same name as your when you extend a shared module/class. But if you for instance prefix with your initials you decrease the likely hood that your method is overwritten.
Personally I don't extend the base Ruby and SketchUp classes because of the potential of name conflict. (Doesn't look as good - but it's safe.)
-
Hmm, i was wondering when\if these posts would get moved.
PS: if you guys need a easier hint to the 1264 thing send me a PM. I fear i may have set the bar too high!
-
@jessejames said:
Hmm, i was wondering when\if these posts would get moved.
This is an example of people who just cannot follow instructions. (sigh!) And then compound the error, by posting AGAIN, to acknowledge he sould not have posted there. (I shake my head in wonder..)
It just shows that the forum environment is not so good for tutorials. Even the dedicated Tutorials Forum allows reply posts. I wish we could lock our own topics such as my [info] thread.
But at least I tried...
-
@jessejames said:
Anyway the real reason i replied is because i would for you and I to create a nice WORKING example of the very nested module system you are referring to. And what better example to use than all the script in the default SketchUp examples folder...
- animation.rb
- attributes.rb
- box.rb
- contextmenu.rb
- linetool.rb
- selection.rb
Well yes I have been thinking about this.. but there are isssues.
-
I just know that some newbies are going to tweek, change and update the examples, without changing the namespaces. The examples need to be in some 'Google' namespace, as opposed to MY examples which would be in my namespace. These 'examples' I don't think would be sub-namspaced under the normal "Plugin" namespace ::PINE, but in an ::EXAMPLE namespace. (Most are not "true" plugins anyhow, more like code snippets we are supposed to paste into our own plugins.) I haven't yet finalized what the proper organized namespace trees should be, but I'm semi-close to publishing a proposed "Community Standard."
-
I have a huge list of my own projects I'm working on, or want to work on. (Some I've had to put aside, because they will rely on another project; or there's some bug in the API; or some missing feature not in the API that I will need. Anyway I either must wait until the API is updated, or create the functionality myself, propbably in C code.)
-
There is an issue of compensation. These scripts are the intellectual property of Google, although they have released them under terms close to the language of the MIT License. Yes, I would be helping everyone in the community, but ALSO, one of the largest software corporations in the world. I need income! I have bills, and am not employed. (The unemplyment rate here on the Florida Space Coast, is high and getting higher with the end of the Space Shuttle program.) I'd love to whip the Examples into shape. I'd love to correct every typo and missing argument description, etc within the API documents. But technical documentation is what I do for a living, and I feel that I should be paid, even if in the short term it's a discount payrate (I'm not greedy, and my expenses are low.)
@jessejames said:
The bad thing about a system like this is the fact that if people find it too confusing to implement they will just choose to be lazy instead -- and the last thing we need to do is help spread MORE laziness around this group! I always say a working example is the key to understanding systems like this.
True.. but there is also immense value in this. Last week one of the newbies I've been mentoring, PM'd me to ask for just this same thing. He wished me to provide him with a working skeleton of a tool plugin, into which he could paste his Tool class definition. (He even put a "## my tool code goes here" comment in his outline.)
I spent three 10 hour days putting together just such a skeleton, and then realized I could not keep doing these things. That is between 500-1000 dollars of work (depending on what you think the payrate should be.) I took a break, went on a walk, thought about it, and came to the conclusion that I need to genericize the code, AND implement it as a "Plugin Builder Wizard" (which would be a plugin itself.) Think about how a Software Installation Wizard works, and you'll get the idea. Sucessive forms, with choice controls (checkboxes, etc.) and the person would either use an "import file pathname" box (with a 'Browse' button of course,) OR a "paste code here textarea." (Their choice.)
So that's what I'm going to do with that project. But this cannot be free. I must have some kind of income from it.
Either individual license, or some entity, (commercial or benevolent,) needs to purchase it from me, for the salary-time I've put into it.To complicate it a bit... I had to stop work on that, in order to resume my project to update the Sketchup Extension class as the "wizard" project will require it. I had already revised the Extension class to v1.1.0 back in January, and have been running it since (but did not release it.) It was only a few simple, minor changes.
This update will be v2.0.0, and will have major changes, BUT also be BACKWARD COMPATIBLE with v1.0.0 (the original un-numbered Google release.)
In addition I have some features I want to put in there, but they may need to wait for v3.0.0 or I'll never get it (or my other projects) finished.
This also has the same compensation issues like I had stated above. How to release it? I will have 2 weeks (say 100 hours invested in v2.0.0,) and really need to be paid for this somehow. Either Google buys it and they release it, OR I need to convince users and developers that it's a good thing and pay some small token license fee. (Somewhere between one and five dollars US.) -
@dan rathbun said:
Well yes I have been thinking about this.. but there are isssues. [...snip...]
Ok Dan, let me make sure i follow you. I going to summarize your post and tell me if i am correct...?
You want to create a "namespace manager" plugin (for lack of better term?) that works like a typical installation wizard. A user of such plugin would create a script by writing code in a "toplevel" manner without worring about modules or even nested modules. THEN they would run the plugin which would auto wrap their code into a proper nesting of module namespaces with their name being the toplevel module space. So in the end, the scripter no longer has to worry about the confusing aspects of Ruby modules and can concentrate on writing usable code that will be safe from invading outside namespaces.
Is this correct?
Hey, this plugin may even work nicely on a nested folder structure of scripts in which to base it's "module nesting" on..? You create a toplevel folder with your name, then maybe a tools folder full of tools, then maybe a lib folder, and on and and on. -
@thomthom said:
What plugin was that? People can edit their own posts.
Hmm, i'll give a clue... the sum of his name is 1264. I'll let the advanced readers decifer the meaning
PS: I'm just glad it was not 666
-
@jessejames said:
@dan rathbun said:
Well yes I have been thinking about this.. but there are isssues. [...snip...]
I going to summarize your post and tell me if i am correct...?You want to create a "namespace manager" plugin (for lack of better term?) that works like a typical installation wizard.
Yes.. and NO. There would be a "Coder's Config" feature (dialog) where they set up defaults (name, company, Location, TopLevel Namespace, etc. etc.) but these defaults should be able to be overriden on a project basis, if say they were doing contract work for other than themselves (ie: another company.) So yes.. there ARE project management aspects.
And there would be Namespace Managemnt aspects, as some prolific coders are likely to subdivide their namespace into Catagorical subnamespaces (Anim, Export, Import, Report, Tool, Utility, Widget, whatever and however they'd want to organize their products.)
But it is really a "Proper Plugin Code Generator and Functionality Adder."
@jessejames said:
A user of such plugin would create a script by writing code in a "toplevel" manner without worring about modules or even nested modules. THEN they would run the plugin which would auto wrap their code into a proper nesting of module namespaces with their name being the toplevel module space.
Yes.. but with flexibility. (I'll just say that [for future possibilites,] they'll have the option of nesting their TopLevel namespace within other namespaces, even nested ones.)
More important. What I was speaking of in the previous post... is much more than a simple wrapper. It is specifically aimed at Tool class, and auto generates Extension loader scripts, optional Smustard Compatible Menu Scripts, Normal Menu Scripts, Toolbar Scripts, etc. It more than just "wraps" the raw tool class code, it also adds management functions, auto unload functions. It takes care of "doing it the correct AND safe way", ie it takes over the setup of the menu / toolbar command, so it's done correctly without creating a zillion uneeded tool objects every time the menu is clicked, etc. It sets things up so a coder can "publish" a safe tool call for other poeple to call (from another script, or a custom toolbar, etc.)
I suppose it could also work for normal non-plugins like Importers / Exporters etc. I'll just need to keep that in mind.@jessejames said:
So in the end, the scripter no longer has to worry about the confusing aspects of Ruby modules and can concentrate on writing usable code that will be safe from invading outside namespaces.
More exactly: "code that will NOT invade outside namespaces." (Meaning that crap scripts can still poop on the Objectspace, but it won't then do much more than waste memory. I still hate poop methods in Object getting inherited by every module and class.)
You are actually describing another item on my todo list. The "wrapper". (A linear command script really does not need a wizard; I've already shown in the forum how to put a couple of module blocks around them.) There's the possibility someone like you and I want to autowrap all code in our plugins folder, rather than manually edit every script we download.
And.. a proplific coder, may want a batch utility to autowrap all his project folders, rather than do it manually.
I may be speaking of several separate utilities here.@jessejames said:
Hey, this plugin may even work nicely on a nested folder structure of scripts in which to base it's "module nesting" on..? You create a toplevel folder with your name, then maybe a tools folder full of tools, then maybe a lib folder, and on and and on.
Yea you speak of a project folder and it's subfolders, such as we'd use with MS Visual Studio. They would contain the "raw" code snippets, and the Wizard would output the "distro" files in folders beneath the project's "distro" folder (which has a "plugins" folder.) Any file (a Extension registration rb,) that needs to go in the Plugins folder, would be put in the "distro/plugins" folder itself. From there it's manual copy to the real plugins folder (for your own testing,) or zip the fake "distro/plugins" folder for distribution/posting.
-
Of course the next campaign.. when we get everyone to wrap there code.
Is to get them to change their $vars to @@vars.Like $my_specific_plugin_menu_is_loaded
-
I use that syntax Dan. As far as I know, I was the first to try to make multiple plugins all work under the same main sub-menu, so as to not clutter the plugins menu.
If you have a problem with my coding, you can always PM me, or mention it in a specific plugin thread. But generalizing about all us noobs with bad habits or pros with bad habits, and talking bad about many of us who are trying hard to contribute is just bad taste. Knock it off.
Chris
-
@dan rathbun said:
Of course the next campaign.. when we get everyone to wrap there code.
Is to get them to change their $vars to @@vars.Like $my_specific_plugin_menu_is_loaded
Dan you bring up another very important point. Too many folks have this knee jerk reaction to create a global when they should be creating either class level or instance level variables. And i don't think they realize the danger of such behaviors. There is a reason why we feel pain, it both protects and teaches us.
I am starting to think that you should be the captain of this lost ship. Too many bad habits are propagating throughout this community. Someone needs to step up and say enough is enough already!
-
@chris fullmer said:
I use that syntax Dan. As far as I know, I was the first to try to make multiple plugins all work under the same main sub-menu, so as to not clutter the plugins menu.
Thats not even what this thread is about Chris. We are talking about namespaces here NOT how many Plugins Menu "commands" your script adds. Your inability to understand what we are talking about is the root of the problem. I don't blame you for learning how to script in a poor manner (namespace wise!) i blame Google and the other pros here who have not stepped up to the plate and made the tough decisions for all of us.
@chris fullmer said:
If you have a problem with my coding, you can always PM me, or mention it in a specific plugin thread. But generalizing about all us noobs with bad habits or pros with bad habits, and talking bad about many of us who are trying hard to contribute is just bad taste.
Sorry Chris but that is NOT how a community works. If i have a problem with your coding style, or if Dan has a problem, or even if John Doe has a problem, we can and should voice our problem publicly. THAT IS OUR RIGHT CHRIS! You made the decision to release public scripts and your public scripts are available for our criticism. If you cannot handle the heat, then get your scripts out of the kitchen!
You act as if we are just making up lies and i can assure you that is not the case. The problems we speak of are very real and infect this community from top to bottom. Obviously the problem is real because you're acting out in a "knee-jerk" emotional way to real criticism. If we are lying then feel free to offer the truth and correct us.
@chris fullmer said:
Knock it off.
Don't you even dare try to use your moderator status to scare anyone away from free speech Chris. You will never scare me, I can assure you of that!
However i want you to understand that nobody is picking on you "personally". Heck, believe it not i like you -- even when your insulting me sometimes . You have given much to the community however you missed something very important. Everyone in this group is guilty of writing poor Ruby code and I want to fix that. Even i have written poor Ruby code because i did not know any better. So we must reign in this madness or it will get out control and sink the whole ship!
I would really like for you to get involved with this effort Chris. Bring some real discussion to the table and we can work it out. But instead of getting all emotional -- try to bring some logic next time.
-
Could you guys (me saying this "generalizing" for the time being) take a little break, go out for a walk in the fresh air and come back a bit more relaxed?
Programming, coding and scripting should not be a reason for such heated discussions.
-
@gaieus said:
Could you guys (me saying this "generalizing" for the time being) take a little break, go out for a walk in the fresh air and come back a bit more relaxed?
Hi Gaieus,
I don't think these discussions are heated at all. SketchUp modelers and scripters are by far the most laid back and good hearted bunch of folks I've had the luxury of dealing with. I admit that I myself over react to criticism -- it's human nature. Chris is a very good Ruby scripter and deep down he knows that what we are talking about is real.
-
RUBY VERSION ISSUE: The toplevel scope operator
Ruby v1.8.0 does not allow the TopLevel scope operator prefix, ie:
class **::**MyTopLevel::MyPlugin::ThisClass
Ruby v1.8.6 does allow it. It basically tells Ruby to start looking at the TopLevel for an indentifier, instead of backing up thru each nesting level from the current level. (It speeds things up. It's similar to telling a system to start at the root of a drive when finding a file.)
I've removed the use of it in the examples in the [info] thread, as many users will be running v1.8.0 on Win32, and not know how to update their Sketchup Ruby. Also if the script is evaluated at the toplevel [which is the norm,] the prefix operator is really not needed.
Advertisement