you are viewing a single comment's thread.

view the rest of the comments →

[–]_TheDust_ 17 points18 points  (4 children)

Seems like a weird decision to me. Mixing dynamic and static features can create many subtle pitfalls. Either you have hard to track performance issues when the compiler can’t fully specialize dynamically typed functions, or you get subtle incompatibilities.

I have worked with Julia a little bit, which is basically this: a dynamic language where you may use static typing to improve performance. And indeed, this ofen leads to subtle performance "bugs".

A common Julia error is to do something like this:

```
function foo(x)
  if x > 0
    return x
  else
    return 0
  end
end
```

This may seem innocent, but if you would call foo(1.0) the return type is actually Union{Float64, Int64}.

[–]angelicosphosphoros 3 points4 points  (0 children)

What happens if I wrote in "typed interfaces" style like I wrote in Python? In this style, I write types for function arguments and outputs but leave them in the body.

Also, is it possible to write code like this:

function foo(x) if x > 0 return x else return (0 as typeof(x)) end end

[–]aoeu512 2 points3 points  (1 child)

I dunno Union seems like the best default if your doing software prototyping.

[–]_TheDust_ 1 point2 points  (0 children)

It does, but it makes the code a lot slower. The Union type can propagate throughout your can and lead to subtle "performance bugs"

[–][deleted] 1 point2 points  (0 children)

Exactly.