Word of warning to developers

Word of warning to developers

Postby RickW » Thu Sep 04, 2008 7:03 am

There are a lot of us writing scripts/plugins, and as our numbers grow, so do the odds that someone will write something that breaks something that someone else wrote.

So, some important items to remember:

1. Try to know what others are doing/have done - this isn't always easy, but some research and questions go a long way in avoiding conflicting class/method names. It can also prevent you from duplicating someone else's effort - why re-create method x when it's already been written? Just tap into it and go (with permission, of course). Sometimes, the already-written code won't do exactly what you want. In that case, you can either subclass yours and modify the methods (for classes, obviously), or write your own using a different class/method name.

2. Try to use unique names rather than common ones - for example, if you write a "ProgressBar" class, you will cause conflicts with any other "ProgressBar" class. That will make for unhappy users, as they try to get tech support for something the author says works just fine on his machine, but clearly won't work on their machine; and will make for unhappy fellow developers, who have to hunt down the conflicting script, locate the author, and try to work out a solution.

3. Encapsulate methods in a Module or a Class - within a class, you don't have to worry about method naming conflicts, and within a module, you can be less careful about both class and method names.

4. Test your work against as many other works as possible, and test them against yours - unfortunately, the burden of compatibility will more than likely fall to the second developer. However, if you send your script to other developers asking them to test for compatibility with their works, they'll most likely be happy to oblige (subject to their own time constraints, naturally). This will help keep the user experience (and your reputation) positive.

Just some helpful tips to hopefully keep this great collective creative work going smoothly...
0

RickW 
 

Re: Word of warning to developers

Postby Matt666 » Thu Sep 04, 2008 12:42 pm

Hi Rick ! Thank you, I will pay attention to these items for future scripts !

3. Encapsulate methods in a Module or a Class
Sorry but I don't really know how to encapsulate methods in a module...
Is there just one method to use Module ? I know this method (from Jim' scripts)
Code: Select all
Module Test
  def self."method1"
    ...
  end
  def self."method2"
    ...
  end
end

And to call the script, we have to write 'Test."method1"' for example. Are we obliged to write the "self"?
Briefly, I do not know this method :)

Can you help me ?
0
Frenglish at its best !
My scripts

Matt666 
 

Re: Word of warning to developers

Postby RickW » Thu Sep 04, 2008 3:29 pm

The Pragmatic Programmer's Guide has some good information on modules.

Hope that helps,
0

RickW 
 

Re: Word of warning to developers

Postby Matt666 » Thu Sep 04, 2008 3:35 pm

Thank you !
0
Frenglish at its best !
My scripts

Matt666 
 

Re: Word of warning to developers

Postby CPhillips » Thu Sep 04, 2008 10:35 pm

Come on. Spill it. What plugin did you find a conflict with? :)
0

CPhillips 
PluginStore Author
PluginStore Author
 

Re: Word of warning to developers

Postby todd burch » Sat Sep 06, 2008 1:20 am

One of my paid scripts was broken by a free script. Names are being withheld until notification of next of kin. :lol:
0

todd burch 
 

Re: Word of warning to developers

Postby Didier Bur » Sat Sep 06, 2008 10:31 am

:oops: :oops: :oops:
0
Didier Bur
Ecole Nationale Supérieure d'Architecture de Nancy (F)
User avatar
Didier Bur 
 

Re: Word of warning to developers

Postby Gaieus » Sat Sep 06, 2008 11:24 am

:D :roflmao: :lol:
0
User avatar
Gaieus 
 

Re: Word of warning to developers

Postby ScottLininger » Fri Oct 24, 2008 9:11 pm

Another broad area of "wishlisting" is how we can best handle the problem of our scripts accidentally clobbering other people's. It's great that Ruby is such a flexible language, but we've all seen situations where two of us choose the same name for something and everybody loses.

RickW has suggested to me that we form some sort of "official" policy and/or repository for handling this problem, and for reducing code rewriting, so that we all benefit from the collective knowledge of the group, but as of yet I haven't pulled together a proposal for the community. What are your ideas?

Some possibilities:
> Create an "official" means for extending Sketchup.rb, along with a versioning system, so that we can extend the base API.
> Create some kind of name-spacing convention that we can publicize and encourage folks to use.

I'm sure these are things you've all been talking about (I'm still catching up on back-messages.) I want something that's *easy* for people to use, from novice ruby programmer to expert. If it's too hard for people to understand and adopt, then we're wasting our time... What do you think? I'm all ears.
0
- Scott Lininger
SketchUp Software Engineer
Have you visited the Ruby API Docs?
User avatar
ScottLininger 
 

Re: Word of warning to developers

Postby solo » Fri Oct 24, 2008 10:15 pm

I am no coder so my opion is worthless however .... how about having all ruby's include the authors initials? IE adjust_textures_PJS.rb (hypothetical ruby)
0
http://www.solos-art.com

If you see a toilet in your dreams do not use it.
User avatar
solo 
Global Moderator
 

Re: Word of warning to developers

Postby Dik Harrison » Sat Oct 25, 2008 2:22 am

Formally, I worked for a large government agency that developed their software internally, with development taking not only at development centers, but also at individual sites (170+), at least that is how it worked a number of years ago, now there is not much development going on now. Any way, back when everybody was developing or at least customizing for local use, each site was given a short code 3-4 letters that made their variables and routines unique. Using initials or some such would work in this situation, but a list of initials would need to be maintained, so that duplicated would not occur. Then a coder would simply add their code as a prefix or sub-fix to their routines and variables. For example, I would write a routine called something-wrh.rb, with a variable x-wrh. It would be up to me not to step on my own code.
0
Have fun...

Dik

Dik Harrison 
PluginStore Author
PluginStore Author
 

Re: Word of warning to developers

Postby TIG » Sun Oct 26, 2008 11:36 pm

The precepts of the law are these: To live honourably, not to injure another, to give each his due.

As Gaeius's strap-line says [in pig Latin]...

i.e. Remember: Be nice to others. Don't mess others up. Give others due credit...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: Word of warning to developers

Postby Gaieus » Mon Oct 27, 2008 8:01 am

Hi TIG - yes, a bit off-topic but hey... :D

It's Institutiones Iustiniani 1.1.3

(I wrote my thesis in Roman Law at the Law School ;) )
0
User avatar
Gaieus 
 

Re: Word of warning to developers

Postby Jim » Tue Oct 28, 2008 12:47 am

I have been using my initials as a module name to encapsulate everything I release, although I think sometimes little things slip through the cracks.

Would a shared Google Docs spreadsheet be good enough to claim and register namespaces?

Code: Select all
        Name        |        Email        | Registered Namespace
Carl Coder          | ccoder@gmail.com    | Ccoder
0
Hi

Jim 
Global Moderator
 

Re: Word of warning to developers

Postby ScottLininger » Tue Oct 28, 2008 4:31 pm

Have people seen any errors from other ways that scripts mess with each other besides naming overlaps? For example, observers from script A are messing with the model before my observers from script B fire off?
0
- Scott Lininger
SketchUp Software Engineer
Have you visited the Ruby API Docs?
User avatar
ScottLininger 
 

Re: Word of warning to developers

Postby todd burch » Wed Oct 29, 2008 5:25 pm

There have been right-click context menu issues with validation routines. The classic issue here is HouseBuilder causing a beep if installed whenever any right click was done. Not so much a conflict as an annoyance.

I remember an issue one time with some script extending a base class of Ruby (like NullClass) and it causing issues. Don't remember the specifics.

What should probably be promoted is script authors subclassing Sketchup classes to extend them, as opposed to just extending them.
0

todd burch 
 

Re: Word of warning to developers

Postby tomasz » Wed Oct 29, 2008 7:04 pm

ScottLininger wrote:Have people seen any errors from other ways that scripts mess with each other besides naming overlaps?

I've got two scripts on my black list.
1st place : Matchbox Plugin 1.1 by antantantant
Population.rb
Code: Select all
class Array
  def * (n)
    temp = Array.new()
    i = 0
    if n.kind_of? Float
      each {|v| temp[i] = v*n
            i = i + 1}
    end
    return temp
  end
 
  def + (n)
    if n.kind_of? Array
      i = 0
      temp = Array.new()
      while i < [self.length, n.length].max
        temp.push(self[i] + n[i])
        i = i + 1
      end
    return temp
    elsif n.kind_of? Float
      each {|v| v = v + n}
    end
  end
end

Arrrrgggghhhhhhh..... !! Do NOT modify built-in Ruby methods, please!!

2nd place: Train Simulator 1.2 exporter by Paul Gausden
mstsx.rb
Code: Select all
class Sketchup::Color
    def ==(c)
       return (c.alpha==self.alpha and c.red==self.red and c.green==self.green and c.blue==self.blue)
    end
 end

Modification of original SU method, which can : 1st - give different results than other Ruby programmers expect, 2nd - prevents != method to work correctly.

Those bugs makes my life and users of my exporter harder. :(
0

tomasz 
SU2TH & SU2KT Developer
 

Re: Word of warning to developers

Postby sepo » Sun Jan 25, 2009 8:38 pm

Matchbox is also on the Podium NO NO list.
0

sepo 
 

Re: Word of warning to developers

Postby deerwood » Fri Feb 06, 2009 7:42 am

Hi all,

though I not yet had any name clash problem, may I suggest a rule adopted from the Java world? The essential idea is to qualify/prefix "packages" with something unique in our internet world. Namely the domain of the author, reversed, optionally followed by some more specific info.

So e.g. Jim's "jitter.rb" is qualified by "com_blogspot_sketchuptips" and the specific info beeing "jitter".

And Ricks "GoldenGauge" is qualified by "com_smustard" (or maybe "com_smustard_wilson_rick") and the specific info beeing "golden_gauge".

Following that idea the plugins working code would not reside any longer directly inside the "plugins" directory (unless it is an essential thing/library) but in some directory named after the domain inside "plugins".

E.g. Jim's plugins ALL reside in "plugins/com_blogspot_sketchuptips" and ALL of the Smustard ones are present under the "plugins/com_smustard" directory, optionally further down in a dir named after the author ("..../wilson_rick") or a project ("..../common" or "..../utils").

And, please, all other excellent plugin writers here around: I apologize to not have named you. But you'll get the idea, hopefully.

To call/activate such a plugin on startup of SU there must be a minimal Ruby script directly in the "plugins" dir, requiering the real code. These would be one liners, but then named after the complete path to the plugins code. E.g. "jitter" would have this Ruby in the "plugins" dir (named "com_blogspot_sketchuptips_jitter.rb"):
Code: Select all
require 'com_blogspot_sketchuptips/jitter.rb'


But it should be easy to just call a script common to a domain, that does advanced handling of (sub)scripts to be included. That script then just requires, what the final user wants to have. These require scripts (down to any level of the dir hierarchy) could easily be tweaked by users, by just commenting out "require" statements.

Packaging of plugins into this hierarchie/concept is easy for every developer of plugins.

Every plugin's author is known/can be reached (as long as his domain is existent).

Cluttering of the plugins directory is reduced greatly, especially when the feature of just require'ing subdirs reqire scripts is used.

What do YOU think?

Best regards, deerwood
0

deerwood 
 

Re: Word of warning to developers

Postby RickW » Fri Feb 06, 2009 7:37 pm

Interesting concept, and for creating Module names, it could work. However, locating files in subfolders by organization/author name conflicts with Organizer.rb.

Currently, Organzier allows users to create subfolders in the Plugins folder that then become submenus in the Plugins menu, with the scripts located in those subfolders likewise having menu items in the respective submenus. For example, you could create a "Draw-Create" subfolder, then move all scripts that draw or create geometry in that subfolder. In the Plugins menu, there would be a Draw-Create submenu, and each file in that subdirectory would be represented in the submenu. It's a fast way for users to clean up both their Plugins menu and Plugins folder at the same time, while grouping scripts by like function.

I think that a script that parses the new template file and can display the pertinent script information in a webDialog will go a long way towards helping users who want or need to know the author/contact information or version number to check for updates.
0

RickW 
 

Re: Word of warning to developers

Postby deerwood » Mon Feb 09, 2009 5:42 am

Dear Rick, all,

RickW wrote:Interesting concept, and for creating Module names, it could work. However, locating files in subfolders by organization/author name conflicts with Organizer.rb.


sorry, I wasn't aware of the organizer.rb. Hmm. Still not giving up on the subfolder idea ;) , what about more closely mimic that Java concept by having under "plugins" max 2..4 letter folders named after the top level domains, e.g. "com", "edu", "org", "net", "tv", "de" or "co"? Isn't the length of TLD's restricted?

The organizer then could just ignore short folder names directly under "plugins", or, if neccessary, have a list of (additional) TLD names to ignore.

Under the TLD folders there would be the appropriate domain name folders of the authors. So someones/Jims/yours/mine plugins would reside in
  • plugins
    • co
      • uk
        • someone
        • someone-else
    • com
      • blogspot
        • sketchuptips
      • smustard
    • de
      • georg-rehfeld

For the module/class names I'm not any longer really happy with my proposal, because the names would be so exceptionally long/unusabale. Or did I miss some Ruby feature?

Just brainstorming, not more.

Best regards, Georg (aka deerwood)
0

deerwood 
 

Re: Word of warning to developers

Postby Chris Fullmer » Mon Feb 09, 2009 5:52 am

I think I'm not seeing what the problem is with having plugins just placed in the root plugins folder?
0
Lately you've been tan, suspicious for the winter.
All my Plugins I've written
User avatar
Chris Fullmer 
SketchUp Team
SketchUp Team
 

Re: Word of warning to developers

Postby deerwood » Mon Feb 09, 2009 6:25 am

Hi Chris,

as told, I had no name clashes yet in any way. But I see myself "managing" my plugins already, though I'm still a newby.

Especially because there are soooooo many, very helpfull plugins around/published in this forum :D (wow, thanks to all providers). I have to find a way to try these out and find the ones appropiate for my way of working with SU ... ever changing as I get these new great additions and learn to use them.

And then: Rick warned, I wrote, what came up into my mind. Maybe, that is poor/not appropriate. It is meant as just a base idea ... brain storming, as stupid as it may be, should not be taken literally. Take just one idea out of it or come up with a totally different general approach. Collect as much of ideas as possible. Later on one or the other may be able to make use of the idea.

Best regards, Georg/deerwood
0

deerwood 
 

Re: Word of warning to developers

Postby DavidBoulder » Thu Dec 10, 2009 6:51 pm

Good thread. I may get in to a large ruby project soon, and I'm glad I ran across this. Will give me insight on how best to name and organize my code/scripts.
0
--

David Goldwasser
OpenStudio Developer
National Renewable Energy Laboratory
User avatar
DavidBoulder 
 

Re: Word of warning to developers

Postby MartinRinehart » Fri Dec 11, 2009 6:20 pm

I don't like the initials idea. I'm probably here early enough to lock up "mr" but Mike Roberts and Mary Ryan may not be so happy when they get here next year.

The Java sort-of-standard proposed by Sun (inverted website names) never got popular. Too long. A ten-pound cure for a one-pound problem.

I think that using the name of the plugin should be SOP. VisMap is in a module named VisMap. That means that before you release anything, you Google it, which is a good idea for a lot of reasons.

A Wiki or Google doc re bad plugins would be most helpful. "X is bad" is not helpful, but "X is bad because..." would tell you what not to do so that you don't end up on the bad list.
0
Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

MartinRinehart 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Developers' Forum

Who is online

Users browsing this forum: swan9738 and 7 guests

Visit our sponsors: