Skip to content

Instantly share code, notes, and snippets.

@kornelski
Last active December 24, 2017 09:30
Show Gist options
  • Save kornelski/0f7ebcec230117ab52c959fe0b090335 to your computer and use it in GitHub Desktop.
Save kornelski/0f7ebcec230117ab52c959fe0b090335 to your computer and use it in GitHub Desktop.
Language Adding files from filesystem to the build How? Unfinished files break the program?
Rust Explicit mod declaration No
CommonJS Explicit require import No
ES6 Explicit import import No
Python Explicit import import No
Lua (new) Explicit require import No
PHP Explicit require or use via autoload import or any use No
Perl Explicit use import No
D Explicit import import No
R Explicit import import No
Ocaml Explicit open import No
Swift Implicit in the language, explicit in the IDE Files are added via IDE Depends — it's possible to add files without compiling them
Java Explicit import (but IDE's may write imports automatically) import No, unless IDE auto-adds them
Go Implicit automatic Yes
C# Implicit in the language, explicit in the IDE Via IDE If glob is used in IDE
Ruby Explicit require import No
Visual Basic Implicit Files are added via IDE Yes?
C, C++ Depends on build system/IDE, usually explicit import (headers) + build config Usually not
Clang C++ modules Explicit import import No
Haskell Explicit import import No?
Language Declarations of existence in the parent module Declarations in the module itself Use of the module in the same package Use of the module from another package Notes
Rust mod foo; or
pub mod foo;
pub fn bar(){} mod foo; or
use foo;
extern crate pkg;
use pkg::foo;
CommonJS none exports.bar = function(){} const foo = require('./foo'); const foo = require('pkg/foo');
ES6 none export function bar(){} import foo from './foo'; import foo from 'pkg/foo';
Python none def bar():
  pass
import foo from pkg import foo
Lua (new) none local foo = {}
function foo.bar()
end
return foo
local foo = require "foo" local foo = require "foo"
PHP none namespace Pkg\Foo;
function bar() {}
use Pkg\Foo; use Pkg\Foo;
Perl none package Pkg::Foo;
sub bar {}
use Pkg::Foo; use Pkg::Foo;
D none module pkg.foo; void bar(){} import pkg.foo; import pkg.foo;
R none foo <- module({bar <- function() NULL}) import("foo") import("pkg", "foo")
Ocaml none let bar () = () open Foo #require "pkg";; open Foo
Swift none func bar(){} none import Pkg Packages aren't explicitly divided into modules
Java none package com.example.pkg;
public class Foo{
public static void bar(){}}
import com.example.pkg; import com.example.pkg; Packages aren't explicitly divided into modules
Go none package pkg;
func Bar(){}
none import "pkg"; Packages aren't explicitly divided into modules
C# none namespace pkg {
public static class Foo{
public static void bar(){}}}
optionally using pkg; optionally using pkg; Packages aren't explicitly divided into modules
Ruby none def bar()
end
require_relative 'foo' require 'pkg' Packages aren't explicitly divided into modules
Visual Basic none Namespace Foo
Public Sub Bar()
End Sub
End Namespace
Imports Foo Imports Foo VB also has modules, but they aren't namespaced
C none
(headers tho)
void bar() {} #include "foo.h" #include <pkg/foo.h> Not real modules
C++ none
(headers tho)
namespace foo {void bar() {}} #include "foo.h" #include <pkg/foo.h> Not real modules
ObjC 2 none
(modulemap tho)
void bar() {} #include "foo.h" @import pkg.foo Only used by Apple?
Clang C++ modules none
(modulemap tho)
module pkg.foo; export void bar() {} import pkg.foo import pkg.foo Experimental/working draft
Haskell none module Pkg.Foo(bar) where
bar :: ()
bar = ()
import qualified Pkg.Foo as Foo import qualified Pkg.Foo as Foo
@kornelski
Copy link
Author

@Boddlnagg thanks for the info!

@ahmedcharles I've added extern create with use, because that's how I see it used in practice in projects that have modules themselves. I know you could structure your project to only use crate from one module and/or use full absolute paths to it everywhere, but that would be only to prove a point that you can, rather than representative of how it's done in general.general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment