Skip to content

Adding_Snippet

Rasmus Lindahl edited this page Jan 11, 2020 · 6 revisions

Adding a Snippet

This page contains information about Snippets in general and also contains best practices of adding a snippet to the repository. It also explains what to do if one wants to delete or modify an existing Snippet.


What is a Snippet?

A snippet in itself is no new invention. It is a small piece of code capable of accomplishing a specific functionality. A function in a program is similar to Snippets in many aspects though Snippets generally are more modular. One example of a Snippet could, for instance, be a Snippet that calculates the volume of a cylinder. A Snippet in the context of this project has the following attributes:

Function Name

This is the name of the Snippet. This is also the name that will be inserted in the actual code document. An example of a good Snippet name is one that makes the Snippet functionally apparent just from reading the Snippet name. This could, for instance, be convertKilometersToMeters. Another goal is also to not end up with a name that is too long. At the current moment, contributors should use camelCase exclusively in order to keep the repository consistent. Support for other naming conventions might be added in the future.

Tags

Tags are a set of strings separated by a comma. The goal of these are to improve the search results for Snippets. Here is a good place to add alternative ways to write the function name and also more information. A good example could be changeKilometersToMeters, convertKilometerToMeter.

Input Parameters

These are used for creating placeholders in the IDE in order to make it easier for users to understand how to input the parameter values into the function. Multiple input parameters are separated with a comma. An example of this could be kilometerInput. For now, these should also be in camelCase.

Dependencies

This functionality has as of the current time not been implemented and can, therefore, be left as blank for now. This attribute is supposed to contain instructions for the plugin on how to install any external libraries that a Snippet might use. This functionality would, for example, enable the creation of Snippets that have the capability of translating the text into different languages with libraries such as Google Translate. If the Snippet needs multiple dependencies these are separated with commas. An example of this would be pip3 install unitConverter, pip3 install mathLibrary. Each dependency is supposed to mirror how the user would have had installed the library if it was done manually.

Language

This attribute is needed to specify which language the Snippet belongs to. This is used for searching Snippets and by plugins to correctly incorporate the Snippet code into a workspace. The language is chosen from a drop-down list when submitting the Snippet through the repository. More languages might be added in the future.

Description

This attribute contains a brief description that explains to a user what the function does and how it works. This description will be visible in the IDE when browsing through search results. An example description could be:

This function takes a kilometer value as input and returns the same value after changing the unit to meters.

Code

This field contains the actual functionality e.g. the Snippet code. Any imports or libraries can be added to the top of the Snippet code. It is important to make sure that the parameters specified in Input Parameters actually are inputs to the implemented function. An example of a Snippet code written in Python3 could be:

import unitConverter
import mathLibrary

def convertKilometersToMeters(kilometerInput):
    return kilometerInput*1000

How do I add a Snippet?

After having read through the section explaining the functions of a Snippet. Feel free to add one to the repository. After the Snippet has been added it will be accessible immediately. Each Snippet is reviewed which means that it might be deleted if it contains malicious code or does not reach the standards set by the guidelines. If you want to request a deletion or modification to an existing Snippet reach out to us via mail.

Clone this wiki locally