r/Python • • Mar 07 '17

CIA uses Python (a lot)

From the latest Vault 7 leaks from Wikileaks, we can see that CIA uses a lot of Python in its secret hacking tools.

Most notably in the Assassin, Caterpillar, MagicViking and Hornet projects.

Unfortunatelly, no files from these projects have been released yet. But if you look at the dump that was released, there are plenty of .py files, and even PIL is included.

There are even Coding Conventions: https://wikileaks.org/ciav7p1/cms/page_26607631.html

You can see more Python-related stuff here: https://search.wikileaks.org/?query=python&exact_phrase=&any_of=&exclude_words=&document_date_start=&document_date_end=&released_date_start=&released_date_end=&publication_type%5B%5D=51&new_search=False&order_by=most_relevant#results

1.1k Upvotes

220 comments sorted by

View all comments

393

u/Exodus111 Mar 07 '17 edited Mar 08 '17

Global Variables
Avoid global variables.

Thank you CIA.

6

u/Dualblade20 Mar 08 '17

Everyone knows this, though. Why is the CIA hiring people who don't know how to avoid muddling global scope? Maybe it's just a guide and has things like that for completeness, but still it sort of bothers me.

16

u/MereInterest Mar 08 '17

Believe me, not everybody knows this. These are arguments I've heard in favor of using global variables.

  • But I don't want to pass the configuration around to everything that needs it.

  • It's simpler and easier to reason about.

  • I can adjust the value in one place and change the behavior everywhere in the program.

  • We just have to put locks around it, and it will be threadsafe.

  • I can adjust the behavior of something deep within the call stack without needing to change the function signature all the way down.

Now, I know what you're thinking. These aren't actually arguments in favor of global variables. These are many things that are horribly wrong with global variables. That this makes it impossible to reason about code without knowing the runtime state of the problem.

At some point, it is just easier to have a style guide, then use an argument from authority.

1

u/glacierre2 Mar 09 '17

I do OOP, and maintain several serious libs at work.

But I also do some reference implementations in python (to later be translated to C++ in a uC, for example). And then I go full retard on the globals, because I find the clear reading of the example code and the clean functions that get just one/two parameters are more important than robustness.

Of course I still follow two rules:

  • That kind of code is a reference, NEVER production

  • Even then, the globals are to be read in multiple places, like a C #define, NEVER to be altered of used to pass information back an forth.

2

u/MereInterest Mar 09 '17

Absolutely agreed. Reference implementations are one thing, while production implementations are completely different. One for testing out new features, quickly hacking in something that might be gone in 5 minutes, while the other is for reliability.

I would add to your second rule. The value of the globals should be determined solely from the source code. That is, using a #define rather than static const val = read_from_config_file(); I work with a framework that does the latter, and it can result in bugs that only ever appear on one person's machine.