The speed of light is an integer. Why should we care?

The discussion whether there should be a tutorial section included in the official documentation is a different discussion than the original post to the best of my understanding. Anyway, sorry if I misinterpreted your last post.

I don’t think that this is true at all. I’m sure that if you write a nice tutorial emphasizing the things you find important, people will appreciate it.

What if there was a tutorial mode in the REPL, kind of like how a lot of video games start of popping up info on the screen about what button do what to gradually introduce the information. The first time you define an integer from an integer literal it would pop up some info about what you just did, including a warning about integer overflow and link to the manual. Likewise, the first time you write a for loop in the REPL outside a function, maybe it links you to the performance tips about not working in global scope, and to info about scoping rules for julia. Are there enough items like this to make a tutorial mode useful? Maybe every-time you start up it picks some info from it’s library to put at the top of the REPL.

6 Likes

Actually, everything has already been written in the my first post in this thread.

In my view, the subsection Overflow Behavior only lacks the following link and may include the following example:

If the corresponding git pull request will be accepted, I can prepare it.

The link above can be introduced at the end of the said subsection as follows:
“For further discussion of this topic see link.”

The example above, can be introduced with as follows:
“If your previous experience make you think that integer overflow is quite rare and almost never happen in “real life”, concider the following example:”

Actually as a physicsit it does not seem natural to me to define c as an integer.
Clearly it is define as a whole number of metres in the SI system since 1983
Then again I started my undergrad degree in 1981…

I would first of all reach for PhysicalConstants.jl

I also saw mention of SaferIntegers.jl in this thread. Mind. Blown.
Are there similar things in other modern languages?

3 Likes

IIRC, Rust (which was designed for very safe code) doesn’t have overflow in debug code, but allows it in release code

1 Like

I’d strongly disagree. The speed of light in my view is the dimensionless integer 1 https://github.com/MasonProtter/NaturallyUnitful.jl :smiley:

11 Likes

This is the only acceptable solution. :laughing:
Bonus: it saves you from integer overflows.

2 Likes

@gevis, one of the core tenets of my interactions on this board is to assume the best of faith when interacting with others here. I don’t see folks shoving things in your face, nor do I see folks saying you can’t read, nor do I see folks saying that the documentation is in the best possible state and should not be changed. At the same time, I totally empathize with getting bit by a bug like this and feeling frustrated — and I get how the discussion here might feel like pushback. I’d just ask that you (and others here) focus on the potential improvements and avoid putting words in others mouths (or reacting to such). Remember that we’re all here because we enjoy the language and want to see it improve and succeed.

This discussion has already spurred one concrete improvement to the docs, and I’d further support cross-linking the FAQ to the overflow behaviors. I’m not as certain about the speed-of-light example simply because it’s rather long and complicated for non-physicists. It could be as simple as:

julia> c = 299_792_458
299792458

julia> 100c^2
8987551787368176400

julia> 200c^2
-471640498973198816

But I’m not sure it’d get accepted. There’s a tension in trying to keep things terse as too much detail can also get in the way; I’m not sure where this one falls. We’ve also seen molecular biologists hit this in defining Avogadro’s constant as 6.022*10^23 — should we also include that? What about other domains?

I do want to emphasize that numpy has the same behavior — and also relegates its discussion of overflow to the third major section of their user guide, even though they’re violating the behavior of their own language.

17 Likes

I’m really curious what gave you the impression that the Julia manual is a tutorial. It’s not, as @orialb pointed out. It’s a manual - primarily a technical reference (that’s primarily how I use it) with a fair amount of explanation sprinkled in. Nowhere does it claim to be a tutorial.

I 100% agree that more tutorials would be useful, and I think should be tailored to different domains. I don’t think that’s what the manual is for though.

5 Likes

To be fair, I believe that historically the manual did take on the role of a tutorial, and was partially written that way.

4 Likes

It would be nice.

I do not insist on that.

AFAICT the tutorial-style parts cover concepts that are more or less unique to Julia. A nice example is the sketch of Rational, which brings together various concepts (parametric types, inner and outer constructors, promotion, etc).

I think that these belong in the manual, since otherwise the intent of how basic constructs should be used would be difficult to decipher. This, of course, does not mean that the manual is a tutorial about all things that are necessary to use and understand Julia, especially if they are generic concepts of programming. For example, the Control Flow section does not explain what a conditional is.

That said, just working through (most of) the manual is a very nice way to get started with Julia. But it does require covering about 70% of it, instead of just looking up certain sections.

2 Likes

It is a great shame that Avogadro’s constant cant be expressed cannot be expressed as a Float64 with no loss in precision.

julia> convert(BigInt, big"6.02214076E23") |> Float64 |> BigInt
602214075999999987023872

julia> convert(BigInt, big"6.02214076E23") |> Float64 |> nextfloat |> BigInt
602214076000000054132736
3 Likes

I know this has been mentioned, but I did not see a link. The reason that Julia allows integer overflows is explained in great length here:
https://docs.julialang.org/en/v1/manual/faq/#faq-integer-arithmetic-1

4 Likes

I did a course in Numerical Computing and I was taught all sorts of things like catastrophic cancellation etc. I think if you do a lot of computation computers then learnign about Int and floats and how calculations can be messed up is super useful!

4 Likes

It might be nice if there was a tutorial package that would interactively walk people through the syntax and interfaces, a few key packages, even basic computer science knowledge like this.

Not exactly what you are looking for but checking out exercism which has a julia track.

2 Likes

At least this is false (for the REPL with alternative REPL modes):

Your exact code can work with first doing:

julia> using SafeREPL  # note, exact installation instructions (since not yet registered) at: https://github.com/rfourquet/SafeREPL.jl

i.e. without doing:

c = 299_792_458.0; 

what you otherwise could do, to get a floating point number, arguably better.

I’m not sure about that, I support Julia’s defaults, as it’s faster, while I can see both sides on the topic of the defaults, and thus I agree with you; and because of the danger of getting used to that non-default mode, maybe even it shouldn’t be used/installed by default?

My rule of thumb is that what can be measured, e.g. in meters (per sec), such as the speed of light, should use floating point, and what MUST (can?) be counted, e.g. currency (photons?), should use floats integers. [Those rules are sometimes broken, in banking integer cents or decimal (floating point), for dollars, should be used, while for a hedge fund floats can be appropriate for amounts.]

Since the Avogato constant was also brought up, since its SI redefinition in 2019, it’s exactly 6.02214076×10^23, and as atoms can be counted, its an argument for integers (BigInt then)…, while I guess floats (almost) always used.

So, no place for intergers? :slight_smile:

Not in e.g. JavaScript…, yes, integers have a place (I edited that error in my post), and I’m very conflicted if that language has the right idea (Fraudian slip? :slight_smile: ), but it does simplify to only have floats (for the user, not the implementer of the language/runtime, or for speed, while JS/V8 is often very fast).