Modules
Imports
- C
- C++
- C#
- Java
- Rust
- Go
- Javascript
- Typescript
- Python
// ------------------------------------
// Imports
// ------------------------------------
#include <stdio.h> // input/output to console
#include <stdlib.h>
#include <string.h>
// File names between <angle brackets> are headers from
// the C standard library.
#include "my_module.h"
#include "path/to/my_module.h"
#include "../path/to/my_module.h"
// For your own headers, use double quotes instead (Convention)
// ------------------------------------
// Imports
// ------------------------------------
// C standard headers are available in C++.
// C headers end in .h, while
// C++ headers have no ".h" suffix.
// C headers in C++ are prefixed with "c" and have no ".h" suffix.
#include <iostream> // input/output to console
#include <cstdio>
#include <string>
// File names between <angle brackets> are headers from
// the C++ (Cpp) standard library.
#include "my_module.h"
#include "path/to/my_module.h"
#include "../path/to/my_module.h"
// For your own headers, use double quotes instead (Convention)
// ------------------------------------
// Imports
// ------------------------------------
using System; // input/output to console
using Alias = System.Console;
// ------------------------------------
// Imports
// ------------------------------------
import java.util.Scanner; // Input
import java.util.ArrayList;
import java.util.*;
// ------------------------------------
// Imports
// ------------------------------------
// No need for input/output library for the console
use std::env
// ------------------------------------
// Imports
// ------------------------------------
package main // input/output to console
import "fmt" // import keyword is used to import packages in your program and fmt package is used to implement formatted Input/Output with functions.
More Info:
// ------------------------------------
// Imports - ECMAScript format
// ------------------------------------
import defaultExport from 'module-name';
import defaultExport from "module-name";
import * as name from "module-name";
import { export1 } from "module-name";
import { export1 as alias1 } from "module-name";
import { export1 , export2 } from "module-name";
import { foo , bar } from "module-name/path/to/specific/un-exported/file";
import { export1 , export2 as alias2 , [...] } from "module-name";
import defaultExport, { export1 [ , [...] ] } from "module-name";
import defaultExport, * as name from "module-name";
import "module-name";
var promise = import("module-name");
// ------------------------------------
// Imports - Browser Specific
// ------------------------------------
<script type="module">
// "Bare" import specifiers aren't currently supported
// You also need the file extension
// Supported:
import defaultExport from 'https://website/module_name.js';
import defaultExport from '/folder/module_name.js';
import defaultExport from './module_name.js';
import defaultExport from '../module_name.js';
// Not supported:
import defaultExport from 'module_name.js';
import defaultExport from 'folder/module_name.js';
// Code Here
</script>
// ------------------------------------
// Imports - Node.js Specific
// ------------------------------------
// Since version 13, node has experimental support (Similar to the Browser)
// If you want to use a ECMAScript format now, you can try a loader like https://www.npmjs.com/package/esm
// "Bare" import specifiers aren't currently supported
// You also need the file extension
// Supported:
import defaultExport from 'https://website/module_name.js';
import defaultExport from '/folder/module_name.js';
import defaultExport from './module_name.js';
import defaultExport from '../module_name.js';
// Not supported:
import defaultExport from 'module_name.js';
import defaultExport from 'folder/module_name.js';
// ------------------------------------
// Imports - Legacy CommonJS format
// ------------------------------------
const package = require('module-name');
const { PI } = Math;
More Info:
// ------------------------------------
// Imports
// ------------------------------------
import defaultExport from "module-name";
import * as name from "module-name";
import { export1 } from "module-name";
import { export1 as alias1 } from "module-name";
import { export1 , export2 } from "module-name";
import { foo , bar } from "module-name/path/to/specific/un-exported/file";
import { export1 , export2 as alias2 , [...] } from "module-name";
import defaultExport, { export1 [ , [...] ] } from "module-name";
import defaultExport, * as name from "module-name";
import "module-name";
let promise = import("module-name");
More Info: https://www.typescriptlang.org/docs/handbook/modules.html
# ------------------------------------
# Imports
# ------------------------------------
import module_name
from module_name import function1 , function2
from module_name import *
import module_name as alias
from module_name import function as alias
import module_name1, module_name2
import folder.subfolder.subfolder.module_folder # "The __init__.py" files are required to make Python treat directories containing the file as packages.
from folder.subfolder.subfolder import module_folder
from folder.subfolder.subfolder import *
from . import relative_module_name
from .. import relative_module_name
from ..module_name import relative_module_name
Exports
- C
- C++
- C#
- Java
- Rust
- Go
- Javascript
- Typescript
- Python
// ------------------------------------
// Exports
// ------------------------------------
// Option 1 - Header Guards.
// This notation is just a convention, not the actual file name
#ifndef MY_HEADER_FILE_NAME_H
#define MY_HEADER_FILE_NAME_H
// Code Declarations Here
// This is a header file (.h) the actual code will be
// inside a source file (.c)
#endif
// Option 2 - Pragma
// Same purpose as header guards. However,
// is not an official part of the C/C++ language,
// and not all compilers support it (although most modern compilers do).
#pragma once
// Code Declarations Here
// This is a header file (.h) the actual code will be
// inside a source file (.c)
More Info:
// ------------------------------------
// Exports
// ------------------------------------
// Option 1 - Header Guards.
// This notation is just a convention, not the actual file name
#ifndef MY_HEADER_FILE_NAME_H
#define MY_HEADER_FILE_NAME_H
// Code Declarations Here
// This is a header file (.h) the actual code will be
// inside a source file (.cpp)
#endif
// Option 2 - Pragma
// Same purpose as header guards. However,
// is not an official part of the C/C++ language,
// and not all compilers support it (although most modern compilers do).
#pragma once
// Code Declarations Here
// This is a header file (.h) the actual code will be
// inside a source file (.cpp)
More Info:
// ------------------------------------
// Exports
// ------------------------------------
// Just create a class And import it from another file
public class Calculator
{
public int Sum(int a, int b)
{
return a + b;
}
}
// ------------------------------------
// Exports
// ------------------------------------
// TODO
// ------------------------------------
// Exports
// ------------------------------------
// TODO
// ------------------------------------
// Exports
// ------------------------------------
// TODO
More Info:
// ------------------------------------
// Exports - ECMAScript format
// ------------------------------------
// There are two types of exports:
// - Named Exports (Zero or more exports per module)
// - Default Exports (One per module)
// Exporting individual features
export let name1, name2, nameN; // also var, const
export let name1 = name2 = nameN; // also var, const
export function functionName() {}
export class ClassName {}
// Export list
export { name1, name2, nameN };
// Renaming exports
export { variable1 as name1, variable2 as name2, nameN };
// Exporting destructured assignments with renaming
export const { name1, name2: bar } = o;
// Default exports
export default expression;
export default class ClassName {}
export default function () {} // also class, function*
export default function name1() {} // also class, function*
export { name1 as default, … };
// Aggregating modules
export * from …; // does not set the default export
export * as name1 from 'module';
export { name1, name2, …, nameN } from 'module';
export { import1 as name1, import2 as name2, nameN } from 'module';
export { default } from 'module';
// ------------------------------------
// Exports - Legacy CommonJS format
// ------------------------------------
// TODO
More Info:
// ------------------------------------
// Exports
// ------------------------------------
// There are two types of exports:
// - Named Exports (Zero or more exports per module)
// - Default Exports (One per module)
// Exporting individual features
export let name1, name2, nameN; // also var, const
export let name1 = name2 = nameN; // also var, const
export function functionName() {}
export class ClassName {}
// Export list
export { name1, name2, nameN };
// Renaming exports
export { variable1 as name1, variable2 as name2, nameN };
// Exporting destructured assignments with renaming
export const { name1, name2: bar } = o;
// Default exports
export default expression;
export default class ClassName {}
export default function () {} // also class, function*
export default function name1() {} // also class, function*
export { name1 as default, … };
// Aggregating modules
export * from …; // does not set the default export
export * as name1 from 'module';
export { name1, name2, …, nameN } from 'module';
export { import1 as name1, import2 as name2, nameN } from 'module';
export { default } from 'module';
More Info: https://www.typescriptlang.org/docs/handbook/modules.html
# ------------------------------------
# Exports
# ------------------------------------
# No extra code is needed
# Just type your code and import from other files
# BUT you can use the following convention
# Lets say you have the following folder/files
"""
MyModule/
MyModule/__init__.py
MyModule/MyClass.py
MyModule/MyUtil.py
"""
# Import them inside __init__.py
from MyClass import MyClass
from MyUtil import MyUtil
# You can now import them directly from your Module.
from MyModule import MyClass