# Why are there all these strange stumbling blocks in Julia?

**URL:** <https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644>\
**Category:** New to Julia\
**Tags:** syntax, python\
**Created:** [January 7, 2023, 6:19pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644 "2023-01-07T18:19:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandjan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sandjan/32/45684_2.png) [@Sandjan](https://discourse.julialang.org/u/Sandjan)\
**Post date:** [January 7, 2023, 6:19pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/1 "2023-01-07T18:19:30Z")

</div>

I have programmed in Python so far and find the Python syntax very convenient. When learning Julia I constantly notice things that I can not understand:  
Why is there no short and simple floor division operator like in Python //?  
Why is the type conversation not as short and sweet as in Python int(“4”)?  
Why do I concatenate strings with \* instead of + ? (that makes no sense to me at all)  
Why does the indexing start with 1 instead of 0 as in most established languages?  
What was wrong with the simple dict syntax of Python? {“Hello”: “World”}  
Why elseif and not elif?

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 7, 2023, 6:27pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/2 "2023-01-07T18:27:54Z")

</div>

> [@Sandjan](#):
>
> Why is there no short and simple floor division operator like in Python //?

There are two: `div` and `÷`, the latter being an infix operator.

> [@Sandjan](#):
>
> Why is the type conversation not as short and sweet as in Python int(“4”)?

Type conversion is completely straightforward: `Int(x)`. If you are talking about parsing strings into numbers, that is not conversion, but parsing, and is, appropriately, called `parse`.

> [@Sandjan](#):
>
> Why do I concatenate strings with \* instead of + ? (that makes no sense to me at all)

This is a big discussion, but string concatenation is more like multiplication than like addition, therefore `*` does in fact make more sense, but it is more unfamiliar to new users.

> [@Sandjan](#):
>
> Why does the indexing start with 1 instead of 0 as in most established languages?

0-based indexing is good in some places, 1-based in other places. I scientific programming 1-based is better, and frankly, IMO, it also makes a lot more sense in general. It’s too much to get into here, though.

> [@Sandjan](#):
>
> What was wrong with the simple dict syntax of Python? {“Hello”: “World”}

Nothing wrong with that syntax, but braces was used for a different purpose in Julia, which was more important. Also, dictionaries are probably less important and less used in Julia than in Python.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [January 7, 2023, 6:32pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/3 "2023-01-07T18:32:54Z")

</div>

I think there is a more fundamental answer than @DNF’s. Julia is not a python clone. It was not intended to be a python clone. Julia takes inspiration from a large number of languages (C, python, lisp, Matlab, Fortran, APL, and probably a bunch of others).

---

<div class="post-metadata">

**Author:** ![Andrea\_Pagnani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrea_pagnani/32/3136_2.png) [@Andrea\_Pagnani](https://discourse.julialang.org/u/Andrea_Pagnani)\
**Post date:** [January 7, 2023, 6:34pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/4 "2023-01-07T18:34:30Z")

</div>

Just to elaborate a bit on why \* and not + for string concatenation. Whereas for most if not all mathematical objects + is symmetric \*, depending on the type, is not (think about matrices products). Obviously string concatenation is not symmetric in general.

---

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [January 7, 2023, 6:49pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/5 "2023-01-07T18:49:05Z")

</div>

> [@Sandjan](#):
>
> Why elseif and not elif?

In my opinion the real question should be “why `elif`?” 🙂

I like Python a lot, but seriously all of these points are just as weird, or even weirder, if you go the opposite direction (except 0-based vs 1-based, to me it’s just indifferent). Julia’s keywords make complete sense: want a function? `function`. Want “else if”? `elseif`

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [January 7, 2023, 6:49pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/6 "2023-01-07T18:49:22Z")

</div>

> [@Sandjan](#):
>
> I have programmed in Python so far

> [@Sandjan](#):
>
> and find the Python syntax very convenient.

Please note that these two clauses are very much correlated. Do you feel like these stylistic choices were obvious to you when first learning Python? Maybe if your first programming experience ever had been with Julia then you would find its choices more convenient and Python’s more cumbersome?

In fact, the implicit statement that these are the _largest_ stumbling blocks you’ve encountered is a testament to me about how relatively seamless it is to move to Julia from Python. Imagine how much more difficult and “inconvenient” you might find it when trying out a language with a steeper initial learning curve, like e.g. OCaml

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [January 7, 2023, 7:25pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/7 "2023-01-07T19:25:54Z")

</div>

Not really trying to pile on, but I just got curious so I compiled a list of string concatenation operators across a bunch of languages. If any of these are incorrect, blame ChatGPT 🙂

Some languages (`C,`, `Lisp`-y ones) do not have infix operators for string concatenation at all.

- `Maple` uses `||`
- `Mathematica` and `Gap` use `<>`
- `Agda`, `Idris`, `Erlang`, `Haskell`, `Elm`, `Zig` all use `++`
- `F#`, `OCaml` use `^`
- `Ada`, `Nim` use `&`
- `Fortran` uses `//`
- `Lua` has `..`
- `Perl` has `.`
- `Smalltalk` has `,`

And of course many popular languages use `+`, including `C++`, `Python`, `Java`, `Go`, `Ruby`, `Typescript`, `Rust`, `Solidity`, `R`, `Swift` etc.

So while it does seem to be true that `Julia` is a bit of an outlier in using specifically `*`, there are plenty of other examples of languages choosing to diverge from `+`.

---

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [January 7, 2023, 7:42pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/8 "2023-01-07T19:42:38Z")

</div>

When I learned Spanish, I found all sorts of quirks that were unintuitive and frustrating. I found it hard to turn my English words into something coherent.

Likewise, when I came from Python to Julia, I frequently had problems that were generally of the form “How to I translate X thing from  
how I’d write it in Python to Julia?”

Why does Spanish have so many verb conjugations? Why does Julia use full length keywords? There are reasons for both, but more importantly, it just is what it is.

The important thing to do when learning any language is to learn the fundamentals well enough that you aren’t thinking in your native tongue and then translating.

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [January 7, 2023, 7:52pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/9 "2023-01-07T19:52:12Z")

</div>

> [@Sandjan](#):
>
> Why does the indexing start with 1 instead of 0 as in most established languages?

I think the more interesting question to ask here is: why do most established languages use zero-based indexing?

When you understand that, and then you learn how modern compilers make it unnecessary, then the question should become: why don’t more modern languages use 1-based indexing instead, as we do naturally in life anyway?

Indexing an `n`-dimensional collection is so much more natural with `1:n` than `0:n-1` or Python’s `0:n` with last element excluded.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [January 7, 2023, 7:54pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/10 "2023-01-07T19:54:49Z")

</div>

Overloading the multiplication operator for concatenation doesn’t make that much sense, I don’t think it’s worth defending. Better than `+` though.

Btw @adienes Where did you get that impressive list?

---

<div class="post-metadata">

**Author:** ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)\
**Post date:** [January 7, 2023, 7:58pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/11 "2023-01-07T19:58:59Z")

</div>

You should probably read [Noteworthy Differences from other Languages · The Julia Language](https://docs.julialang.org/en/v1/manual/noteworthy-differences/#Noteworthy-differences-from-Python).

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [January 7, 2023, 8:09pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/12 "2023-01-07T20:09:50Z")

</div>

> [@jar1](#):
>
> Btw @adienes Where did you get that impressive list?

I asked ChatGPT to "please translate Python code ‘a’ + ‘b’ into language `XYZ` " 😅

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 7, 2023, 8:11pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/13 "2023-01-07T20:11:15Z")

</div>

> [@Andrea\_Pagnani](#):
>
> Just to elaborate a bit on why \* and not + for string concatenation. Whereas for most if not all mathematical objects + is symmetric \*, depending on the type, is not (think about matrices products). Obviously string concatenation is not symmetric in general.

The word you are looking for is “commutative”, I believe.

This is a Julia FAQ: [Why does Julia use `*` for string concatenation? Why not `+` or something else?](https://docs.julialang.org/en/v1/manual/faq/#Why-does-Julia-use-*-for-string-concatenation?-Why-not-or-something-else?)

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [January 7, 2023, 8:19pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/14 "2023-01-07T20:19:20Z")

</div>

> [@DNF](#):
>
> > [@Sandjan](#):
> >
> > Why is there no short and simple floor division operator like in Python //?
> 
> There are two: `div` and `÷`, the latter being an infix operator.

Except that `div` is not floor division, `fld` is. This is one of two points where I’m jealous that Python has got it right but Julia hasn’t.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [January 7, 2023, 8:28pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/15 "2023-01-07T20:28:20Z")

</div>

Why is that wrong?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [January 7, 2023, 8:59pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/16 "2023-01-07T20:59:11Z")

</div>

Because having the rounding change direction when the first argument passes zero is bug trap. Maybe not that much for the division itself but when it comes to the corresponding remainder operator, `%`, it has (in Julia terminology) `rem` semantics in Julia and `mod` semantics in Python. A frequent use of the remainder is to model cyclic behaviors and having that suddenly switch sign is a bug waiting to happen. (If you are guaranteed that both arguments are positive, `mod` or `rem` doesn’t matter, which covers at least 90% of the uses of `%`. The real danger is when you thought they both were but there turns out to be a corner case where the first argument becomes negative. Or you later change the code and forgot the assumption.)

---

<div class="post-metadata">

**Author:** ![mstewart](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@mstewart](https://discourse.julialang.org/u/mstewart)\
**Post date:** [January 7, 2023, 10:42pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/17 "2023-01-07T22:42:17Z")

</div>

I like `*`. Strings with concatenation do form a noncommutative semigroup, for which the operation would conventionally be written as multiplication. Starting out with Julia, my reaction was along the lines of “Nice choice. Good call not using `+`.” I assumed that someone involved in that choice likes algebra and was persistently annoyed at seeing `+` used for something noncommutative. But I’m sure there is something to be said for not trying to relate string operations to algebra and going with a special operator. I’d imagine `*` does look odd to a lot of new users.

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [January 7, 2023, 10:42pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/18 "2023-01-07T22:42:24Z")

</div>

Huh, I thought it was because concatenation is distributive over [alternation](https://en.m.wikipedia.org/wiki/Alternation_(formal_language_theory)).

String concatenation and regular expression concatenation are consistent:

```julia
julia> match(r"abc"*r"def", "abc"*"def")
RegexMatch("abcdef")

```

Interestingly though, we don’t have a regexp alternation operator implemented:

```julia
julia> r"abc" * r"def" # concatenation ok
r"(?:abc)(?:def)"

julia> r"abc" + r"def" # alternation not implemented
ERROR: MethodError: no method matching +(::Regex, ::Regex)

```

---

<div class="post-metadata">

**Author:** ![fph](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fph/32/17159_2.png) [@fph](https://discourse.julialang.org/u/fph)\
**Post date:** [January 7, 2023, 11:13pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/19 "2023-01-07T23:13:42Z")

</div>

Are there any practical differences between using `+` and `*` for string concatenation, apart from the abstract argument that “it communicates the right algebraic properties”? For instance, certain generic implementations that work for strings, too?

---

<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:** [January 7, 2023, 11:16pm UTC](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644/20 "2023-01-07T23:16:50Z")

</div>

> [@fph](#):
>
> For instance, certain generic implementations that work for strings, too?

Try `"hello" ^ 5`

[Next page](https://discourse.julialang.org/t/why-are-there-all-these-strange-stumbling-blocks-in-julia/92644.md?page=2)
