# Why I love Julia

**URL:** <https://discourse.julialang.org/t/why-i-love-julia/29489>\
**Category:** Community\
**Tags:** announcement\
**Created:** [October 4, 2019, 3:29pm UTC](https://discourse.julialang.org/t/why-i-love-julia/29489 "2019-10-04T15:29:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kolia](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@kolia](https://discourse.julialang.org/u/kolia)\
**Post date:** [October 4, 2019, 3:29pm UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/1 "2019-10-04T15:29:50Z")

</div>

I just gave a talk at my company attempting to explain why we are all so excited about Julia in one hour. I tried to focus on the essence of it, borrowing material from the manual, Stephan’s “Unreasonable effectiveness of multiple dispatch” talk and others.

Thought I’d share the [nextjournal notebook](https://nextjournal.com/kolia/why-i-love-julia) I used to present, for others to fork and reuse.

Notifications of inaccuracies and omissions welcome.

---

<div class="post-metadata">

**Author:** ![evanfields](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evanfields/32/1744_2.png) [@evanfields](https://discourse.julialang.org/u/evanfields)\
**Post date:** [October 4, 2019, 6:45pm UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/2 "2019-10-04T18:45:13Z")

</div>

I am expecting to give a similar talk soon so this will be very useful. Thanks!

---

<div class="post-metadata">

**Author:** ![Glen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glen/32/3583_2.png) [@Glen](https://discourse.julialang.org/u/Glen)\
**Post date:** [October 5, 2019, 12:27am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/3 "2019-10-05T00:27:12Z")

</div>

Hi,

Nice work. For your `summed` case you could write it like this:

```julia
function summed(a)
    result = 0.0 # note 0.0
    @simd for x in a # note @simd
        result += x
    end
    return result
end

```

This is fast as the built-in `sum` on 1.2 (for me at least). The built-in sum is more generic and handles more corner cases. I first tried changing `0` to `0.0` to match the type of the elements of `a` but it didn’t speed up (so 1.2 must be smarter than previous versions).

Glen

---

<div class="post-metadata">

**Author:** ![kolia](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@kolia](https://discourse.julialang.org/u/kolia)\
**Post date:** [October 5, 2019, 10:43am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/4 "2019-10-05T10:43:12Z")

</div>

When I give the talk I explain that this is a naive impl of sum, and I show that for example a better init for result would be zero(eltype(a))

I tried slapping a @simd in front of the for loop but it doesn’t speed it up in the notebook env which is 1.2. What array size did you try this with to see a speed up? I’m guessing the speed up for naively putting @simd in front of the for loop is dependent on size(a), whereas The recursive binary divide and conquer in the Base.sum impl gives you a speed up on a broad range of sizes, probably? Anyone have some insight here?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [October 5, 2019, 11:23am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/5 "2019-10-05T11:23:17Z")

</div>

The divide and conquer algorithm in Base for floating point summation is used to reduce accumulation error as far as I know. ~~Naive linear summation has O(n) additions whereas the one in base does O(log n).~~

---

<div class="post-metadata">

**Author:** ![kolia](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@kolia](https://discourse.julialang.org/u/kolia)\
**Post date:** [October 5, 2019, 1:00pm UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/6 "2019-10-05T13:00:56Z")

</div>

Isn’t the number of non leaf nodes in a full binary tree with n leaves n-1? It’s still linear.

But maybe doing the additions in the bottom up binary tree order leads to less error?

[SIMD and SIMD-intrinsics in Julia | Kristoffer Carlsson](http://kristofferc.github.io/post/intrinsics/) Is a good read. Still not entirely sure how the divide and conquer strategy helps.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [October 5, 2019, 5:12pm UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/7 "2019-10-05T17:12:22Z")

</div>

Yes of course, my mistake - it’s purely to reduce summation error, not necessarily faster.

> **[Pairwise summation](https://en.wikipedia.org/wiki/Pairwise_summation)**
>
> In numerical analysis, pairwise summation, also called cascade summation, is a technique to sum a sequence of finite-precision floating-point numbers that substantially reduces the accumulated round-off error compared to naively accumulating the sum in sequence. Although there are other techniques such as Kahan summation that typically have even smaller round-off errors, pairwise summation is nearly as good (differing only by a logarithmic factor) while having much lower computational cost—it In...

---

<div class="post-metadata">

**Author:** ![kolia](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@kolia](https://discourse.julialang.org/u/kolia)\
**Post date:** [October 5, 2019, 6:52pm UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/8 "2019-10-05T18:52:12Z")

</div>

Thanks for the explanation, pairwise summation it is!

The remaining mysteries are why prepending @simd does not speed up my naive loop when it does speed up yours, and why the @simd divide and conquer for loop in Base.sum does give me a speed up…

I’ll try playing with it until I figure it out

---

<div class="post-metadata">

**Author:** ![Glen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glen/32/3583_2.png) [@Glen](https://discourse.julialang.org/u/Glen)\
**Post date:** [October 6, 2019, 12:52am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/9 "2019-10-06T00:52:26Z")

</div>

Hi kolia,

I used the same input as you. My `versioninfo()` returns:

```julia
Julia Version 1.2.0
Commit c6da87ff4b (2019-08-20 00:03 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, haswell)

```

Maybe why you don’t see a speed-up is related to your CPU or OS. Here’s my `@code_native` to compare with yours:

```julia
julia> @code_native summed(a)
	.text
; ┌ @ REPL[2]:3 within `summed'
; │┌ @ simdloop.jl:71 within `macro expansion'
; ││┌ @ simdloop.jl:51 within `simd_inner_length'
; │││┌ @ REPL[2]:2 within `length'
	movq	8(%rdi), %rax
; │└└└
; │┌ @ int.jl:49 within `macro expansion'
	testq	%rax, %rax
; └└
; ┌ @ simdloop.jl:72 within `summed'
	jle	L26
	movq	(%rdi), %rcx
; │ @ simdloop.jl:75 within `summed'
	cmpq	$16, %rax
	jae	L34
	vxorpd	%xmm0, %xmm0, %xmm0
	xorl	%edx, %edx
	jmp	L124
L26:
	vxorps	%xmm0, %xmm0, %xmm0
; └
; ┌ @ REPL[2]:6 within `summed'
	vzeroupper
	retq
; │ @ REPL[2]:3 within `summed'
; │┌ @ simdloop.jl:75 within `macro expansion'
L34:
	movq	%rax, %rdx
	andq	$-16, %rdx
	leaq	96(%rcx), %rsi
	vxorpd	%xmm0, %xmm0, %xmm0
; ││ @ simdloop.jl:78 within `macro expansion'
; ││┌ @ int.jl:53 within `+'
	movq	%rdx, %rdi
	vxorpd	%xmm1, %xmm1, %xmm1
	vxorpd	%xmm2, %xmm2, %xmm2
	vxorpd	%xmm3, %xmm3, %xmm3
; ││└
; ││ @ simdloop.jl:77 within `macro expansion' @ REPL[2]:4
; ││┌ @ float.jl:395 within `+'
L64:
	vaddpd	-96(%rsi), %ymm0, %ymm0
	vaddpd	-64(%rsi), %ymm1, %ymm1
	vaddpd	-32(%rsi), %ymm2, %ymm2
	vaddpd	(%rsi), %ymm3, %ymm3
; │└└
; │┌ @ int.jl:53 within `macro expansion'
	subq	$-128, %rsi
	addq	$-16, %rdi
	jne	L64
; │└
; │┌ @ simdloop.jl:77 within `macro expansion' @ REPL[2]:4
; ││┌ @ float.jl:395 within `+'
	vaddpd	%ymm0, %ymm1, %ymm0
	vaddpd	%ymm0, %ymm2, %ymm0
	vaddpd	%ymm0, %ymm3, %ymm0
	vextractf128	$1, %ymm0, %xmm1
	vaddpd	%ymm1, %ymm0, %ymm0
	vhaddpd	%ymm0, %ymm0, %ymm0
	cmpq	%rdx, %rax
; └└└
; ┌ @ simdloop.jl:75 within `summed'
	je	L158
L124:
	subq	%rdx, %rax
	leaq	(%rcx,%rdx,8), %rcx
	nopw	%cs:(%rax,%rax)
; └
; ┌ @ REPL[2]:3 within `summed'
; │┌ @ simdloop.jl:77 within `macro expansion' @ REPL[2]:4
; ││┌ @ float.jl:395 within `+'
L144:
	vaddsd	(%rcx), %xmm0, %xmm0
; ││└
; ││ @ simdloop.jl:75 within `macro expansion'
; ││┌ @ int.jl:49 within `<'
	addq	$8, %rcx
	addq	$-1, %rax
; ││└
	jne	L144
; │└
; │ @ REPL[2]:6 within `summed'
L158:
	vzeroupper
	retq
	nopw	%cs:(%rax,%rax)
; └

```

Glen

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [October 6, 2019, 1:32am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/10 "2019-10-06T01:32:00Z")

</div>

You can do `zero(typeof(a))` or more simply `zero(a)`.

---

<div class="post-metadata">

**Author:** ![Alec\_Loudenback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alec_loudenback/32/278_2.png) [@Alec\_Loudenback](https://discourse.julialang.org/u/Alec_Loudenback)\
**Post date:** [October 6, 2019, 3:38am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/11 "2019-10-06T03:38:30Z")

</div>

Nice presentation, @kolia!

I gave a talk ([Nextjournal link](https://nextjournal.com/alecloudenback/julia-and-jupyter-notebooks)) a few months ago to a less technical audience (I assume based on some of the elements of your notebook that your audience has more of a computer science background).

My audience was actuaries, who have more of a math and mild-programming via data-science background.

I also included a comparison to R vs Python, based on a combination of opinion and feedback on the Julia Slack:

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

Probably in the intervening months some updates needed (e.g. 2.5/3 stars for Parallelism with 1.3)

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [October 6, 2019, 3:41am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/12 "2019-10-06T03:41:57Z")

</div>

tbf, I won’t call Julia ‘written’ in Julia, although, `stdlib` is mostly written in Julia

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [October 6, 2019, 9:34am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/13 "2019-10-06T09:34:47Z")

</div>

I didn’t know that R is written in Rust

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [October 6, 2019, 10:26am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/14 "2019-10-06T10:26:08Z")

</div>

I’m pretty sure most of R is written in C - then again a lot may have changed since I last looked.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 6, 2019, 11:05am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/15 "2019-10-06T11:05:46Z")

</div>

Indeed: it is mostly R, C, and Fortran:

[https://github.com/wch/r-source](https://github.com/wch/r-source)

Packages also use C++ and other languages. There is a project with Rust, but it appears to be dormant:

[https://github.com/rustr/rustinr](https://github.com/rustr/rustinr)

---

<div class="post-metadata">

**Author:** ![Alec\_Loudenback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alec_loudenback/32/278_2.png) [@Alec\_Loudenback](https://discourse.julialang.org/u/Alec_Loudenback)\
**Post date:** [October 6, 2019, 1:07pm UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/16 "2019-10-06T13:07:06Z")

</div>

Yea, I think I meant to say “R itself” per [its Wikipedia page](https://en.wikipedia.org/wiki/R_(programming_language)).

---

<div class="post-metadata">

**Author:** ![kolia](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@kolia](https://discourse.julialang.org/u/kolia)\
**Post date:** [October 6, 2019, 3:30pm UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/17 "2019-10-06T15:30:23Z")

</div>

Finally got around to figuring it out, it was very simple.

Turns out that adding @simd without fixing the type mismatch between the `result = 0` init and `eltype(a)` keeps @simd from doing its thing.

This does give the speedup, and it’s nice and clean and eltype-agnostic:

```julia
function sumsimd(a)
  result = zero(eltype(a))
  @simd for x in a
    result += x
  end
  return result
end

```

I added this `@simd for x in a` version to the nextjournal presentation notebook, and added the link to Pairwise Summation wikipedia page explaining why Base.sum does what it does.

---

<div class="post-metadata">

**Author:** ![kolia](https://avatars.discourse-cdn.com/v4/letter/k/c68b51/32.png) [@kolia](https://discourse.julialang.org/u/kolia)\
**Post date:** [October 6, 2019, 3:52pm UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/18 "2019-10-06T15:52:13Z")

</div>

As you guessed, my audience was software engineers who work mostly with Scala and Python, and data scientists.

Julia is an easy sell to data science folks so I targeted the software folks. Julia is just a good general programming language generally, and I set out to explain why.

The presentation was met with a lot of nods and what’s the catch and when can we switch. The main dissent was some being horrified about the lack of privacy of defining new methods on functions like `Base.print` whenever you define a new datatype, and an ensuing discussion of what [type piracy](https://docs.julialang.org/en/v1/manual/style-guide/index.html#Avoid-type-piracy-1) is, and why it hasn’t been an issue. Not everyone was convinced by the argument that the Julia community has been doing this for a while without the sky coming crashing down, and that we see more benefits from it than downsides…

---

<div class="post-metadata">

**Author:** ![pistacliffcho](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pistacliffcho/32/8518_2.png) [@pistacliffcho](https://discourse.julialang.org/u/pistacliffcho)\
**Post date:** [October 7, 2019, 12:42am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/19 "2019-10-07T00:42:55Z")

</div>

Not to be a wet blanket, but given the R packages [parallel and foreach](https://nceas.github.io/oss-lessons/parallel-computing-in-r/parallel-computing-in-r.html) at the native R level and [RcppParallel](https://rcppcore.github.io/RcppParallel/) at the Rcpp level, I have a little trouble giving R only one star for parallel support.

I will say that it is a bit easier in Julia. But truth be told, I found RcppParallel to more efficiently use multiple threads than Julia on the same machine with the same algorithm. I have no insight into the why of that and user error is a very real possibility.

Of course, the fact that you have to think about two different languages for parallezation in R instead of one points directly to the two language problem that Julia answers.

---

<div class="post-metadata">

**Author:** ![Glen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/glen/32/3583_2.png) [@Glen](https://discourse.julialang.org/u/Glen)\
**Post date:** [October 7, 2019, 2:32am UTC](https://discourse.julialang.org/t/why-i-love-julia/29489/20 "2019-10-07T02:32:15Z")

</div>

Hi Kolia,

Good to hear you figured it out. I like that you explained why Julia’s `sum` is so much more complicated because when I looked at it the first time I was totally confused and it didn’t give me the impression that Julia is easy to use.

Glen

[Next page](https://discourse.julialang.org/t/why-i-love-julia/29489.md?page=2)
