Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Nim LT
Search
medy
July 01, 2021
Technology
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Nim LT
Nimって何?っていう紹介
medy
July 01, 2021
Transcript
45 slides
Nimについて 発表者: medy (@dumblepytech1)
Nimって何よ? 2008年から開発が始まった新しいプログラミング言語 GoやRustが競合です
Nimの何が良いの? アジェンダ 1. 速い 2. 軽い 3. 書きやすく読みやすい 4. 整った環境
5. どこでも動く 6. C言語と連携が簡単 7. 何でもできる 8. 私がNimで作ったライブラリ
速い
Nimはコンパイルすると最適化されたC言語を出力し、C言語をgccや clangを使ってバイナリにコンパイルします。 Nim→C言語→実行可能バイナリ Nimの実行速度≒C言語の実行速度
軽い
C言語を「最適化」してコンパイルするので、バイナリを非常に小さくでき ます。
動的型付き言語であるPHP、 JavaScript、Python、Rubyより速く、C 言語、Go、Rustと遜色ないパフォーマン スなことがわかります。 メモリ消費もGoよりも少ないことがわか ります。 https://github.com/frol/completely- unscientific-benchmarks
Webフレームワークで比較 NimのJesterというフレームワークは圧倒的爆速です
書きやすく読みやすい
フィボナッチ数列の例 proc fib(n: int): int = if n < 2:
return n else: return fib(n - 1) + fib(n - 2) echo(fib(30))
FizzBuzzの例 let n = 600_000 for i in 1..n: if
i mod 3 == 0 and i mod 5 == 0: echo "FizzBuzz" elif i mod 3 == 0: echo "Fizz" elif i mod 5 == 0: echo "Buzz" else: echo i
GoやRustのようにmain関数は不要 ファイルにズラズラ書けばそれで動く Pythonのようなオフサイドルールで読みやすい!
UFCS 関数の第一引数を前に持ってきてメソッドチェーンのようにできる記法 これによってオブジェクト指向のメソッドを表現する D言語から取り入れられた機能
type Customer = ref object name: string email: string proc
getName(self:Customer):string = return self.name let taro = Customer(name: "taro") echo taro.getName() >> "taro" echo getName(taro) >> "taro" ライブラリ内の独自の型に対してメソッドを後から追加できる
JSONパースが楽 import json, os # ファイルを開く let file = readFile("./file.json")
# 文字列をJsonNode型に変換 let node = file.parseJson echo node >> {"key1":{"id":20,"name":"takahashi"},"key2":["val1","val2"]} echo node["key1"]["id"].getInt >> 20 echo node["key1"]["name"].getStr >> "takahashi" echo node["key2"] >> ["val1","val2"]
# key1に要素を追加 node["key1"]["email"] = %"
[email protected]
" echo node["key1"]["email"].getStr >> "
[email protected]
" #
key2に要素を追加 node["key2"].add(%"val3") echo node["key2"] >> ["val1","val2","val3"] Goのように構造体を用意する必要がない 動的型付け言語の連想配列ようにJSONを扱うことができる
整った環境
環境構築 https://github.com/dom96/choosenim
MacOS、Linuxなら1行で環境構築が完了 curl https://nim-lang.org/choosenim/init.sh -sSf | sh WindowsでもGithubのリリースページからZipをダウンロードし 解凍して中の runme.bat を実行するだけ
もちろんDockerイメージもDockerhubにあります
標準ライブラリ 標準ライブラリの全ての関数とサンプ ル、型一覧や関数の引数の型は何かが まとめられている Pythonの「battery included」の思想を 受け継いでおり、めちゃくちゃ標準ライブ ラリが豊富
外部ライブラリ 検索すればライブラリが見つかる nimble install コマンドでインストールできる( npm install みたいな) https://nimble.directory
VSCodeの拡張機能 シンタックスハイライト 補完 マウスオーバーで関数定義の表示 定義元ジャンプ
どこでも動く
Windows
Android
iOS
Nintendo Switch
IoT http://mpu.seesaa.net/article/463328035.html
C言語と連携が簡単
各OS毎のdllやsoファイルをロードして when defined(nimHasStyleChecks): {.push styleChecks: off.} when defined(windows): const dllName
= "libpq.dll" elif defined(macosx): const dllName = "libpq.dylib" else: const dllName = "libpq.so(.5|)"
C言語のドキュメント通りに関数定義作れば、 C言語の関数をNimから呼べる PPGconn* = ptr PGconn PPGresult* = ptr PGresult
proc pqexec*(conn: PPGconn, query: cstring): PPGresult{.cdecl, dynlib: dllName, importc: "PQexec".}
何でもできる
Web https://github.com/dom96/jester
デスクトップアプリ https://github.com/status-im/status-desktop
2Dゲーム https://vladar4.github.io/nimgame2/
3Dゲーム https://github.com/pragmagic/godot- nim https://qiita.com/NabeKz/items/f952e 43d7807935734d0
コンテナエンジン https://github.com/fox0430/nicoru
OS https://twitter.com/uchan_nos/status/1359014828090683393
私がNimで作ったライブラリ
Basolato LaravelライクなフルスタックWebフレー ムワーク
allographer Laravelライクなクエリビルダ
interface-implements Nimで インターフェースの実装 を表現でき るようになるライブラリ
最後に
今日のスライドはMarpというVSCodeの拡張機能を使って、マークダウンで作りました。 おすすめです。
More Decks by medy
See All by medy
Nimで静的ファイルサーバーを作る
dumblepy
0
270
stapy79_Pythonistaに伝えたいNimの魅力
dumblepy
0
520
Masonote hands On in Tokyo Japan
dumblepy
0
150
Other Decks in Technology
See All in Technology
メルカリの小規模チーム「Pod」で、 エンジニアがデータアナリストなしで、 AIを使ってデータ分析の自走を目指す取り組み
jackojacko_
1
400
AIエージェントの認証がまとめて進化! ~pre:Inventで来た3つのアップデート~
minorun365
PRO
0
140
OWASP AI Agentic Top10に準拠するクラウドネイティブなガードレールの実践(CNDW 2026)
keitah
1
460
正しくWeb サイトを守るためのコンテンツセキュリティーポリシー
hinalin
0
850
Terraform 0 to 100:100個以上のリポジトリを常に最新にし続けるための自動化
sue445
3
1.5k
AWS AIB 受験体験記!~練習問題を AI に作らせてみて感じたこと~
ysuzuki
0
110
Web Performance Is a Journey [PerfNow 2026]
tammyeverts
3
190
Is the Website Dying?
miriamschwab
0
280
【Oracle AI SPOTLIGHT ウェビナー】AI時代、狙われるデータと止められない業務をどう守るか?
oracle4engineer
PRO
1
170
認知負荷の減らし方 ~開発にも日常業務にも活かせるノウハウ~
minorun365
PRO
20
20k
PMの私の 最近のAgent Skills活用法
haru860
0
110
全てを疑え!非自明な挙動と異常系から考える堅牢なカスタムコントローラ開発入門(CNDW2026)
lycorptech_jp
PRO
0
120
Featured
See All Featured
Tell your own story through comics
letsgokoyo
1
1.1k
WENDY [Excerpt]
tessaabrams
15
41k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
550
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
The Cost Of JavaScript in 2023
addyosmani
56
10k
Speed Design
sergeychernyshev
33
2.3k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
480
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.6k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.8k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.2k
Test your architecture with Archunit
thirion
2
2.5k