# Version 1.0 released of Nim Programming Language

**URL:** https://discourse.julialang.org/t/version-1-0-released-of-nim-programming-language/29099
**Category:** Offtopic
**Created:** [September 24, 2019, 2:48am UTC](https://discourse.julialang.org/t/version-1-0-released-of-nim-programming-language/29099 "2019-09-24T02:48:42Z")
**Posts on this page:** 5
**Page:** 7

<div class="post-metadata">

### Author: ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)
#### Post date: [October 4, 2019, 4:46pm UTC](https://discourse.julialang.org/t/version-1-0-released-of-nim-programming-language/29099/121 "2019-10-04T16:46:34Z")

</div>

> [@Mason](#):
>
> It’s pretty frustrating if you have to wait the full 100 seconds just to get an error from `f("hi")` .

A variation on this problem

```julia
if not error
  println(answer)
else
  println(err_mse)
end

```

oops i mispelled, “err\_msg”, but I don’t find out about it until i actually hit that else statement. I HATE THAT. This was my #1 source of bugs in python code. Seldom executed else clauses would throw errors after the program had run for 1/2 hour. It made python really sketchy for large scale projects (I have no idea how people can write reliable 10,000 line python programs).

And no, I don’t think I should run a test case for this _because the variable doesn’t exist_ and the compiler should tell me that. How can Julia possibly do all this work on method matching and type dispatching and when it gets all said and done, and that variable is not defined ANYWHERE, comes back and says : yeah- ur gud to go. Yes I know there are probably very good reasons for it, but it sure is unintuitive.

Now it’s a substantial source of julia bugs. Yes, it does makes me wonder what happens in large scale julia programs. “My program has been running for 3 days, but just crashed because of a typo in a variable name in an else clause”.

Advantage Nim ?

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [October 4, 2019, 4:53pm UTC](https://discourse.julialang.org/t/version-1-0-released-of-nim-programming-language/29099/122 "2019-10-04T16:53:47Z")

</div>

TDD? Unit tests?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [October 4, 2019, 5:37pm UTC](https://discourse.julialang.org/t/version-1-0-released-of-nim-programming-language/29099/123 "2019-10-04T17:37:24Z")

</div>

> [@purplishrock](#):
>
> . How can Julia possibly do all this work on method matching and type dispatching and when it gets all said and done, and that variable is not defined ANYWHERE, comes back and says : yeah- ur gud to go. Yes I know there are probably very good reasons for it, but it sure is unintuitive.

Just to spell it out but the reason is global variables

```julia
julia> f() = print(x)
f (generic function with 1 method)

julia> f()
ERROR: UndefVarError: x not defined
Stacktrace:
 [1] f() at ./REPL[1]:1
 [2] top-level scope at REPL[2]:1

julia> x = "hello"
"hello"

julia> f()
hello

```

The VSCode linter is (was) pretty good at finding these.

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [October 4, 2019, 5:46pm UTC](https://discourse.julialang.org/t/version-1-0-released-of-nim-programming-language/29099/124 "2019-10-04T17:46:53Z")

</div>

> [@purplishrock](#):
>
> oops i mispelled, “err\_msg”, but I don’t find out about it until i actually hit that else statement. I HATE THAT. This was my #1 source of bugs in python code. Seldom executed else clauses would throw errors after the program had run for 1/2 hour. It made python really sketchy for large scale projects (I have no idea how people can write reliable 10,000 line python programs).
> 
> And no, I don’t think I should run a test case for this _because the variable doesn’t exist_ and the compiler should tell me that. How can Julia possibly do all this work on method matching and type dispatching and when it gets all said and done, and that variable is not defined ANYWHERE, comes back and says : yeah- ur gud to go. Yes I know there are probably very good reasons for it, but it sure is unintuitive.

The problem is that if I define `err_mse = "boo!"` in an enclosing scope then the variable _can_ exist even if it wasn’t defined in the function body itself and there is no way to statically guarantee that it won’t exist until you actually run the program and try to evaluate `println(err_mse)`. You can restrict the language so that such a thing is not possible, but you are left with a strictly less expressive language. For some that’s an advantage for others, it’s a pain in the neck.

Julia so far has been concerned with offering as much dynamism as it can possibly offer without sacrificing performance. There hasn’t yet been a serious emphasis in julia’s development on restricting dynamism for the purposes of catching bugs. Instead, the community so far seems to mostly agree that robust test suites are the answer since actual runtime tests can catch strictly more bugs than compile time analysis (you have access to types _and_ values instead of just types).

That said, I think julia is in a really cool position because it has such powerful reflection and introspection capabilities, I think there’s definitely room for a system of packages built around making compile time restrictions on julia code so that you can tape off a section of your code base and demand it satisfies a list of static guarantees, such as having a frozen, untouchable method table, no runtime eval, no dynamic dispatch, etc.

* * *

I played around with a macro and found a (brittle and unpolished) way of warning you at macro expansion time if you’re defining a function with unassigned symbols in it.

```julia
using MacroTools: splitdef, prewalk, @capture 

strip_args(ex::Expr) = (ex.head == :(::) || ex.head == :(=)) ? ex.args[1] : ex
strip_args(s) = s

macro check_names(fdef)
    d = splitdef(fdef)
    assigned_names = Vector{Symbol}(strip_args.(d[:args]))
    prewalk(d[:body]) do x
        @capture(x, name_ = val_) && push!(assigned_names, name)
        if x isa Symbol && !isdefined( __module__ , x) && !(x ∈ assigned_names)
            @warn "Symbol $x not defined at function definition time." 
        end
        x
    end
    fdef        
end

```

Now if we apply this macro to a function definition with your problematic piece of code, we get a warning:

```julia
julia> @check_names function foo(error::Bool)
           answer = 10
           error_msg = "hi"
           if !error
               println(answer)
           else
               println(err_mse)
           end
       end
┌ Warning: Symbol err_mse not defined at function definition time.
└ @ Main REPL[4]:8
foo (generic function with 1 method)

```

In general though, this is just something a linter should be doing on your whole code base. It doesn’t really need to be enforced by a compiler.

---

<div class="post-metadata">

### Author: ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)
#### Post date: [October 4, 2019, 6:09pm UTC](https://discourse.julialang.org/t/version-1-0-released-of-nim-programming-language/29099/125 "2019-10-04T18:09:56Z")

</div>

> [@Mason](#):
>
> the community so far seems to mostly agree that robust test suites are the answer

Petr, of the community, agrees with you, 🙂

> [@PetrKryslUCSD](#):
>
> TDD? Unit tests?

yes well, that’s a longer conversation about when I need to write tests and depends on what kind of code i’m writing (i’m referring to the extent of testing - i’m always testing whether i like it or not 😉 . I think we can agree that the compiler catching a typo is preferable to devising a run-time test to catch a typo, or can we ?

> [@kristoffer.carlsson](#):
>
> Just to spell it out but the reason is global variables

So, trade-offs, trade-offs. Ever the problem…  
Looking at a C program, if the variable is not declared, ERROR. Therefore,

```julia
global varname :: T

```

as a requirement means a global has to be declared and problem solved, right ? However, by the theorem of “simple and wrong”, it’s not that easy, or it would have been done. 🤔

I believe i’m taking the off-topic thread, off-topic. I’ll stop now.

A compiler that doesn’t catch typos aside, I love Julia, and I think Nim is pretty neat too. I thought CLOS was the greatest thing ever, and I was always a fan of macros, so discovering Julia (back at 0.48) and seeing that it incorporated those kind of things sure was exciting 😃 I’ve been using it ever since. in my little corner of the world it’s a bit of a tough sell, because Matlab. But that’s a different off-topic thread.

[Previous page](https://discourse.julialang.org/t/version-1-0-released-of-nim-programming-language/29099.md?page=6)
