# It is so nice to program in a sane language!

**URL:** <https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227>\
**Category:** Offtopic\
**Created:** [December 13, 2019, 10:41am UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227 "2019-12-13T10:41:25Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![recri](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/recri/32/5280_2.png) [@recri](https://discourse.julialang.org/u/recri)\
**Post date:** [December 14, 2019, 1:49am UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/21 "2019-12-14T01:49:58Z")

</div>

Oh, that one has a bigger sibling:

```julia
julia> f = 2; f1 = 2; 2f+2f1
400.0f0

julia> 2f + 2f1
24.0f0

```

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [December 14, 2019, 1:57am UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/22 "2019-12-14T01:57:39Z")

</div>

That might just be the most horrible thing I’ve ever seen.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [December 14, 2019, 3:13am UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/23 "2019-12-14T03:13:48Z")

</div>

I’m talking about the case where `n` is a number, e.g.

```julia
julia> v = zeros(Int, 5);

julia> n = length(v)
5

julia> for i in n
           v[i] = i
       end

julia> v
5-element Array{Int64,1}:
 0
 0
 0
 0
 5

julia> for i in 1:n
           v[i] = i
       end

julia> v
5-element Array{Int64,1}:
 1
 2
 3
 4
 5

```

It’s too easy to write the former when you mean the latter, due to the fact that a number is iterable.

---

<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:** [December 14, 2019, 3:29am UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/24 "2019-12-14T03:29:13Z")

</div>

> [@dpsanders](#):
>
> I’m talking about the case where `n` is a number

Yes I’m aware. I occasionally find it useful.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [December 14, 2019, 4:24am UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/25 "2019-12-14T04:24:45Z")

</div>

You mean for generic code where n could also be an array?

This is my most common typo bug. I also wish it was an error…

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 14, 2019, 8:34am UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/26 "2019-12-14T08:34:40Z")

</div>

I don’t think you can catch this at the syntax level, since `n` might as well be an iterable.

The fundamental problem is that numbers are iterable. That would have to be fixed so that this can just error.

---

<div class="post-metadata">

**Author:** ![laborg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laborg/32/5474_2.png) [@laborg](https://discourse.julialang.org/u/laborg)\
**Post date:** [December 14, 2019, 9:09am UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/27 "2019-12-14T09:09:25Z")

</div>

Just curious about others:

_ **If you could, would you remove Numeric Literal Coefficients in Julia 2.0?** _

_Poll ([view on site](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/27))_

---

<div class="post-metadata">

**Author:** ![peterkovesi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peterkovesi/32/5946_2.png) [@peterkovesi](https://discourse.julialang.org/u/peterkovesi)\
**Post date:** [December 14, 2019, 9:32am UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/28 "2019-12-14T09:32:14Z")

</div>

One thing that I am sure catches out many new users are the ambiguities caused by the use of white space in parsing matrices and how these ambiguities also splatter into the parsing of vectors (but not tuples).

```julia
julia> v = [1 - 2, 3 + 4]
2-element Array{Int64,1}:
 -1
  7

julia> m = [1 - 2 3 + 4]
1×2 Array{Int64,2}:
 -1 7

julia> m = [1 - 2 3 +4]
1×3 Array{Int64,2}:
 -1 3 4

julia> v = [1 - 2, 3 +4]
ERROR: syntax: missing separator in array expression

julia> v = [1 -2, 3 + 4]
ERROR: syntax: unexpected comma in matrix expression

julia> t = ( 1 -2, 3 + 4 )
(-1, 7)

```

I really hope something like [this proposal in #7128](https://github.com/JuliaLang/julia/issues/7128#issuecomment-348742232) makes it into Julia 2.0

---

<div class="post-metadata">

**Author:** ![Syx\_Pek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/syx_pek/32/6364_2.png) [@Syx\_Pek](https://discourse.julialang.org/u/Syx_Pek)\
**Post date:** [December 14, 2019, 2:05pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/29 "2019-12-14T14:05:24Z")

</div>

I actually think the current system is fine, just requires a little effort to get used to. I understand it maybe a little tricky initially.

Perhaps the pain of all these is to encourage people to use loop comprehensions instead.

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [December 14, 2019, 4:24pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/30 "2019-12-14T16:24:25Z")

</div>

> [@Fun One Liners](https://discourse.julialang.org/t/fun-one-liners/28352/56):
>
> I think I’ll just continue to define Tau myself rather then import this package. Maybe there’s some elaborate argument why it should be “tau ~ 2pi” but for my uses, it’s just 2pi. tau = 2pi Cool to know about mod2pi. Didn’t know it was in the base library, because I had no idea there was a name for this function, the code for it is well, interesting: [https://github.com/JuliaLang/julia/blob/c6da87ff4bc7a855e217856757ad3413cf6d1f79/base/math.jl#L801-L987](https://github.com/JuliaLang/julia/blob/c6da87ff4bc7a855e217856757ad3413cf6d1f79/base/math.jl#L801-L987) Guess this is why I’d never call myself …

The discussion of Tau has arrived numerous times on here!

There is a package for it 😃 [GitHub - JuliaMath/Tau.jl: A Julia module providing the definition of the circle constant Tau (2π)](https://github.com/JuliaMath/Tau.jl)

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 14, 2019, 6:43pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/31 "2019-12-14T18:43:35Z")

</div>

Rather than removing numeric literal coefficients, I might prefer the more radical move of changing the engineering syntax for floating point literals to something that (a) doesn’t clash with numeric literal coefficients and (b) is more extensible to different floating point sizes. Currently we have:

- `1e2` — `Float64` literal
- `1E2` — means the same thing
- `1f2` — `Float16` literal
- `1F2` – nope, that is NOT a float literal syntax
- no syntax for `Float16` literals
- no syntax for `Float128` literals (and we don’t have those… yet)

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 14, 2019, 6:44pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/32 "2019-12-14T18:44:59Z")

</div>

Space-sensitive parsing is a real pain. Unfortunately, it also applies to macro calls, so even if we got rid of it for array concatenation, we’d still have it there.

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [December 14, 2019, 6:59pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/33 "2019-12-14T18:59:10Z")

</div>

Could you elaborate a bit on how such a new syntax could look like? I find the current one quiet convenient and can’t really think of any syntax that’s neither taken already nor awkward to write.

---

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [December 14, 2019, 8:06pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/34 "2019-12-14T20:06:20Z")

</div>

Fwiw, there’s [an extensive discussion of this point](https://github.com/JuliaLang/julia/issues/7903) (from 2014-2017) on the issue tracker.

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [December 14, 2019, 9:28pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/35 "2019-12-14T21:28:52Z")

</div>

I suggest to rename this thread to `Julia: WAT!` 😉

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 15, 2019, 12:09pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/36 "2019-12-15T12:09:37Z")

</div>

Thanks, I am aware of that, but also that it is unlikely to be changed in the foreseeable future, so I was just venting 😉

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 15, 2019, 5:20pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/37 "2019-12-15T17:20:03Z")

</div>

No idea 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [December 15, 2019, 6:53pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/38 "2019-12-15T18:53:51Z")

</div>

I would like it if `1.0*10^30` were parsed as a floating point literal (instead of evaluating to 5.077e18 due to integer overflow).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 15, 2019, 7:14pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/39 "2019-12-15T19:14:48Z")

</div>

How would you suggest the above is parsed instead? Why not just use `1e30`?

I would, instead, prefer if in general

```julia
f(literal, b, c...)

```

and

```julia
let a = literal
    f(a, b, c...)
end

```

were indistinguishable everywhere and the parser refrained from clever tricks without being asked explicitly.

That is already violated with literal integer powers (as pointed out above). When that was introduced I thought it was an especially neat trick, now I don’t think it was worth the confusion.

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [December 15, 2019, 8:57pm UTC](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227/40 "2019-12-15T20:57:10Z")

</div>

> [@Tamas\_Papp](#):
>
> How would you suggest the above is parsed instead?

My parsing rule would be that `[literal float] * [literal integer] ^ [literal integer]` would evaluate in arbitrary precision, and then yield a literal `Float64` if the result would fit, and a literal `BigFloat` otherwise.

Yes, this would be confusing sometimes, but so is `1.0*10^30 ≈ 5.07694427030e18`.

Now that I think about it, maybe `[literal integer] ^ [literal integer]` should always be evaluated at parse time, and yield `Int128` or `BigInt` as necessary, just as integer literals with many digits do.

(Then you’d have to write e.g. `2^127 % Int64` if you wanted the current behavior, which I think is fair, because that is a very confusing way to write `0`.)

[Previous page](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227.md?page=1)

[Next page](https://discourse.julialang.org/t/it-is-so-nice-to-program-in-a-sane-language/32227.md?page=3)
