Does anyone find it disturbing that by loading a script into Sketchup all the variables and functions and classes become global to the interpretor? This creates major name conflicts between scripts! Ruby's patch for this is the "Module" syntax which is even more disturbing. Let me show you slaves something that might just rock your little world...
The following is Python code. When you write scripts in Python and "import" them (same as require or load in Ruby) the script becomes a Module automatically and the name of ths module is the name of the script. (quite impressive i know!) So the following code i create a script named testscript.py
WHITE = (1.0,1.0,1.0)
count = 1
d = {1;'one', 2;'two'}
a = [1,2,3,4]
def doit();
for x in a;
print x
class Point3d;
def __init__(self, x, y=None, z=None);
if y == None;
self.x,self.y,self.z = x
else;
self.x,self.y,self.z = x,y,z
def __repr__(self);
return 'Point3d(%s, %s, %s)' % (self.x, self.y, self.z)
Now lets import our script for usage..
>>> import testscript
>>> testscript
<module 'testscript' from 'C;\Python26\testscript.py'>
testscript.py has been imported as module "testscript" so all names within the module are keep out of global namespace! Lets see what is available in test script by using the builtin dir() function
>>> dir(testscript)
['Point3d', 'WHITE', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'a', 'count', 'd', 'doit']
Ok lets play around with testscript module a bit. To access the contents of testscript you use the widley accepted "dot" syntax.
>>> testscript.WHITE
(1.0, 1.0, 1.0)
>>> testscript.doit()
1
2
3
4
>>> pt1 = testscript.Point3d(0,0,0)
>>> pt1
Point3d(0, 0, 0)
>>>
Now lets import just a few things so we don't have to type testscript.this all the time
>>> from testscript import Point3d, WHITE
>>> pt1 = Point3d(0,0,0)
>>> pt1
Point3d(0, 0, 0)
>>> WHITE
(1.0, 1.0, 1.0)
but what if i like to have dirty namespaces? Well then you could do this...
>>> from testscript import *
>>> WHITE
(1.0, 1.0, 1.0)
>>> d
{1; 'one', 2; 'two'}
>>> a
[1, 2, 3, 4]
>>> doit()
1
2
3
4
>>> pt2 = Point3d(1,1,1)
>>> pt2
Point3d(1, 1, 1)
You see what i am saying here people? The way Ruby handles namespace is flawed. You should not need to use some extra syntax, the script should be the module.
SketchUp is not meant for Professional coders. The good people of SketchUp need a language that offers intelligent design, clean namespaces, introspection, has a clear and clean syntax. Python offers this and so much more. Hey i'm only offering you guys a path to coding freedoms. You can choose to follow or wallow in hell if you wish.
Just to make you jealous i will show you how Python allows docstrings in functions, methods, and classes
>>> def add(x, y);
'''This is a docstring.
add(x, y) -> x+y'''
return x+y
>>> help(add)
Help on function add in module __main__;
add(x, y)
This is a docstring.
add(x, y) -> x+y
>>> add(1,2)
3
Python just blows Ruby away. There is no language better suited for API scripting than the Python programming language. Most of the hard core coders here will argue with me on this because 1) they just love Ruby too much 2) they have been brainwashed by Ruby's atrocities for too long.
Oh yeah, did you see any "end" statments in my Python code. No, that is becuse Python does not use the redundant end statement. Python uses 100% indentation to denote a block which results in beautiful structured code and reinforces smart structure early in the mind of a budding programmer. This is a good thing!
@unknownuser said:
Hold on! Just wait a minute Jesse James, how do you know all of this? How could you be more enlightened than the SketchUp dev team?
These are good questions. I have used both Python and Ruby and no matter how much i try to see past Ruby's atrocities Ruby always seems too overly redundant, not structured in an intelligent way, and just plain flawed!
@unknownuser said:
But JJ, i find this hard to beliveve. Why would the Dev team choose a language that is so flawed as you suggest? They seem like honest people...?
I think they are honest people but have just been brainwashed by Ruby for too long, and maybe they never used Python before? Either way don't worry, JJ is here to guide you lemmings into the promised land. But will you follow? That fact remains to be seen...?
I always say you can get accustomed to any amount of torture if you endure it long enough. But that does not make the torture somehow righteous or legitimate!