Codiga has joined Datadog!

Read the Blog·

Interested in our Static Analysis?

Sign up
← All posts
Khalid Khan Friday, April 22, 2022

How to store and reuse your code snippets?

Share

AUTHOR

Khalid Khan, Developer Relations Engineer

Khalid is the Developer Relations Engineer at Codiga. He is passionate about Software Engineering. Startups and Developer Advocacy. He is also an MLH Coach and Organizer & Member to numerous Hackathons & Developer communities

See all articles

Developers know that repetitive feeling when they need to write the same code or the same kind of command every time. This hinders the productivity of software engineers. This problem of repeating work can be solved by finding or creating code snippets of the reusable code and applying them when needed. So what exactly are these code snippets? Let's find out!

What are code snippets?

To put it simply, a code snippet is a reusable block of code that can be imported when needed. Generally, these code snippets are smaller units of a big codebase. For example, here is a code snippet that gives a React function component.

import React from "react";
import ReactDOM from "react-dom";

const Demo = () => {
  return <h1>Welcome to Codiga</h1>;
};

export default Demo;

How do we store code snippets?

There are various ways you can store a code snippet, either by keeping it in a GitHub repository or can use a smart code snippet manager, like Codiga’s Coding Assistant. Coding Assistant allows you to store and reuse code snippets.

Codiga’s Coding Assistant contains thousands of Smart Code Snippets spanning multiple languages, which are ready to use directly in your IDE to save you valuable time and effort..

Codiga supports Smart Code Snippets, but what exactly are these? Let's find out:

What are Smart Code Snippets?

Searching and using code snippets can be difficult because they lack context and information about how to use them. The snippets available over the internet are just a block of code without any name, description or not even the language they are coded in(of course, that can be understood, but it can be that much harder to find exactly what you are looking for). Additionally, sourcing code snippets online can pose a certain risk, as the blocks of code may be outdated, or worse, defected.

To solve this problem, Codiga has introduced Smart Code Snippets. These are code snippets with additional information in the form of metadata so that they can be used and searched easily. The additional information contains,

  1. Name - one-liner explanation of code
  2. Language - what language they are coded on
  3. Dependencies: what libraries of framework does the snippet depend
  4. The code
  5. Description - Multi-line explanation of what the code does
  6. Keywords: helps to find the snippets for search engine
  7. Tags - List of tags to organize the code snippet

meme for smart code snippets

We also suggest Smart Code Snippets based on your filename, language and libraries used.

So, the question is, does the user have to add all this information? The answer here is no; we have made an engine that will completely automate the majority of the descriptive fields for you. You will just have to add the Smart Code Snippet and let our algorithm do the work for you.

How to add your Smart Code Snippet on the Codiga Hub?

Codiga Coding Assistant hub has a curated list of all available code snippets ready to use.

VS Code screenshot

Well, it is pretty simple to add your Smart Code Snippets from your IDE (With a Codiga extension plugin installed) on Codiga Hub. Just select the code you want to add and right-click --> Create Codiga Recipe. Note that we are right now supported on VS Code and JetBrains. Here is a video explanation of the same.

How to use Smart Code Snippets?

There are two ways we can use a Smart Code Snippet, searching for the code snippet or using the shortcuts; let us see how both are done;

First, make sure you have a Codiga plugin installed within your IDE. To search for Smart Code Snippets you have subscribed to on the Codiga Hub and import them into your IDE, press CMD + SHIFT + C on Mac or CTRL + ALT + C on Windows. It will open a search bar where you can search for the desired Smart Code Snippet using keywords. Example: To import react functional components, one would use keywords like react, functional, component, etc.

shortcuts gif

Alternatively, you can use these Smart Code Snippets via shortcuts, so let us see how it's done. Since you all must not be familiar with the shortcuts, here is how you look at the list of shortcuts: press CMD + SHIFT + S for Mac and CTRL+ALT+S for Windows.

Once you are familiar with the shortcuts, you can directly use them directly in your IDE.

Is your code secure?

Yes, Codiga respects code privacy. We are a non- AI-based code assistant; we NEVER store or use your code to train our model. That means your code belongs to you.

Wrapping up

We spend much time in front of the computer screen writing code, fixing bugs, and forgetting about our main job, which is to work on the code logic to make our code work. Writing repetitive code sometimes may become a hectic job and tiring task. Using Smart Code Snippets on Codiga solves this problem and increases the productivity of a developer and the engineering team.

To put it simply, you can write better code faster with Codiga's smart Code Snippets. These Smart Code Snippets have context and additional information to help you quickly find and use code.

Resources

Are you interested in Datadog Static Analysis?

Sign up