Fireship · @fireship

Nim in 100 Seconds

Uploaded November 3, 2022 · Length 2:35

Nim in 100 Seconds

Summary

Nim language basics, performance, and features in 100 seconds.

  • nim language
  • systems programming
  • statically typed language
  • meta programming

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    Nim a general purpose systems

  2. 0:02

    programming language that can deliver

  3. 0:03

    high performance native apps with

  4. 0:05

    concise elegant code it was created by

  5. 0:08

    Andreas rump in Germany in 2005 who

  6. 0:10

    wanted a language with the performance

  7. 0:12

    of C the productivity of Python and the

  8. 0:14

    extensibility of lisp like other systems

  9. 0:16

    languages Nim is statically typed and

  10. 0:19

    compiled however it's Unique because its

  11. 0:21

    source code is first translated to a

  12. 0:23

    different language usually C then uses a

  13. 0:25

    compiler like clang to convert it to

  14. 0:27

    machine code and it can also transpile

  15. 0:29

    to C plus plus Objective C and even

  16. 0:31

    JavaScript by default it uses a

  17. 0:34

    deterministic memory management strategy

  18. 0:36

    based on reference counting but this

  19. 0:38

    Behavior can be customized or removed

  20. 0:40

    altogether allowing low-level control

  21. 0:42

    over memory with pointers syntactically

  22. 0:44

    it feels like a statically typed python

  23. 0:46

    but it also provides extensive support

  24. 0:48

    for meta programming with a macro system

  25. 0:51

    that allows direct access to the

  26. 0:53

    abstract syntax tree allowing you to

  27. 0:55

    mold the language to your exact needs

  28. 0:56

    much like the list family of languages

  29. 0:58

    to get started install an on your

  30. 1:00

    machine then create a new file ending in

  31. 1:02

    dot Nim unlike C no main function is

  32. 1:04

    necessary use Echo to print to the

  33. 1:06

    standard output or create a variable

  34. 1:08

    with the VAR keyword and follow it with

  35. 1:10

    an optional type annotation variables

  36. 1:12

    can be reassigned but we can make them

  37. 1:14

    single assignment with let or use cons

  38. 1:16

    to make the assigned value immutable

  39. 1:18

    when writing a complex statement like an

  40. 1:21

    if condition indentation matters like

  41. 1:23

    python this keeps the code nice and

  42. 1:24

    readable like when declaring multiple

  43. 1:26

    variables for Loops it has a variety of

  44. 1:29

    built-in iterators like count up and

  45. 1:31

    countdown or you can use the iterator

  46. 1:33

    keyword along with yield to build your

  47. 1:35

    own from scratch to Define functions or

  48. 1:37

    methods we use procedures which can take

  49. 1:39

    input arguments and return a value it

  50. 1:42

    also supports closures and using

  51. 1:43

    procedures as arguments or return values

  52. 1:46

    for functional programming patterns

  53. 1:48

    however it's also possible to use object

  54. 1:50

    oriented patterns by first creating a

  55. 1:52

    complex type which can then be

  56. 1:54

    instantiated like a class and it also

  57. 1:56

    supports generics allowing you to use

  58. 1:58

    types as parameters what makes Nim