Nim
Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
Top Related Projects
The Julia Programming Language
The Crystal Programming Language
Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
Odin Programming Language
Elixir is a dynamic, functional language for building scalable and maintainable applications
Quick Overview
Nim is a statically typed, compiled, and efficient programming language that focuses on performance, safety, and concurrency. It is designed to be a pragmatic and powerful alternative to languages like C, C++, and Rust, offering a unique combination of features and a focus on developer productivity.
Pros
- Performance: Nim is designed to be fast and efficient, with a focus on generating high-performance native code.
- Concurrency: Nim has built-in support for concurrency, allowing developers to easily write concurrent and parallel programs.
- Flexibility: Nim is a multi-paradigm language, supporting procedural, object-oriented, and functional programming styles.
- Interoperability: Nim can seamlessly interoperate with C, C++, and other languages, making it easy to integrate with existing codebases.
Cons
- Smaller Community: Compared to more established languages like Python or Java, Nim has a smaller community and ecosystem, which may limit the availability of libraries and resources.
- Steeper Learning Curve: Nim's unique syntax and features can make it more challenging to learn for developers coming from more mainstream languages.
- Limited Tooling: The Nim ecosystem may not have the same level of mature tooling and IDE support as some other languages.
- Niche Adoption: Nim is still a relatively niche language, which may make it harder to find job opportunities or collaborate with other Nim developers.
Code Examples
Here are a few examples of Nim code:
Hello, World!
echo "Hello, World!"
This simple program outputs the classic "Hello, World!" message.
Fibonacci Sequence
proc fib(n: int): int =
if n <= 1:
return n
else:
return (fib(n-1) + fib(n-2))
echo fib(10)
This code defines a recursive function fib
that calculates the nth Fibonacci number, and then calls it with the argument 10
.
Concurrency Example
import asyncdispatch
proc worker(id: int) {.async.} =
echo "Worker ", id, " started"
await sleepAsync(1000)
echo "Worker ", id, " finished"
proc main() {.async.} =
var tasks: seq[Future[void]] = @[]
for i in 0..<5:
tasks.add(worker(i))
await all(tasks)
waitFor main()
This example demonstrates Nim's built-in support for asynchronous programming. The worker
procedure runs asynchronously, and the main
procedure creates and waits for multiple worker tasks to complete.
Getting Started
To get started with Nim, you can follow these steps:
- Download and install the Nim compiler from the official website: https://nim-lang.org/install.html
- Create a new Nim file (e.g.,
example.nim
) and write your first Nim program:
echo "Hello, Nim!"
- Compile and run the program using the Nim compiler:
nim c example.nim
./example
- Explore the Nim documentation and learn more about the language's features, syntax, and standard library: https://nim-lang.org/docs/index.html
- Check out the Nim package manager,
nimble
, to install and manage third-party Nim packages: https://github.com/nim-lang/nimble
That's a quick overview of the Nim programming language and its GitHub repository. Remember, Nim is a powerful and versatile language, and the best way to get started is to dive in and start writing code!
Competitor Comparisons
The Julia Programming Language
Pros of Julia
- Scientific Computing: Julia is designed for high-performance numerical and scientific computing, with a focus on speed, ease of use, and a rich ecosystem of libraries for various scientific domains.
- Dynamic Typing: Julia combines the ease of use and flexibility of dynamic typing with the performance of statically-typed languages, making it a powerful choice for data analysis and prototyping.
- Parallelism and Concurrency: Julia has built-in support for parallel and concurrent programming, allowing for efficient utilization of multi-core systems.
Cons of Julia
- Smaller Community: Compared to Nim, the Julia community is smaller, which may result in fewer available packages and a slower pace of development in some areas.
- Steeper Learning Curve: While Julia is designed to be user-friendly, its combination of dynamic typing, metaprogramming, and advanced features can make it more challenging to learn for beginners, especially those coming from more traditional programming languages.
Code Comparison
Nim:
proc fib(n: int): int =
if n <= 1:
return n
else:
return (fib(n-1) + fib(n-2))
echo fib(10)
Julia:
function fib(n::Int)
if n <= 1
return n
else
return fib(n-1) + fib(n-2)
end
end
println(fib(10))
The Crystal Programming Language
Pros of Crystal
- Crystal has a more expressive and readable syntax compared to Nim, making it more approachable for developers coming from languages like Ruby.
- The Crystal standard library is more comprehensive and includes a wider range of built-in functionality.
- Crystal has a more active and growing community, with a larger number of available libraries and tools.
Cons of Crystal
- Nim has a more mature and stable compiler, with a longer development history and more robust tooling.
- Nim's performance is generally considered to be on par with or better than Crystal's, especially for low-level and systems programming tasks.
- Nim has a more flexible and powerful macro system, allowing for more advanced metaprogramming capabilities.
Code Comparison
Nim:
proc greet(name: string) =
echo "Hello, " & name & "!"
greet("Alice")
Crystal:
def greet(name)
puts "Hello, #{name}!"
end
greet("Alice")
Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
Pros of V
- Simplicity: V aims to be a simple and lightweight language, with a focus on ease of use and readability.
- Performance: V is designed to be fast and efficient, with a focus on performance and low-level control.
- Concurrency: V has built-in support for concurrency, with a focus on simplicity and ease of use.
Cons of V
- Ecosystem: Nim has a larger and more mature ecosystem, with a wider range of libraries and tools available.
- Documentation: Nim has more comprehensive and well-documented language features and standard library.
- Community: Nim has a larger and more active community, with more resources and support available.
Code Comparison
Nim:
proc main() =
echo "Hello, World!"
when isMainModule:
main()
V:
fn main() {
println('Hello, World!')
}
fn main() {
}
General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
Pros of Zig
- Simplicity: Zig is designed to be a simple and straightforward language, with a focus on low-level control and performance.
- Cross-compilation: Zig has excellent cross-compilation capabilities, allowing developers to build for a wide range of platforms and architectures.
- Memory Safety: Zig's design includes features to help prevent common memory-related bugs, such as null pointer dereferences and buffer overflows.
Cons of Zig
- Smaller Community: Compared to Nim, Zig has a smaller and less established community, which may mean fewer available libraries and resources.
- Steeper Learning Curve: Zig's focus on low-level control and performance can make it more challenging for developers coming from higher-level languages.
Code Comparison
Nim:
proc main() =
echo "Hello, World!"
when isMainModule:
main()
Zig:
const std = @import("std");
pub fn main() !void {
std.debug.print("Hello, World!\n", .{});
}
Odin Programming Language
Pros of Odin
- Odin is designed to be a systems programming language, with a focus on performance and low-level control.
- Odin has a simpler and more concise syntax compared to Nim, which can make it easier to learn and use.
- Odin has built-in support for SIMD instructions, which can provide significant performance benefits for certain types of applications.
Cons of Odin
- Odin has a smaller community and ecosystem compared to Nim, with fewer libraries and tools available.
- Odin is a newer language, and may not have the same level of maturity and stability as Nim.
- Odin's focus on systems programming may make it less suitable for certain types of applications, such as web development or data analysis.
Code Comparison
Nim:
proc main() =
echo "Hello, World!"
when isMainModule:
main()
Odin:
main :: proc() {
fmt.println("Hello, World!");
}
main();
Both of these code snippets demonstrate the basic "Hello, World!" program in Nim and Odin, respectively. The Nim version uses a main
procedure and the when isMainModule
block to ensure the program is executed when the file is run as the main module. The Odin version simply defines a main
procedure and calls it directly.
Elixir is a dynamic, functional language for building scalable and maintainable applications
Pros of Elixir
- Concurrency and Scalability: Elixir is built on the Erlang Virtual Machine (BEAM), which provides excellent support for concurrent and distributed systems, making it well-suited for building scalable and fault-tolerant applications.
- Functional Programming: Elixir embraces functional programming principles, which can lead to more expressive and maintainable code.
- Vibrant Community: Elixir has a growing and active community, with a wide range of libraries and tools available to developers.
Cons of Elixir
- Steeper Learning Curve: Elixir's functional programming paradigm and the Erlang ecosystem can have a steeper learning curve compared to more mainstream languages like Nim.
- Smaller Ecosystem: While Elixir's ecosystem is growing, it may not have the same level of third-party libraries and tooling as some other more established languages.
- Performance Overhead: Elixir's focus on concurrency and fault-tolerance can sometimes come with a slight performance overhead compared to lower-level languages like Nim.
Code Comparison
Nim:
proc fib(n: int): int =
if n <= 1:
return n
else:
return (fib(n-1) + fib(n-2))
echo fib(10)
Elixir:
defmodule Fibonacci do
def fib(0), do: 0
def fib(1), do: 1
def fib(n), do: fib(n-1) + fib(n-2)
end
IO.puts Fibonacci.fib(10)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Nim
This repository contains the Nim compiler, Nim's stdlib, tools, and documentation. For more information about Nim, including downloads and documentation for the latest release, check out Nim's website or bleeding edge docs.
Community
- The forum - the best place to ask questions and to discuss Nim.
- #nim IRC Channel (Libera Chat) - a place to discuss Nim in real-time. Also where most development decisions get made.
- Discord - an additional place to discuss Nim in real-time. Most channels there are bridged to IRC.
- Gitter - an additional place to discuss Nim in real-time. There is a bridge between Gitter and the IRC channel.
- Matrix - the main room to discuss Nim in real-time. Matrix space contains a list of rooms, most of them are bridged to IRC.
- Telegram - an additional place to discuss Nim in real-time. There is the official Telegram channel. Not bridged to IRC.
- Stack Overflow - a popular Q/A site for programming related topics that includes posts about Nim.
- GitHub Wiki - Misc user-contributed content.
Compiling
The compiler currently officially supports the following platform and architecture combinations:
Operating System | Architectures Supported |
---|---|
Windows (Windows XP or greater) | x86 and x86_64 |
Linux (most distributions) | x86, x86_64, ppc64, and armv6l |
Mac OS X (10.04 or greater) | x86, x86_64, ppc64, and Apple Silicon (ARM64) |
More platforms are supported, however, they are not tested regularly and they may not be as stable as the above-listed platforms.
Compiling the Nim compiler is quite straightforward if you follow these steps:
First, the C source of an older version of the Nim compiler is needed to
bootstrap the latest version because the Nim compiler itself is written in the
Nim programming language. Those C sources are available within the
nim-lang/csources_v2
repository.
Next, to build from source you will need:
- A C compiler such as
gcc
5.x/later or an alternative such asclang
,Visual C++
orIntel C++
. It is recommended to usegcc
5.x or later. - Either
git
orwget
to download the needed source repositories. - The
build-essential
package when usinggcc
on Ubuntu (and likely other distros as well). - On Windows MinGW 4.3.0 (GCC 8.10) is the minimum recommended compiler.
- Nim hosts a known working MinGW distribution:
Windows Note: Cygwin and similar POSIX runtime environments are not supported.
Then, if you are on a *nix system or Windows, the following steps should compile
Nim from source using gcc
, git
, and the koch
build tool.
Note: The following commands are for the development version of the compiler. For most users, installing the latest stable version is enough. Check out the installation instructions on the website to do so: https://nim-lang.org/install.html.
For package maintainers: see packaging guidelines.
First, get Nim from GitHub:
git clone https://github.com/nim-lang/Nim.git
cd Nim
Next, run the appropriate build shell script for your platform:
build_all.sh
(Linux, Mac)build_all.bat
(Windows)
Finally, once you have finished the build steps (on Windows, Mac, or Linux) you
should add the bin
directory to your PATH.
See also bootstrapping the compiler.
See also reproducible builds.
Koch
koch
is the build tool used to build various parts of Nim and to generate
documentation and the website, among other things. The koch
tool can also
be used to run the Nim test suite.
Assuming that you added Nim's bin
directory to your PATH, you may execute
the tests using ./koch tests
. The tests take a while to run, but you
can run a subset of tests by specifying a category (for example
./koch tests cat async
).
For more information on the koch
build tool please see the documentation
within the doc/koch.md file.
Nimble
nimble
is Nim's package manager. To learn more about it, see the
nim-lang/nimble
repository.
Contributors
This project exists thanks to all the people who contribute.
Contributing
See detailed contributing guidelines. We welcome all contributions to Nim regardless of how small or large they are. Everything from spelling fixes to new modules to be included in the standard library are welcomed and appreciated. Before you start contributing, you should familiarize yourself with the following repository structure:
bin/
,build/
- these directories are empty, but are used when Nim is built.compiler/
- the compiler source code. Also includes plugins withincompiler/plugins
.nimsuggest
- the nimsuggest tool that previously lived in thenim-lang/nimsuggest
repository.config/
- the configuration for the compiler and documentation generator.doc/
- the documentation files in reStructuredText format.lib/
- the standard library, including:pure/
- modules in the standard library written in pure Nim.impure/
- modules in the standard library written in pure Nim with dependencies written in other languages.wrappers/
- modules that wrap dependencies written in other languages.
tests/
- contains categorized tests for the compiler and standard library.tools/
- the tools includingniminst
(mostly invoked viakoch
).koch.nim
- the tool used to bootstrap Nim, generate C sources, build the website, and generate the documentation.
If you are not familiar with making a pull request using GitHub and/or git, please read this guide.
Ideally, you should make sure that all tests pass before submitting a pull request.
However, if you are short on time, you can just run the tests specific to your
changes by only running the corresponding categories of tests. CI verifies
that all tests pass before allowing the pull request to be accepted, so only
running specific tests should be harmless.
Integration tests should go in tests/untestable
.
If you're looking for ways to contribute, please look at our issue tracker.
There are always plenty of issues labeled Easy
; these should
be a good starting point for an initial contribution to Nim.
You can also help with the development of Nim by making donations. Donations can be made using:
If you have any questions feel free to submit a question on the Nim forum, or via IRC on the #nim channel.
Backers
Thank you to all our backers! [Become a backer]
Sponsors
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]
You can also see a list of all our sponsors/backers from various payment services on the sponsors page of our website.
License
The compiler and the standard library are licensed under the MIT license, except for some modules which explicitly state otherwise. As a result, you may use any compatible license (essentially any license) for your own programs developed with Nim. You are explicitly permitted to develop commercial applications using Nim.
Please read the copying.txt file for more details.
Copyright © 2006-2024 Andreas Rumpf, all rights reserved.
Top Related Projects
The Julia Programming Language
The Crystal Programming Language
Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
Odin Programming Language
Elixir is a dynamic, functional language for building scalable and maintainable applications
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot