3 ms·
This was written back in Julia v0.5, and the compiler got smarter so I need to update my examples :). Here, Julia specializes now on the fact that `-5` is a lit
by ChrisRackauckas 8y ago
This was written back in Julia v0.5, and the compiler got smarter so I need to update my examples :). Here, Julia specializes now on the fact that `-5` is a literal, and then inlines the literal and corrects the output type using that value. If you define it as a variable and stop constant propogation, it'll error. Stuff like this are making it harder to write tutorials to show what's actually going on, because literals and constants are all getting optimized on now!
Another confounding fact is that Julia optimizes on small unions, so the generated code isn't that bad anymore. Now it just creates a branch. It used to have to do all of inference and dynamic dispatching on the fly, which is what it has to do in fully uninferrable code of course, but a union of two things just does a type check and splits. So now... that example is not as bad as it used to be...
- FabHK 8y agoAh, well, I guess that's good news then!
- krull10 8y agoAs a rule of thumb, it is probably a good idea to ignore Julia articles that are more than a year or so old. Anything that is discussing pre-1.0 may be completely irrelevant at this point. The language has evolved a lot, even the past few years, and it is only with the 1.0 release last fall that the devs promised to start maintaining backwards compatibility. So there are lots of older articles discussing drawbacks to Julia, or ways to do things in Julia, that simply aren’t relevant anymore. Unfortunately they still often are the first links that come up when searching google for Julia questions.