# In as few lines as possible describe why you love julia

**URL:** <https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179>\
**Category:** New to Julia\
**Created:** [January 10, 2020, 2:07am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179 "2020-01-10T02:07:29Z")\
**Posts on this page:** 20\
**Page:** 1

<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:** [January 10, 2020, 2:07am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/1 "2020-01-10T02:07:29Z")

</div>

In as few lines of coherent code as possible show why you love Julia 🙂

I’ll kick this off with a silly example:

```nohighlight
message = Dict( [1,2,3,4] .=> ["why", "is", "julia", "great?"])
result = join(map(x -> message[x], [3, 2, 4] ), " ")
println(result[1:(end-1)])

```

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [January 10, 2020, 2:28am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/2 "2020-01-10T02:28:00Z")

</div>

This is why I love Julia. I just write down the stuff that occurs in my head and it just works!

```julia
prior=Dict()
prior["preg"]=1.0/60.0
prior["notpreg"]=1.0-prior["preg"]

Pr=Dict()
Pr["positive|notpreg"]=0.01
Pr["negative|notpreg"]=1.0-Pr["positive|notpreg"]
Pr["negative|preg"]=0.02
Pr["positive|preg"]=1.0-Pr["negative|preg"]

hypo=Dict()
hypo["test negative AND notpreg"] = Pr["negative|notpreg"] * prior["notpreg"]
hypo["test positive AND notpreg"] = Pr["positive|notpreg"] * prior["notpreg"]
hypo["test negative AND preg"] = Pr["negative|preg"] * prior["preg"]
hypo["test positive AND preg"] = Pr["positive|preg"] * prior["preg"]

Cost=Dict()
Cost["Do nothing|notpreg"] = 0.0
Cost["Do abortion|notpreg"] = 1000.0
Cost["Do nothing|preg"] = 12000.0 * 18.0
Cost["Do abortion|preg"] = 2000.0

Action=Dict()
Action["Do nothing|Test Negative"]= Cost["Do nothing|notpreg"] * hypo["test negative AND notpreg"] + Cost["Do nothing|preg"] * hypo["test negative AND preg"]
Action["Do abortion|Test Negative"]= Cost["Do abortion|notpreg"] * hypo["test negative AND notpreg"] + Cost["Do abortion|preg"] * hypo["test negative AND preg"]
Action["Do nothing|Test Positive"]= Cost["Do nothing|notpreg"] * hypo["test positive AND notpreg"] + Cost["Do nothing|preg"] * hypo["test positive AND preg"]
Action["Do abortion|Test Positive"]= Cost["Do abortion|notpreg"] * hypo["test positive AND notpreg"] + Cost["Do abortion|preg"] * hypo["test positive AND preg"]

for kv in Action
   println(kv[1]," ",kv[2])
end

```

---

<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:** [January 10, 2020, 2:32am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/3 "2020-01-10T02:32:46Z")

</div>

Flexible as Python, easy as Matlab, fast as Fortran, deep as Lisp.

EDIT: now I see you asked for code…

---

<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:** [January 10, 2020, 2:35am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/4 "2020-01-10T02:35:05Z")

</div>

After reading your succinct solution I am inclined to believe you did write Julia code :). No code neccessary!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 10, 2020, 2:38am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/5 "2020-01-10T02:38:28Z")

</div>

Someone opened an issue on one of the DiffEq packages to discuss a few things, and then showed me how they were using the boundary value problem solvers (which wrap pure Julia ODE solvers underneath the hood) perform parameter fitting on a model defined with quaternions (aerospace application) using automatic differentiation. Did it work? Yeah, I didn’t even realize we were that cool, but Julia always surprises you by generating cool new codes… and you get to claim you intended that to happen the whole time. 🙂

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [January 10, 2020, 2:48am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/6 "2020-01-10T02:48:11Z")

</div>

When I wrote PDFP (basically decimal floating point instead of binary floating point) in Mathematica, it looked like this when I used it

```julia
D = PDFP_add[PDFP[1],PDFP_mul[PDFP[2],PDFP[3]]]

```

I convert it to Julia and it look like this when I used it

```julia
using PDFPs

D = PDFP(1) + PDFP(2) * PDFP(3)

```

---

<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:** [January 10, 2020, 2:49am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/7 "2020-01-10T02:49:07Z")

</div>

@StevenSiew Thats how I always felt about it too. Its more like math or something, when you know the rules things just work.

@ChrisRackauckas - I think that’s also how I feel about it. Not that I’ve had an abstract ah-hah like that! But, most other languages I find a lot of my time is spent changing code, or adding more abstractions to do something that seems like what it should be doing already. In Julia I’m usually like “oh I could do it this way or that way or I guess even - that way”. Its so flexible, you don’t have to force things to do things, they are just floating to be put into place.

You can literally feel when you hit wrapper code for python/C/whaterver by how much time is spent in Doc’s, and looking at git repos.

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [January 10, 2020, 2:56am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/8 "2020-01-10T02:56:59Z")

</div>

And matrix operations works too!

Without me even telling julia how to work with PDFP  
I just tell julia that PDFP is a subset of Real

```julia
julia> using PDFPs
[Info: Precompiling PDFPs [top-level]

julia> PDFP_setShowStyle(:tiny)
:tiny

julia> inv([PDFP(1) PDFP(2); PDFP(3) PDFP(4)])
2×2 Array{PDFP,2}:
 -2.000 1.000 
  1.500 -0.5000

```

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [January 10, 2020, 3:28am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/9 "2020-01-10T03:28:02Z")

</div>

This just came to my mind:

```julia
using Dates

# Find the next Friday the 13th that falls on April
tonext(today()) do d
   dayofweek(d) == Fri &&
   day(d) == 13 &&
   month(d) == Apr
end
# 2029-04-13

```

Python’s datetime is horrible to use…

---

<div class="post-metadata">

**Author:** ![00vareladavid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/00vareladavid/32/23521_2.png) [@00vareladavid](https://discourse.julialang.org/u/00vareladavid)\
**Post date:** [January 10, 2020, 4:54am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/10 "2020-01-10T04:54:05Z")

</div>

@Sijun I’m sure it was an honest mistake, but I believe your first sentence violates the community guidelines. Kindly edit your post.

---

<div class="post-metadata">

**Author:** ![Sijun](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Sijun](https://discourse.julialang.org/u/Sijun)\
**Post date:** [January 10, 2020, 4:57am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/11 "2020-01-10T04:57:25Z")

</div>

Oh I see what you mean.

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [January 10, 2020, 6:14am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/12 "2020-01-10T06:14:09Z")

</div>

I code

---

<div class="post-metadata">

**Author:** ![rapus95](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapus95/32/3773_2.png) [@rapus95](https://discourse.julialang.org/u/rapus95)\
**Post date:** [January 10, 2020, 9:02am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/13 "2020-01-10T09:02:34Z")

</div>

Version 1: Just need that running

```julia
struct ReverseDigitsIterator
    num::Int
end
Base.eltype(x::ReverseDigitsIterator) = Int
Base.iterate(x::ReverseDigitsIterator) = reverse(divrem(x.num,10))
function Base.iterate(x::ReverseDigitsIterator, state::Int)
    state==0 && return nothing
    return reverse(divrem(state,10))
end
Base.IteratorSize(::Type{<:ReverseDigitsIterator}) = Base.SizeUnknown()

```

Version 2: More types (e.g. BigInt) & length prediction

```julia
struct ReverseDigitsIterator{T<:Integer}
    num::T
end
Base.eltype(x::ReverseDigitsIterator{T}) where T = T
Base.iterate(x::ReverseDigitsIterator) = reverse(divrem(x.num,10))
function Base.iterate(x::ReverseDigitsIterator{T}, state::T) where T
    state==0 && return nothing
    return reverse(divrem(state,10))
end
Base.length(x::ReverseDigitsIterator) = ndigits(x.num)

```

Version 3: Screw it, I want arbitrary Int base aswell!

```julia
struct ReverseDigitsIterator{T<:Integer, B}
    num::T
    ReverseDigitsIterator(val::T, base::Int=10) where T = new{T, base}(val)
end
Base.eltype(x::ReverseDigitsIterator{T}) where T = T
Base.iterate(x::ReverseDigitsIterator{T,B}) where {T,B} = reverse(divrem(x.num,B))
function Base.iterate(x::ReverseDigitsIterator{T,B}, state::T) where {T,B}
    state==0 && return nothing
    return reverse(divrem(state,B))
end
Base.length(x::ReverseDigitsIterator{T,B}) where {T,B} = ndigits(x.num, base=B)

```

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [January 10, 2020, 9:30am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/14 "2020-01-10T09:30:38Z")

</div>

rapus95 , it took me a while to figure out what you are trying to say

You are saying, it is very easy to go from a function of a very specific type to coding up a function of a very generic arbitrary type

---

<div class="post-metadata">

**Author:** ![rapus95](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rapus95/32/3773_2.png) [@rapus95](https://discourse.julialang.org/u/rapus95)\
**Post date:** [January 10, 2020, 9:47am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/15 "2020-01-10T09:47:10Z")

</div>

Originally I only wanted to post version 1 to show the elegant layout of the iteration interface aswell as its shortness and efficiency:

```julia
julia> reverse_digits_fast(x) = reduce((old,new)->old*10+new,ReverseDigitsIterator(x))
julia> @btime reverse_digits_fast(-23784395623)
  20.942 ns (0 allocations: 0 bytes)
-32659348732

```

but as those timing was fluctuating in a range of a whole single ns(!!! 😛) I decided to implement `length` and also arbitrary types to test BigInt. → Version 2  
Turned out, speed was still fluctuating, but at least I could benchmark BigInt now:

```julia
julia> @btime reverse_digits_fast(big"-2378345987256434395623")
  15.899 μs (458 allocations: 7.84 KiB)
-3265934346527895438732

```

and just out of simple opportunity I added the 3rd version.  
Benchmarking sadly got a bit worse 😕

```julia
reverse_digits_fast(x, base=10) = reduce((old,new)->old*base+new,ReverseDigitsIterator(x, base))
julia> @btime reverse_digits_fast(-23784395623)
  21.664 ns (0 allocations: 0 bytes)
-32659348732

julia> @btime reverse_digits_fast(big"-2378345987256434395623")
  16.599 μs (460 allocations: 7.87 KiB)
-3265934346527895438732

```

At the end I found the ease of incremental coding (eventually even prototyping) worth to be showcased aswell. Also note that there is almost no change in the amount of needed code for those additional features.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [January 10, 2020, 11:48am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/16 "2020-01-10T11:48:37Z")

</div>

Because you can write code that looks like the pseudocode in the paper and still have it turn out 20% faster than Matlab’s internal C code. Even when it’s complicated:

 ![computeft](https://global.discourse-cdn.com/julialang/original/3X/4/f/4f35e0c23cf1f6b004720d7eaa5ae9c449021336.png)

This example involves nested loops of arbitrary dimensionality (see all the `...` in the paper figure).

Citation:  
Maurer, Qi, and Raghavan (2003). A Linear Time Algorithm for Computing Exact Euclidean Distance Transforms of Binary Images in Arbitrary Dimensions. IEEE Transactions on Pattern Analysis and Machine Intelligence (2003). 25: 265-270. (DOI: 10.1109/TPAMI.2003.1177156)

---

<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:** [January 10, 2020, 11:51am UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/17 "2020-01-10T11:51:25Z")

</div>

You know, a lot of languages talk about being “closer to the metal” - and thats a real thing. But, being “closer to the math” is incredibly important for us scientific computing peoples.

Beautiful thing about julia is, it’s close to the metal and it’s close to the math!

---

<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:** [January 10, 2020, 12:06pm UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/18 "2020-01-10T12:06:19Z")

</div>

I never understood the fascination of being “close to the metal”.

_I want to be as far away from the metal as possible_. The metal has billions of transistors (literally), complex instruction sets (that vary by machine), and various arcane structures like layers of caches. I occasionally need to think about these things, but being close all details would be a distraction.

I want to write _generic code_. It’s the job of the language and the compiler to figure out how it works on the metal. The less I need to know about the low-level details the happier I will be.

Julia helps me with this.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [January 10, 2020, 1:08pm UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/19 "2020-01-10T13:08:02Z")

</div>

By using Julia, I hardly ever have any frustrations with programming. The versatility of the type system and the multiple dispatch is so advanced that I can always transform a mathematical idea into implementation. After iterating through evolving design choices, the result is a naturally fitting algebra and computational language with efficient and adaptive representation.

---

<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:** [January 10, 2020, 1:25pm UTC](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179/20 "2020-01-10T13:25:07Z")

</div>

> [@chakravala](#):
>
> By using Julia, I hardly ever have any frustrations with programming.

I seriously envy you 😉 I think that Julia reduced my frustration with programming by a factor of 10, but there is still plenty of it left.

I just finished profiling, benchmarking, and micro-optimizing a medium-sized codebase so that it can run some estimation of an economic model over the weekend. I got a 10x speedup in the end, most of it from a tracking down a noxious type instability that was only activated for AD, but I was seriously considering buying a farm (without internet) and keeping horses.

[Next page](https://discourse.julialang.org/t/in-as-few-lines-as-possible-describe-why-you-love-julia/33179.md?page=2)
