Ruby scripts lack style
-
@unknownuser said:
My reason is that I have never bothered to look do closely at this whole open source concept. I know I use lots of software that are open source, but there are so many licenses out there to choose from - each with a long chuck of text with many clauses that it's hard to get an overview. And I also have no idea of what each license does - some let people use it commercial purposes etc. So I find it easier to just let people ask me and state their purpose.
I agree the amount of licenses available and understanding the clauses are a task better suited for tax code lawyers. However really all you need to concentrate on is a few small words...
- use
- copy
- modify
- distribute
- commercial
Thats really all you need for open sourcing a script...
# Copyright YEARHERE, NAMEHERE. # # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the above # copyright notice appear in all copies. # # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
However! There really needs to be some templates for licensing posted at an official SketchUp site. Because most people (as you have admitted yourself) do not complelely understand the legality of all these licenses and when to apply them.
Choosing the wrong license spec can be damaging to the entire community. We desperately need some templates so everybody can copy paste the same license (of which they can choose from three) in the following categories...
- Completely open source license.
- Completely free to use for personal use only!
- Free to use only!...and hopefully we will place these in the same place as the official script repository!
Of course Google and @Last should be pushing for ALL scripts to be completely open source or at least open source for personal usage. Of course --as i stated before-- i am not against people close sourcing "certain" scripts if they have done a substantial amount of groundbreaking work on them. But Google's official statement should promote the fee exchange of ideas, technology, and collaboration. That's IMO! Push the completely open source and frown on the closed.
@thomthom said:
@jessejames said:
Look we need to declare all out holy war against bad coding styles. We need to go through all the scripts at Ruby Library Depot, SketchUp scripts, and anywhere else we can get our grubby paws to, and re-write these abominations before too much damage is done
This just ain't going to happen.
In all due respect i highly disagree with that statement and the attitude of laziness you display. ThomThom, you have always been and continue to be one of my favorite people around here but please don't make damning statements like that. That very attitude is why we have found ourselves in such a pitiful state today. And with you being a moderator statements like that have greater potential to destroy the will of the new scripter's to do the right thing and follow a prescribed style of code writing.
@thomthom said:
All these scripts are written by people on their own time. Most are written by non-professional like me. And many are written for a small specific purpose just to get the job done. I doubt there are many enthusiastic about re-working everything just for the sake of making the code pretty while not providing any advantage for end user. I certainly have no interest, and most importantly time, for such a huge task.
Thats great that people give their time to do this however they need to realize the damage that is done from use a bad style. Bad styles are like a hereditary disease, they get passed down from generation to generation. Some one has to put a stop to that infestation at some point. And i hope we can all agree to apply the cure before it's too late!
@thomthom said:
Whenever I pick up an old plugin of mine to add some new features I do usually refactor - but I never bother to refactor just for the sake of refactoring.
I seriously hope that i can make you realize how important proper style is and change your bad habits ThomThom. Because it's always much harder to unlearn a bad habit than to learn a new "good habit"! Hopefully we caught the problem before it becomes terminal.
@thomthom said:
I do appreciate the thought of a wast repository of cleanly coded plugins - but it just isn't realistic.
But it is realistic ThomThom, we can go back and change the scripts if we can get the larger community speaking with the same voice. I would love to contribute myself at re-working these scripts -- and i will. However for the "non modifiable" licenses we will need the authors permission. Thats why we need peer pressure to make this work. It WILL work if you believe that it will. And we should use that peer pressure to encourage full open sourcing where applicable!
@thomthom said:
What is realistic is advocating good style for new plugins. And help out new scripters with best practices. There are loads of information on this forum - but unfortunately it's not properly organised.
I highly agree. At the very least we cannot. And we should not allow future scripts to be so sloppy. If we do the endless cycle repeats...
while lazy code_sloppy() end
@thomthom said:
What I like about SketchUp is that it has a low entry level - for its modelling and for it's scripting system.
Absolutely! And offering these budding chaps clean code will only serve to quicken the pace of their learning. There is no downside to accepting a good style of coding. Everyone will benefit in the end
-
@jessejames said:
FURTHERMORE! We need to be yelling and screaming daily to Google, @Last, and anybody who will listen ...
FYI: @Last Software no longer exists.
Google acquires @Last Software
Yelling and screaming and insulting hasn't worked. We've tried it (and given up.)
The same old bugs are still in the application we've cried about for years. (Shadow bug.)
Everyday we discover another missing method that should have always been in the API, or another Registry setting we cannot access or a property of a Drawingelement subclass that has no attribute accessors. ..etc.. etc. (I have become weary of doing hours and hours of work proofreading the API docs and identifying bugs and shortcomings of the API itself without getting paid. If the Sketchup API was OpenSource, I would feel differently, but it's not. Google is one of the largest software companies in the world and can afford to hire the gurus to get done what needs to be done, if they wished to. It has become obvious to me that corporate Google either does not know the bad state of the API and it's documentation; or they do not care. I think they see Sketchup as a mere utility that supports the "real" product Google Earth.)I'm thinking the world needs a TRUE OpenSource 3D Modeling Application Project that supports multiple scripting engines (Ruby, Python and OpenBasic,) to name a few.
But I'm going off topic here...
-
@dan rathbun said:
I'm thinking the world needs a TRUE OpenSource 3D Modeling Application Project that supports multiple scripting engines (Ruby, Python and OpenBasic,) to name a few.
Blender? Might not support multiple languages - but it's fully open source.
-
@thomthom said:
Blender? Might not support multiple languages - but it's fully open source.
I was thinking of making scripting APIs for BRL-CAD
http://brlcad.org/It was written at Berkley Research Labs with public funds (I believe. I'm under the impression that NASA uses it for some of it's graphics.) I had downloaded the code back about 10 years but never did anything with it. It has been updated many times since then.
-
@jessejames said:
Modules and Classes ...to indent or not to indent. That is the question!
I have said it before and i'll say it again... the module syntax is clutter and it would be more elegant to use the file as the module (like Python does) however thats a Ruby issue and we need to accept that for now.Your dang right you have to accept it.. because never have you been more wrong James!
THIS issue is by a large margin more important than proper indenting. (Poorly indented or ugly style scripts don't "crap" on my code. Any non-coding user and I, will never know how ugly they may be unless we open the code in an editor. If the code works, however ugly, what does it matter if it's never seen.) I'm all for good indenting, and I HATE outdenting!
Module syntax is NOT clutter. If you (speaking generally to all readers and especially newbies,) do not understand the importance of modules, then you do not understand how Ruby operates and how code is (and should be,) loaded.
Modules separate your code from other people's code, and prevent your code from "crapping" on the ObjectSpace (which is the same as "crapping" on everyone else's modules and classes, including Google's and Ruby's.) ANY script that defines methods, instance variables, class variables or constants in the ObjectSpace IS "crap." It does not matter if Google did it in their examples, it is still "crap."
Not only should you be using A module around your script... you should be using nested modules. The outermost is your TOP_LEVEL namespace, Ex(using your SCF screenname):
module JesseJames
Any tool or plugin you create should be in a nested module (submodule,) of your TOP_LEVEL namespace. This allows individual tools or plugins to be removed from memory when they are no longer being used. TOP_LEVEL modules and classes can NOT be removed (by design.) This means the standard Ruby modules and classes, and Google's Sketchup, UI and Geom modules are safe. It also means a malicous coder cannot remove YOUR top level namespace. (It also means Google incorrectly put their modules at the toplevel, when they should have been within module Google. What happens in the future when Layout gets an API, and/or Picasa gets a Ruby API that integrates to Sketchup and Layout?)Back to indenting... anticpating a chorus of whiney voices, thus:
"Oh man, nested modules mean I have to waste so much space on the left of my code, and push the "meat" of my rubies way to the right! And then I have to hit that TAB key all the time on every line... boohoo!"
No you don't! Ruby allows multiple scope defintions !
If I wish to define a class within a submodule of my toplevel module, I can do so and only have 1 indent:unless defined?(;;MyTopLevel)=='module' module ;;MyTopLevel end end # unless unless defined?(;;MyTopLevel;;MyPlugin)=='module' module ;;MyTopLevel;;MyPlugin end end # unless # The Outer namespace modules must exist before referencing them class ;;MyTopLevel;;MyPlugin;;ThisClass def initialize(*args) # INIT CODE GOES HERE end # def end # class ;;MyTopLevel;;MyPlugin;;ThisClass
[You don't need the definition test(s) if you KNOW that the outer module(s) have already been created (like their definitions had preceeded this class definition in the same file, OR this file "requires" the file that defined the outer modules.)]
I can also save an indent when defining a plugin module by doing:
unless defined?(;;MyTopLevel)=='module' module ;;MyTopLevel end end # unless # The Outer namespace module must exist before referencing it module ;;MyTopLevel;;MyPluginTwo class<<self private def method_one # .. code .. end public def method_two # .. code .. end # .. etc .. end # self end # module ;;MyTopLevel;;MyPluginTwo
instead of doing this:
module MyTopLevel module MyPluginTwo class<<self private def method_one # .. code .. end public def method_two # .. code .. end # .. etc .. end # self end # module MyPluginTwo end # module MyTopLevel
Let's save Ruby vs Python for another topic thread, but for now, let me say in regard to your statement:
@jessejames said:...it would be more elegant to use the file as the module (like Python does)..
that this CAN be done in Ruby using the wrap parameter of the load method. However it is simplistic and lacks control. The script is loaded into a temporary Anonymous namespace (module,) that is removed from memory when the script ends. So the important lesson here is the lack of controlling the namespace(s) under which the code runs, as well as controlling the persistance of the objects the code may create.
Your just better off wrapping the code the namespace(s) ie, modules of your choice, to begin with.I have been tempted to write a Toilet plugin, that will load "crappy" scripts into namespace:
::Toilet::Crap
and when done, "flush the toilet" so to speak by calling ::Toilet.flush which would remove the submodule Crap. I am musing over the idea to have a scanner that would scan scripts to determine if they do "crappy" things, like defining $global variables for one time use, and converting them to module vars.
But number 1 on the list of "crappy" things, (drumroll,) is defining custom classes at the top level (ie, within Object.) ONLY Ruby base classes generic to the entire Ruby universe should be declared at the top level. (And yes Google broke that rule in a few places, but it does not negate the rule. Example: The custom Sketchup Set class is defined at the top level, instead of as Sketchup::Set, and will clash with Ruby's standard Set class, if you load the latter.) -
@dan rathbun said:
Module syntax is NOT clutter. If you (speaking generally to all readers and especially newbies,) do not understand the importance of modules, then you do not understand how Ruby operates and how code is (and should be,) loaded.
Modules separate your code from other people's code, and prevent your code from "crapping" on the ObjectSpace (which is the same as "crapping" on everyone else's modules and classes, including Google's and Ruby's.) ANY script that defines methods, instance variables, class variables or constants in the ObjectSpace IS "crap." It does not matter if Google did it in their examples, it is still "crap."
NO CRAP Dan! Don't lecture me about the fundamentals of modules and namespaces. I know first hand the importance of modules. For without them, we would have so many name clashes that nobody could write code that did not blow chunks! The API would fall apart.
What i am referring to is the fact that Ruby makes you explicitly define module namespace! Wrapping up namespaces between syntax is a complete waste of time WHEN Ruby should create the module from each separate file -- like Python does! Python handles this so much more beautifully.
In Python, a programmer creates a module simply by writing code in a file. THE FILE WILL THEN BECOME THE MODULE. Do you see the beauty of such a system Dan? Even if you write toplevel code in the file (psst: thats a module Dan!) it does not matter. The code will be insulated from the global namespace by the module's namespace (psst: thats the file Dan!). And guess what else Dan...the FILE NAME then becomes the MODULE NAME. Woohoo! No need for more redundant syntax like Ruby forces on the programmer!
Ruby's modules are a monkey patch because Matz did not think far enough ahead when designing Ruby. Then he had to pull a "rabbit-out-of-his-hat" and came up with this module...code...end monkey business.
In Python, when we want to bring in all the names of a module we use the **from module import *** -- That means import everything. It's very much the same as what Ruby does with require HOWEVER, python gives you even more leverage with the from module import name1, name2, ..., nameN. With this statement you can choose to only bring in a few names and not the whole polluting shebang! But thats not all Dan, oh no, you can even import names and give them alias's right on the spot with the syntax from module import X as _X, y as WhyAskWhy, .... You see Dan Python is a far better choice for any scripting environment. Python was built with this very thing in mind from day one.
@dan rathbun said:
Not only should you be using A module around your script... you should be using nested modules. The outermost is your TOP_LEVEL namespace, Ex(using your SCF screenname):
module JesseJames
Any tool or plugin you create should be in a nested module (submodule,) of your TOP_LEVEL namespace. This allows individual tools or plugins to be removed from memory when they are no longer being used. TOP_LEVEL modules and classes can NOT be removed (by design.) This means the standard Ruby modules and classes, and Google's Sketchup, UI and Geom modules are safe. It also means a malicous coder cannot remove YOUR top level namespace. (It also means Google incorrectly put their modules at the toplevel, when they should have been within module Google. What happens in the future when Layout gets an API, and/or Picasa gets a Ruby API that integrates to Sketchup and Layout?)Sadly all this nonsense would be unnecessary if we would adopt Python. Then we could concentrate on actually writing the meat and potatoes of our software instead of constantly worrying about name clashes from a scripting language with a piss poor design philosophy! Ruby is good for personal use and not much else.
@dan rathbun said:
Back to indenting... anticpating a chorus of whiney voices, thus:
Thanks for showing the class about how to maintain proper indention whist keeping the left margin minimal. This was a great and informative piece of text that should be posted some where were all can see and learn from.
@dan rathbun said:
Let's save Ruby vs Python for another topic thread, but for now, let me say in regard to your statement:
@jessejames said:...it would be more elegant to use the file as the module (like Python does)..
that this CAN be done in Ruby using the wrap parameter of the load method. However it is simplistic and lacks control. The script is loaded into a temporary Anonymous namespace (module,) that is removed from memory when the script ends. So the important lesson here is the lack of controlling the namespace(s) under which the code runs, as well as controlling the persistance of the objects the code may create. Your just better off wrapping the code the namespace(s) ie, modules of your choice, to begin with.Well i agree there is not much we can do. Our hands are tied. And not only with extending and patching this API, but also with the Ruby language proper as it too is boxing us in. We are basically surrounded on all sides by asininity and there seems to be no way out of this mess. Well, there is a way but trying to convince Ruby religious fanatics around here that greener pastures exists is almost a fruitless endeavor.
@dan rathbun said:
I have been tempted to write a Toilet plugin...<snip>...(And yes Google broke that rule in a few places, but it does not negate the rule. Example: The custom Sketchup Set class is defined at the top level, instead of as Sketchup::Set, and will clash with Ruby's standard Set class, if you load the latter.)
Ah yes. When the gods lead by bad example then the lemmings will follow them strait off the cliff. We need to do something about this mess Dan. You seem to be a smart, professional minded programmer. We need to get together, have a few beers, and discuss a battle plan for retaking this lost ship.
Currently SketchUp scripting is a captain-less ship left to the sport of every hacks whim. Someone needs to step in and lead by example. Rule with an iron fist, and kick some major butt around here. In times like these it takes drastic measures to bring about drastic changes. But in the end we will set sail on calmer seas. And graze on greener pastures.
-
@thomthom said:
@dan rathbun said:
I'm thinking the world needs a TRUE OpenSource 3D Modeling Application Project that supports multiple scripting engines (Ruby, Python and OpenBasic,) to name a few.
Blender? Might not support multiple languages - but it's fully open source.
Blender is a great open source environment for organic modeling, rendering, animation, and more. However for architectural stuff it sucks. And the people who are in charge of Blender have no plans to change that -- believe me i know! Blender is good complement to SketchUp but it will never be anything even close to a replacement for SketchUp.
PS: Blender has the most bone headed UI every created! This is one of the reasons it will only be a niche toy for a very small group of Blender heads.
-
Sounds like its time for me to start encoding my scripts so Jesse will stop trying to read it.
@Dan - the double wrapping thing sounds excessive, unless it is true that you say it makes it so SU can unload tools or modules from memmory when they are not being used? If that is true, then I think I'll jump on your double wrapping bandwagon. I have only done a limited amount of reading on Ruby and never seen that mentioned, but I have not read very much in depth info like that.
@Thom, your not lazy. Jesse just likes to tell others they are lazy so they forget to notice that he does not actually do anything more than rant.
@Jesse, leading by example 'eh? Where is the goods? How many freeware scripts have you cleaned up? Leading by example means doing something good, and others will see and follow allong because they believe in your cause. So far I just feel like you show up to yell at the regulars. Thats not nice.
-
@chris fullmer said:
Sounds like its time for me to start encoding my scripts so Jesse will stop trying to read it.
No need because since your scripts are hosted at the site that promotes corporate greed and selfishness i would never pollute my eyes with the contents of them anyway. And anybody who does is only supporting and giving reason for such a sites existence, sadly though i don't think many realize the contract that they bind themselves into by downloading these scripts.
@chris fullmer said:
@Jesse, leading by example 'eh? Where is the goods? Leading by example means doing something good
And where is your good examples "pot"? Sure you have scripts but are they written in good style. Do they promote proper coding practices or simply contribute to the collective laziness that seems so pervasive around here.
-
Watch it Jesse - behave yourself. You will get nowhere fast with this attitude.
Chris has a very good point: where are your examples? Where is the work you have done for the community?
If you really want to be helpful and guide people - then start producing something yourself. Provide a starting point of what you want to achieve - then you might get people listening.
Right now, and given your history, I can't help but feel that you are trolling and have no intention do any other than that. I really hope you are not one of these people that are entertained by starting quarrels.
-
@thomthom said:
Watch it Jesse - behave yourself. You will get nowhere fast with this attitude.
What attitude?
@thomthom said:
Chris has a very good point: where are your examples? Where is the work you have done for the community?
Don't try to discredit me by questioning my resolve ThomThom. I have been preaching freedom to slaves on this list for ~1.5 years. I have been trying to open your minds to new possibilities, out of the box thinking styles, clean coding styles, better API, better languages, etc, etc. But most importantly i have tried to bring freedom to the slave mindset around here.
@thomthom said:
If you really want to be helpful and guide people - then start producing something yourself. Provide a starting point of what you want to achieve - then you might get people listening.
Sure i want to help, but with all the negative energy why should i? Instead trying so hard to discredit me, how about saying Yes, i would like to help keep the code base clean and written in a proper style. Yes i would like to make the API better. Yes i would like to make the Docs better.
@thomthom said:
Right now, and given your history, I can't help but feel that you are trolling and have no intention do any other than that. I really hope you are not one of these people that are entertained by starting quarrels.
I can't believe you would call ME a troll. All i have ever done was come here to help. Givin out my spare time and for what? Just because you don't agree with my statements does not mean i am a troll.
Advertisement