Editing your Algorithm

When you first create your Algorithm, you'll see a popup which provides the option of cloning your code down to a local machine, using either our CLI or Git. It also provides the option of using our Web IDE, which we'll use in this lesson because it has some additional important features.

You can even do both: clone the code down, edit with your favorite IDE and commit changes, then jump over to the Web IDE while you're travelling. Just don't do both at the same time... if you pushed code via Git while the Web IDE was open, reload the page to get the latest copy.

If you're coming back to an existing Algorithm, or if you accidentally closed the popup, no worries: you can get the Git url again on the "Manage" tab of your Algorithm's page, or you can open the Web IDE by clicking the "Source" tab.

In the Web IDE, your files are listed on the left, and the code you're editing is on the right. Note that there's already some boilerplate code in your Algorithm: click the Build button in the upper-right, and wait for it to finish (you'll see a message "Algorithm version ... is now online").

Next, click in the Console at the bottom of the page and type something simple, like "world" (including the quotes). You should get back a "hello world" response in most cases (some of the packageset-specific code templates may be more complex). The input you typed into the console was automatically sent to the "apply" method of your code, and the result returned from that function was printed to the console output.

You can write any code you like, but there is one requirement: the "apply" function must remain, and can take only a single parameter. This is the starting point for your Algorithm; any call to it will begin at the apply method. The input passed to this method will be an appropriate language-native object, inferred from what the caller sent: for example, if the caller sent a simple piece of text, the input will be a string; if the caller sent a bunch of key-value pairs, then the input will be a dictionary (in Python), a Map (Java), or similar.

Your apply function should return the result want sent back to the caller. This can be any datatype you like; we take care of the JSON serialization and all the other mechanics needed to translate your result into the language that the caller is working in. The only requirement is that the result you return has to be serializable (for example, you can't return a local file pointer; you should instead return the file's contents, or the URL of a file in Hosted Data).

You can bring in new packages/libraries by clicking the "Dependencies" button in the upper-right. The details of these dependencies are language-specific, but in general they work just like your default dependency manager for your language: for example, in Python it is identical to the "requirements.txt" that pip would use.

Continue editing your code, experimenting with your favorite libraries. If you need to step away, click the Save button: this commits your changes. Click Build anytime you want to test your changes in the Console.

When you're ready, click the Publish button to publish your algorithm... but first, you may want to learn how to debug.