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.
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?
IIRC, Rust (which was designed for very safe code) doesnāt have overflow in debug code, but allows it in release code
Iād strongly disagree. The speed of light in my view is the dimensionless integer 1
GitHub - MasonProtter/NaturallyUnitful.jl: Facilities for using natural units with Unitful.jl
This is the only acceptable solution.
Bonus: it saves you from integer overflows.
@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.
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.
To be fair, I believe that historically the manual did take on the role of a tutorial, and was partially written that way.
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.
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
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
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!
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.
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?
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? ), 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).