

Comtypes: How Dropbox learned to stop worrying and love the COM - frsandstone
https://tech.dropbox.com/?p=393

======
snprbob86
COM is a necessary evil when integrating with Windows, Office, Visual Studio,
or any other big/old Microsoft product. That's just _how it works_.

The .NET framework actually does a pretty good job of hiding the complexity
from you, but having done some serious integration with VS, let me say that's
an abstraction leak that I wouldn't wish upon my worse enemy.

~~~
dmethvin
I never thought the .NET Framework did enough complexity hiding to justify a
60MB installed size, especially if it was just providing a bit of plumbing to
get you back down to the COM level.

Most COM interfaces support late binding, so you can easily call them from a
language like JavaScript, which is already installed in Windows as part of the
platform. Ten years before node.js existed, you could run this JavaScript on
Windows 2000 to read and print a file:

    
    
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        if ( fso.FileExists("myfile.txt") ) {
           var ts = fso.OpenTextFile("myfile.txt", ForReading);
           WScript.Echo(ts.ReadAll());
           WScript.Quit(0);
        } else {
           WScript.Echo("File Not Found");
           WScript.Quit(1);
        }

~~~
dguaraglia
Well, that's a facetious argument if I've ever seen one :). .NET does a lot
more than just interface with COM or the Windows API. VB (pre .NET days) had
much better integration with OLE/COM and the runtimes were like 1mb in size at
worst.

I've always thought of COM as one of those almost brilliant pieces of
technology that somehow got completely ignored. Of course, it's still
commonplace in the Windows world, but the concept facilitates reusability so
much, it's a shame it wasn't adopted by other platforms.

~~~
brusch
I think Mozilla used something similar in Firefox:
<https://developer.mozilla.org/en-US/docs/XPCOM>

Other than that I don't know any other companies who did something like COM.

------
achal
Semi related: Not sure how many people have played with PowerShell/COM, but
it's fun to toy with. Haven't used it for anything too useful (yet) but for
example, to delete all the comments in a Word document in a couple lines:

$a = New-Object -com Word.Application

$a.visible = $false

$a.Documents.Open("{absolute path}").DeleteAllComments()

Better examples: [http://www.simple-talk.com/dotnet/.net-tools/com-
automation-...](http://www.simple-talk.com/dotnet/.net-tools/com-automation-
of-office-applications-via-powershell/)

~~~
eckyptang
And this and VBA is why office is so irreplaceable. I wrote a report
generation tool in 1999 with word 97. It picked a report definition off a file
share, assembled documents from fragments on disk (up to 50 pages a pop with
tables, graphs etc) and emailed them or printed them. 2000 documents an hour
on a single Pentium pro 200 with 128mb of ram on NT. It took 2 days to write
and was used until 2009 by 9000 users

This was just word, com and nothing else. Even the application host was an
instance of word.

I doubt it could have been done with anything else then or now.

------
ta12121
Provocative title for a pretty generic article.

1\. Summary of COM, a widely used technology

2\. Summary of comtypes, a python package for interacting with COM

3\. One example of a gotcha they ran into with comtypes and arrays of COM
objects.

Conclusion: meh.

~~~
ejdyksen
How is the title provocative?

~~~
ta12121
The title, "How Dropbox learned to stop worrying and love the COM" is a
reference to the film "Dr. Strangelove or: How I Learned to Stop Worrying and
Love the Bomb". The object taking the place of the atomic bomb in the variant
title is COM. To me this implies that the article will describe why people
worry about COM and why they're wrong. I did not find it to contain either.

Admittedly I have never seen the movie, which wikipedia describes as a "dark
comedy satirizing the nuclear scare". I suspect the article doesn't follow
along those lines either.

~~~
hermannj314
> I have never seen the movie

You should fix that.

In addition, the bomb in question was the result of an ill- conceived Doomsday
device to prevent the use of bombs.

In other words, this title suggests that as part of a policy of mutually
assured destruction, Microsoft created a device to unleash COM if it ever
sensed it was being attacked. They just forgot to tell anyone about the device
(why didn't you tell the world!?!) and now we are all living with the fallout.

------
bugsbunnyak
Am I reading this correctly? they are using comtypes as an exploratory tool,
but the photo upload feature was written in something else...

(I haven't disassembled the dropbox dlls, but there aren't any obvious python
signatures in the install directory)

If the above is wrong, I would love to know what they are using!

~~~
owlishness
No, Dropbox is using Python and comtypes in its actual product.

~~~
bugsbunnyak
Any idea what they are using to package the Python into the exe?

I've tried py2exe and all of the similar packagers that I could find, and
every one of them requires brittle incantations to get everything packaged
(I'm using a lot of graphics and number-crunching code beyond standard python,
but all from the package index). I guess on the scale of Dropbox this is
probably not a big issue. On my scale (1), it's one of the reasons I've
started using C# (an unexpectedly awesome experience so far, btw). I need the
fastest possible path to one-click exe files that non-technical (bio/chem)
researchers and RAs can run. I've belatedly realized that the overhead of
doing this in python is really too high.

[edit: found this SO answer: [http://stackoverflow.com/questions/2678180/how-
does-dropbox-...](http://stackoverflow.com/questions/2678180/how-does-dropbox-
use-python-on-windows-and-os-x) but it doesn't give specifics. In particular,
AFAIK, none of the packagers can eat libpython.dll into a larger exe files]

[edit: interesting - [http://blog.codepainters.com/2012/09/17/python-care-and-
feed...](http://blog.codepainters.com/2012/09/17/python-care-and-feeding-the-
dropbox-way/) ]

~~~
toyg
SharpDevelop and IronPython will give you one-click packaging to exe.
IronPython has a built-in compiler, so really you can use it with any IDE.

IronPython is actually very cool if you want/have to live in .Net Land: it's
mature, simple, and supports Python 2.7.

~~~
duncans
... but an EXE that has a dependency on the .NET runtime

~~~
jrockway
Like every other application on Windows.

~~~
tedunangst
Some people just really, really liked Windows 2000 and they aren't giving up
on it.

------
dpark
> _So, the following code_
    
    
      for i in range(100):
          print idevice_item_array[0]
    

> _actually crashes Python because it creates and destroys a hundred
> IDeviceItem objects, resulting in a hundred calls to Release on the real COM
> object. After the first Release call, the COM object is considered deleted._

This doesn't sound like a "gotcha". It sounds like a huge bug that comtypes
needs to address.

------
tonyedgecombe
If you read Don Box's book on COM he takes you through each part of it
explaining in detail why it is the way it is. Every point is justifiable and
the book is convincing.

However it clearly didn't work as a whole as Microsoft felt the need to
replace it with .Net for application level programmers.

------
cek
_"COM is Love"_ \- Don Box [1]

[1] <http://en.wikipedia.org/wiki/Don_Box>

~~~
mahmud
What do you expect, he wrote _the_ book on it.

~~~
cek
And I wrote the forward to _the_ book on it :-)

