7 ms·
Why Does Julia Work So Well?
- mcv 6y ago> ∇f(u) = α*u; ∇f(2) > sin(2π) Is that legal Julia? That's pretty awesome, but how do I type this? I think I need a new keyboard.
- Rygian 6y agoEvery Western-style input method should come with a Compose function enabled, and a simple tutorial on how to use it. For example, on Windows I use Wincompose [1], that lets me type things like "⋄*g" for Greek gamma: 'γ', or "⋄ee" for 'ə', or even "⋄⋄plane" for a '' (and of course the list is customizable). The "⋄" symbol represents the Compose key, which I chose to map to the Caps Lock key on my keyboard. [1] http://wincompose.info/ http://wincompose.info/ Edit: HN removed the airplane icon.
- mcv 6y agoI've been thinking about a dynamic keyboard where each key is a tiny oled screen that shows what character you're going to type in this particular mode. And then you're free to switch from regular to math to Greek to Chinese if you want, and the keyboard simply adjusts.
- Rygian 6y agoSuch as Optimus Maximus, for example? https://www.youtube.com/watch?v=qj7GYU-wedo https://www.youtube.com/watch?v=qj7GYU-wedo
- elcomet 6y agoYou can write \pi and then press tab. It works in the julia repl, and also on most editors that have julia plugins. Works for all greek letters, and other unicode characters.
- jaster 6y agoThe REPL (and most tooling I think) supports LaTeX-like abbreviations that autocomplete to the corresponding Unicode symbol, so no need for a special keyboard. See here https://docs.julialang.org/en/v1/manual/unicode-input/ https://docs.julialang.org/en/v1/manual/unicode-input/
- pa7x1 6y agoIt's legal Julia. Julia editors or VS Code with the Julia plugin support LaTeX commands and will perform autocompletion and convert it to the unicode character. For example, if you write \nabla it will offer autocompletion and write ∇. I think it's a neat feature and makes a lot of sense in scientific computing contexts but I feel I wouldn't like a code-base that abuses it too much. Sprinkled here and there can help make code more readable, succinct and pleasant.
- st1x7 6y ago> but I feel I wouldn't like a code-base that abuses it too much This is why I think it was a poor design choice to include the feature and actively encourage its use. The benefit of potentially more succint code is far outweighed by having to look with a codebase written entirely in Greek and there's no way to enforce moderation.
- kescobo 6y agoStyle guide for the base language is to generally stick to ascii, and many of the big packages do that too. It's really nice in examples, analysis scripts and the like though.
- pa7x1 6y agoIt's impossible to impose moderation in any language and you don't need unicode characters to write stupid code. Java programmers were writing HelloWorldFactory classes way before Julia existed.
- mcv 6y agoI think it's great for mathematicians, but I shudder to think what some Scala library builders might do if they get there hands on this.
- deleted 6y ago[deleted]
- mrkeen 6y ago> Type stability is the idea that there is only 1 possible type which can be outputtted from a method. > This right here is multiple-dispatch: the * operator calls a different method depending on the types that it sees. > If you have type stability inside of a function (meaning, any function call within the function is also type-stable), then the compiler can know the types of the variables at every step. > Type-stability is not the only necessity. You also need strict typing. Maybe it's time for me to embrace dynamic languages.
- JHonaker 6y agoJulia is dynamic. I've described this before, but the type annotations are used for multiple dispatch, not for static type checking. The quick example of why this is powerful is multiplication: # Assume you only have addition defined # Quick and dirty baseline function *(l::T, r::T) where {T<:Int} out = 0 while l > 0 out += r l -= 1 end out end # Great, now let's say you have a data type, rational numbers: struct Rational{T<:Int} numerator::T denominator::T end # And you want to define multiplication on rational numbers *(l::Rational, r::Rational) = Rational(l.numerator * l.numerator, l.denominator * l.denominator) # Cool, but multiplying Ints by rational number should also be defined *(l::Rational, r::Int) = Rational(l.numerator * r, l.denominator) *(l::Int, r::Rational) = *(r, l) The reason this is so cool, and why, yes it's still dynamic, is that I can call x * y on two variables, x and y, of which I know nothing about. The most specific method defined which matches their type will be called to handle it. If there isn't one defined, that's obviously a method error just like in your favorite other language!
- mlthoughts2018 6y agoThis is unfortunately playing some semantic language games to market for Julia. “type stable” multiple dispatch just means statically typed multiple dispatch (aka implementation overloading, aka specialization). It does not matter if the vtable used to map a function call to the chosen type-specific overload occurs in an otherwise dynamically typed language or not, it’s just your grandpa’s same old static multiple dispatch. This is fundamentally no different than using fused typing in Cython. The main advantage Julia has is that the whole language can use this by default, and so something that is a restricted computation domain in Python (like numpy arrays or pandas DataFrames which both heavily use C extensions and Cython) is just a more general “normal” data type in Julia. Whether this matters is hotly debated and open to wide disagreement. For example, I’m of the opinion that layering in micro-optimizations solely when you prove a need, and not relying on them to be abstract enough to automatically work throughout any use of the language, is a good thing. I prefer that control & distinction. I don’t want numpy ndarray to be arbitrarily subclassable with lots of custom child behavior that inherits the C extension targeted optimization - both because inheritance itself is a universally poor design concept as opposed to composition, and because the targeted optimizations are just that, targeted, and not intended to work properly for any general subclassed use case. Julia is a very impressive language, but it irks me to no end that so much written about it reads like a marketing brochure aimed to denigrate Python or MATLAB and cheerlead Julia. There’s a nasty arrogance in some Julia proponents’ writings on the topic, seeming to come from a place where they “know better” about hard core language design, JIT compilers, multiple dispatch... but this stuff has been heavily researched and understood and used in practice in eg Python for decades. It’s really tone deaf to say “yeah but we have such a clever multiple dispatch design” — congratulations, welcome to the 90s.
- stabbles 6y ago> It does not matter if the vtable used to map a function call to the chosen type-specific overload occurs in an otherwise dynamically typed language or not, it’s just your grandpa’s same old static multiple dispatch. Not sure what you mean. vtable's only allow for single dispatch in C++. For double dispatch you need the visitor pattern. For multiple dispatch, I don't know. Closest to what Julia has in C++ is Bjarne's Open Multi-Methods article [1], but it was not implemented. Another interesting quote from Bjarne's more recent How Can You Be So Certain article [2] is this: > Unified function call: The notational distinction between x.f(y) and f(x,y) comes from the flawed OO notion that there always is a single most important object for an operation. I made a mistake adopting that. It was a shallow understanding at the time (but extremely fashionable). Even then, I pointed to sqrt(2)and x+y as examples of problems caused by that view. This "mistake" is something Julia gets right. [1] https://www.stroustrup.com/multimethods.pdf https://www.stroustrup.com/multimethods.pdf [2] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1962r0.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p196...
- amelius 6y agoIt may sound silly but one thing that's holding me back is the "end" keyword at the end of every construct which seems unnecessarily verbose (and seems inconsistent as it isn't paired with a corresponding "begin").
- improbable22 6y agoIt's not so pretty, but what are the alternatives? Making indentation meaningful has downsides (copy-pasting can go very wrong) and using up ascii characters just for this means they can't do other things (like Vector{Int} type parameters) and still often takes up a line. You can avoid it quite a bit, e.g. f(x,y) = (z=x+y; sqrt(z)) defines a function, with two statements separated by ;.
- IshKebab 6y agoJulia uses `end` because it is derived from MATLAB which also uses `end`, it's not to save ASCII characters.
- cdsousa 6y agoAFAIK it is the opposite of what you have said. And although Julia has a lot of inspiration of Matlab syntax, it is absolutely not derived from it. https://julialang.org/blog/2012/02/why-we-created-julia/ https://julialang.org/blog/2012/02/why-we-created-julia/
- StefanKarpinski 6y agoThere are many fine languages that have used `end` to delimit blocks, including: Pascal — an elegant, classic language (and my first, personally); Ruby — another gem (get it). And yes, also Matlab, which is hardly unique in this respect.
- IshKebab 6y agoRight, but Julia is not derived from Ruby or Pascal.
- st1x7 6y agoI've seen a fair number of Julia posts on HN lately without any big recent developments in the language. It's a fine language but there is a type of preachy blindsighted hype that comes across as arrogant and is extremely offputting. Not quite at the level of Rust but it's getting there.
- dklend122 6y agoThere's no coordinated effort to do this. These are all independent pieces that were written at different times by different people. Where do you see the arrogance in the OP? It's showing exactly what's being claimed
- st1x7 6y agoI was making a general comment about the community. I don't have a problem specifically with the original post (which is several years old now).
- rfrey 6y agoA "general comment" that is name calling without specifics, suggestions, or examples isn't very constructive.
- tannhaeuser 6y ago"Why does Julia work so well", "The unreasonable effectiveness of Julia" tbh read as pure fanboyism at best, but more realistically as an effort to drum up a language that could need some attention, or getting "web mentions" for some hidden investment agenda.
- dklend122 6y agoThis was part of a tutorial series for a data science program The "unreasonable effectiveness" article wasn't, to my knowledge, by a community member. It's normal for magazines to have enthusiastic headlines. You're making a lot of assumptions here that aren't very kind or well supported.
- rcthompson 6y agoDoes anyone know why the text claims that "2^-5" is an error, but the output shows it returning 0.03125?
- kristofferc 6y agoIt used to error, but exponentiation with negative literal integers was made to work. Perhaps the notebook hasn't been updated since then.
- rcthompson 6y agoI would be interested to read how they made it work, given that it seems to violate the principle of type-stability. Did they just implement the slow runtime type check, or did they do something clever?
- dklend122 6y agoI think it's parsed specially, but I could be wrong. Definitely no runtime check
- improbable22 6y agoIt goes to `literal_pow`, one way to check is to overload this: Base.literal_pow(::typeof(^), x::Int, ::Val{n}) where {n} = (println("power $n"); float(x)^n) pow = -5 2^-5 # yes 2^pow # no, hence an error
- ChrisRackauckas 6y agoYes indeed: these are workshop notes from 2017 so it's a little old. In fact, it's surprising to see on Hacker News haha.
- TrackerFF 6y agoQuestion - because I haven't looked into Julia yet: What's the main selling point of Julia, over Python?
- m_mueller 6y agonative performance for things you run repeatedly.
- bb1234 6y agoFor me the main selling point is speed. I had coded a simulation in Python which was slow (would have taken days for the whole thing to run). This version did not use Numpy. Then I coded it in Python so that I could use Numpy. Just to be able to use Numpy I had to use arrays, where it did not seem natural for the problem I was solving. The numpy version gave me a 5 times speed up compared to the original Python version. I then coded it in C, which was about 20 times faster than the numpy version (and 100 times faster than the original version). Then I coded it in Julia, which was much easier to code in than coding it in C as well as Numpy. I could use loops where they felt more natural to me. It was essentially like the C code, but using many high level functions that Julia provides. Not a least bit difficult than the original Python version, would even say that it was a bit easier. The Julia code ran just as fast as C. Other benefits (not over Python, but I believe worthwhile when choosing a language): very friendly community to beginners. You ask simple questions and get answers without any attitude. As I noted above, many high level functions that make dealing with data much easier. If you are going to try it out, I would recommend using the Long term support release, rather than the current stable release. With the latter, I have had issues where some packages often don't work for me. With the LTS release, I have yet to experience that. Maybe I am doing something wrong, but for me LTS release works great.
- jakobnissen 6y agoThe main selling point is the speed. Julia is high performance - in the same class as C, C++, Rust etc (perhaps 1.5x slower on average, but still pretty fast). This allows you to write all your code in Julia rather than just the surface level wrapper. Then, because it's 20 years younger than Python, it has tonnes of ergonomics you would expect of a modern language: A nice, built-in package manager. Good code introspection. Easy ability to call C. An actually usable REPL. Built-in unit testing etc.
- shele 6y agoJulia's design is like Haskell's monads. It requires a bit of effort to sort out exactly what Julia's value proposition is. That's perhaps why people have the urge to write a Blog post to explain what a monad is, ahem, I mean to explain why Julia is a paradigm shift in programming languages and something worth checking out, once they figured it out.
- improbable22 6y agoThere's some truth in this. I think many of its enthusiasts aren't jaded multi-lingual programmers evaluating a new tool among many. They had some other problem they care about, for which Cython/Numba or whatever was obviously an awful kludge, and eventually they got tired of fighting it & looked around. And then discovered that this new tool they found was a beautiful thing in its own right, and they want to tell people.
- ChrisRackauckas 6y agoHey, I guess OP here. These are part of the workshop notes from 2017 (with a few updates, but mostly left intact) on "A Deep Introduction to Julia for Data Science and Scientific Computing". It's a full day 8am-3pm workshop (with extended problem exercises to take home!) that can be found here: http://ucidatascienceinitiative.github.io/IntroToJulia/ http://ucidatascienceinitiative.github.io/IntroToJulia/ The section that was pulled out to be the heading link here was the portion that comes after first explaining the semantics of the language. The "Why Julia?" section is an explanation of why Julia is fast but also the engineering trade-offs that were made to get it done (and thus the drawbacks of the approach). That is the page is that is linked, but if you're curious about the greater context of this page (and learning the language) do check out the rest of the notes. I will say that they are a bit old (one comment noted that a compiler specializations on literals does handle one of the cases I pointed out in the trade-offs) but for the most part are still a good introduction to the Julia programming language. Surprising to have people tell me this ended up on Hacker News but exciting to see!