# Why does scientific notation break the range function?

**URL:** <https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014>\
**Category:** New to Julia\
**Created:** [April 25, 2022, 8:46pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014 "2022-04-25T20:46:57Z")\
**Posts on this page:** 16\
**Page:** 5

<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:** [April 27, 2022, 1:57pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/84 "2022-04-27T13:57:29Z")

</div>

Create a new issue at [Issues · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues) and give an example of the error message and what you think might be a better wording. Discourse is good for discussion but an issue acts like a todo for someone to actually fix something. Thanks!

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [April 27, 2022, 2:05pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/85 "2022-04-27T14:05:49Z")

</div>

As far as I can see it is printed first? In that, it is the first entry in the stacktrace.

Also the stacktrace is specific to VS Code, this is what it looks like in a “regular” notebook, i.e. Jupyter via IJulia:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/b/ab5f167e812a22617e62469593790e3d8aaa0ede.png)

So here it shows you the information `@ In[12]:5`, i.e. the input cell and line in the input cell. I’m not sure whether this is a Julia VSCode issue or VSCode more generally - the notebook support in VSCode is still quite new and I’m not sure how “production ready” it is considered to be (judging from [open issues](https://github.com/microsoft/vscode/issues?q=is%3Aissue+is%3Aopen+notebook+label%3Anotebook) on the VSCode repo it seems there’s still a lot of usability issues)

---

<div class="post-metadata">

**Author:** ![chadagreene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chadagreene/32/34924_2.png) [@chadagreene](https://discourse.julialang.org/u/chadagreene)\
**Post date:** [April 27, 2022, 2:16pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/86 "2022-04-27T14:16:58Z")

</div>

I see what you mean by _first_, because it’s on the first line of the Stacktrace, but I’ll point out that it’s at the end of the fourth line of text that users must read. This means users are tasked with scanning through 30 lines of encoded messages in the Stacktrace to find one tiny number that’s printed at the end of the fourth line of the error message, and is presented without any units. I think the line number could be presented more prominently, and with more clarity, by stating `Error on Line 5:` at the very start of the error message.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [April 27, 2022, 2:38pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/87 "2022-04-27T14:38:39Z")

</div>

When you want to know where the problem happened you always go directly to the stacktrace, this is its purpose, no?

The stracktrace is always printed as `filename:line_number`, however, Jupyter changes this to `[cell_evaluation_number]:line_number` what makes it a little harder to parse (if I see `mycode.jl:10` I immediately understand that 10 is a line number, couldn’t be anything else, but `[7]:10` is far more cryptic).

On the subject of making the error messages more human-readable, besides changing `Union{A, B, C, ...}` to `one among A, or B, or C, or ...` could we also prefix each abstract type with `a subtype of`? Not sure if concrete types need any prefix, I am more interested in having abstract and concrete types to be immediately distinguishable in the message. On special cases, we could also replace `Nothing` by `nothing` as it is its only value (same for `Missing`). Do not really mind if things stay the way they are (found the original message to be legible) but these are my two cents.

---

<div class="post-metadata">

**Author:** ![chadagreene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chadagreene/32/34924_2.png) [@chadagreene](https://discourse.julialang.org/u/chadagreene)\
**Post date:** [April 27, 2022, 2:41pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/88 "2022-04-27T14:41:19Z")

</div>

[Done](https://github.com/JuliaLang/julia/issues/45106).

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [April 27, 2022, 3:01pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/89 "2022-04-27T15:01:23Z")

</div>

> [@Henrique\_Becker](#):
>
> On the subject of making the error messages more human-readable, besides changing `Union{A, B, C, ...}` to `one among A, or B, or C, or ...` could we also prefix each abstract type with `a subtype of` ?

This is perhaps clearer for beginners (so new they haven’t heard of `Union` yet), but is it better for everyone? I’m afraid it could be _less_ readable for experienced programmers (it could become quite verbose).

Could an alternative be to keep the message, but make it _really_ simple to find out what `Union{Nothing, Integer}` means?

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [April 27, 2022, 4:31pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/90 "2022-04-27T16:31:26Z")

</div>

> [@DNF](#):
>
> Could an alternative be to keep the message, but make it _really_ simple to find out what `Union{Nothing, Integer}` means?

And also improve the doc-string of `Union`

> [@nilshg](#):
>
> ```julia
> A type union is an abstract type which includes all instances of any of its argument types. The empty union Union{} is the bottom type of Julia.
> 
> ```

While I think I understand that phrase, I easily see how this is not going to be understandable at all for a newbie (bottom type? Instances? `abstract type`?). 😅

I would propose to have an easier to read doc-string, something like

> [@](#):
>
> `Union{Types...}`
> 
> An `Union` type is an `abstract type` that can reference any of the values of one of its argument. It cannot be instantiated.
> 
> **Examples**  
> **≡≡≡≡≡≡≡≡≡≡**
> 
> ```julia
> julia> IntOrString = Union{Int,AbstractString}
> Union{Int64, AbstractString}
> 
> julia> 1 :: IntOrString
> 1
> 
> julia> "Hello!" :: IntOrString
> "Hello!"
> 
> julia> 1.0 :: IntOrString # Float64 is neither Int64, nor AbstractString
> ERROR: TypeError: in typeassert, expected Union{Int64, AbstractString}, got a value of type Float64
> 
> julia> IntOrString(1) # Error, cannot instantiate
> ERROR: MethodError: no method matching Union{Int64, AbstractString}(::Int64)
> 
> ```
> 
> **Note:**
> 
> The empty `Union{}` is the bottom type of Julia

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 27, 2022, 4:43pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/91 "2022-04-27T16:43:28Z")

</div>

> [@suavesito](#):
>
> I would propose to have an easier to read doc-string, something like

Note that it is quite easy to submit a pull request for this. The `Union` documentation is [here](https://github.com/JuliaLang/julia/blob/1c5648d5c3002cb4c6b118ad97502cfc9ca09c48/base/docs/basedocs.jl#L2515-L2536), and you can just click the “Edit this file” button  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/1/b1e43db5d66a4f99f647062ef8b035c13663c892.png)  
to modify the documentation and submit a patch.

---

<div class="post-metadata">

**Author:** ![suavesito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suavesito/32/34386_2.png) [@suavesito](https://discourse.julialang.org/u/suavesito)\
**Post date:** [April 27, 2022, 5:01pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/92 "2022-04-27T17:01:48Z")

</div>

[Done](https://github.com/JuliaLang/julia/pull/45109) 🙂

---

<div class="post-metadata">

**Author:** ![owiecc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/owiecc/32/8894_2.png) [@owiecc](https://discourse.julialang.org/u/owiecc)\
**Post date:** [April 29, 2022, 8:45am UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/93 "2022-04-29T08:45:42Z")

</div>

> [@chadagreene](#):
>
> Yep, and after that there’s 30 lines of Stacktrace garbage that buries the tiny morsel of the error message that could potentially be helpful.

Let me introduce you to [AbbreviatedStackTraces.jl](https://github.com/BioTurboNick/AbbreviatedStackTraces.jl) It is not in registry yet, so you will need to follow their installation guide.

---

<div class="post-metadata">

**Author:** ![TS-CUBED](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ts-cubed/32/25292_2.png) [@TS-CUBED](https://discourse.julialang.org/u/TS-CUBED)\
**Post date:** [April 29, 2022, 10:26am UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/94 "2022-04-29T10:26:19Z")

</div>

> [@chadagreene](#):
>
> But back to the original issue: **Should the `range` function be updated to allow whole numbers for the length definition, even if they’re Floats?**

You are trying to make Julia behave like Matlab. Unfortunately that would break Julia and make it like Matlab.

The reason why Julia is so much faster than Matlab (even when we take Matlab’s JIT compiler efforts into account) is that Julia is essentially a typed language, less high-level than Matlab (which, tbh, I’d argue is not a programming language at its core).

If your idea would be integrated, then every time you use a float, where an integer is needed, you’d break type stability and make the code slower.

In the end you’d have a language that may be as easy to learn as Matlab, but just as limited when it comes to optimisation. And then you’d need to learn C in addition to Matlab, which would be a lot more painful than to learn to cope with Julia.

So what you describe is the cost you need to pay for getting a more powerful tool.

Or as in the car analogy you use later: automatic transmissions were never used in high-performance cars.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [April 29, 2022, 11:03am UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/95 "2022-04-29T11:03:46Z")

</div>

FWIW, that specific issue is fixed already (and should be in a released version of the extension soonish).

---

<div class="post-metadata">

**Author:** ![TS-CUBED](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ts-cubed/32/25292_2.png) [@TS-CUBED](https://discourse.julialang.org/u/TS-CUBED)\
**Post date:** [April 29, 2022, 12:27pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/96 "2022-04-29T12:27:07Z")

</div>

This is indeed a nice extension. And I’d second that that should potentially be considered default behaviour. While I can filter the error message, many of my students struggle with that kind of error. And, most of the stack trace is going down the rabbit hole of the modules that are loaded. Which are very likely not the cause of the error I’m looking at. So the reduced stacktrace makes a lot of sense to me. In particular, with the “err for full stacktrace” at the end.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [April 29, 2022, 1:22pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/97 "2022-04-29T13:22:37Z")

</div>

Cool! Is there some way for this to work together with something like: [GitHub - MichaelHatherly/InteractiveErrors.jl: Interactive error messages for the Julia REPL.](https://github.com/MichaelHatherly/InteractiveErrors.jl) or [Terminal Menus](https://docs.julialang.org/en/v1/stdlib/REPL/#TerminalMenus), where you can interactively expand the stacktrace, instead of choosing either full or compressed printing?

---

<div class="post-metadata">

**Author:** ![chadagreene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chadagreene/32/34924_2.png) [@chadagreene](https://discourse.julialang.org/u/chadagreene)\
**Post date:** [April 29, 2022, 1:48pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/98 "2022-04-29T13:48:43Z")

</div>

@TS-CUBED That’s an incredibly helpful explanation, thank you! OK, I’m starting to understand the underlying philosophy a little bit better: Sacrifice a few “creature comforts” to keep performance at center stage. That makes sense.

---

<div class="post-metadata">

**Author:** ![chadagreene](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chadagreene/32/34924_2.png) [@chadagreene](https://discourse.julialang.org/u/chadagreene)\
**Post date:** [April 29, 2022, 1:52pm UTC](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014/99 "2022-04-29T13:52:30Z")

</div>

@DNF Yes, I love the idea of a stacktrace that’s collapsed by default, but could easily be expanded on Click for anyone who wants to explore the layers of details in the error.

[Previous page](https://discourse.julialang.org/t/why-does-scientific-notation-break-the-range-function/80014.md?page=4)
