What are packages, and how do you use them?
Packages are big collections of code that other people have written that you can use in your own projects. There are a wide variety of packages, and they all have many different functionalities.
On Repl.it, you can go to the Packages tab:
and search for packages there (if that language has package support on here). Should be intuitive enough: search for a package, click on it, and install by clicking the (+) button.
Python uses a package manager called 'pip', which pulls from PyPI (Python Package Index)
You can import packages installed through pip by using
import calendar import time import mycoolpackage
Node and its subvariants use npm (Node Package Manager)
You use the
require() function to import packages:
fs = require('fs'); http = require('http');
Ruby uses RubyGems, Lua uses LuaRocks, .NET uses NuGet, the list goes on and on.
@poetaetoes Poetry help keep track of other packages (like which ones are used and which ones to include in builds). Not all Python projects need it, but Repl.it has it in every Python Repl.
Also, after a while, complex code gets too complicated and using pre-existing code help speed up the process by quite a bit. I couldn't imagine having to code my own JSON interpreter just for a small project.
Before we talk about packages, we first talk about files.
Imagine you had a big project in one file. There would be a lot of components you could export into a different file, so you can just use them as necessary:
import myMethods myMethods.doThis()
# myMethods.py def doThis(): print("idk")
that allows you to reuse code, on a bigger level! Now packages are just like that, except they are published to a global repository so anyone can use them, like
Packages are like extensions you import with a specific code so you can have different codes that the package does. Like, when you add a code that imports color, you get color. Here is for node.js:
const whatYouAreImporting = require('package')
$npm install package
See? Cool, right?