# Indentation and the end statement

**URL:** https://discourse.julialang.org/t/indentation-and-the-end-statement/74076
**Category:** New to Julia
**Created:** [January 5, 2022, 9:05am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076 "2022-01-05T09:05:34Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![TheGrowingPlant443](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thegrowingplant443/32/32431_2.png) [@TheGrowingPlant443](https://discourse.julialang.org/u/TheGrowingPlant443)
#### Post date: [January 5, 2022, 9:05am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/1 "2022-01-05T09:05:34Z")

</div>

My surgestion is that you can some how be able to switch to an indentation version of Julia at the top of your document. So you both have a version with end statement and a version without. I know the developers of julia wanted the notation of end statement to be more like MATLAB and I agree with them on their points. But I still prefer pythons indentation when their points like copy pasting and presenting are not met. I know there have been many others before me who have raised this question but I thought I would write about my take on it.

```julia
using indentation
for i in 1:10
   if i < 5
      print(i)
   else
      print(i*i)

function f(x,y)
   return(x+y) 
# The return statement functions just like python

```

The same notion of while loops and struct ect. so the end statement becomes the indentation instead to make it more readble and you don’t have to write end statement.

---

<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 5, 2022, 9:20am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/2 "2022-01-05T09:20:08Z")

</div>

Are you sure you want to create you totally own syntax that diverges from every one else’s? How does this impact collaboration and code sharing?

But actually the worst thing that could happen was if this were allowed, and the `end`-less syntax became popular, causing a schism in the language. The whitespace sensitivity of Python is imo its single worst feature, and I would be very unhappy for it to become a Julia feature.

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [January 5, 2022, 9:38am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/3 "2022-01-05T09:38:16Z")

</div>

I don’t mind Python’s use of whitespaces or Julia’s use of `end`, but I would really dislike having both in the same language.

---

<div class="post-metadata">

### Author: ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)
#### Post date: [January 5, 2022, 12:38pm UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/4 "2022-01-05T12:38:39Z")

</div>

I suspect this applies here, even though the proposal is for an option rather than a breaking change:

> [@PSA: Julia is not at that stage of development anymore](https://discourse.julialang.org/t/psa-julia-is-not-at-that-stage-of-development-anymore/44872):
>
> You heard about this brand new exciting programming language called Julia and have some suggestions for how it should work. Wonderful! We’re happy to have you here and help you learn the language and listen to your ideas! However, please be aware that “new” is a relative term. Yes, Julia is newer than, say, C, which was first created in 1972 and standardized in 1989. It is not, however, new in the sense that it is still being freely designed and changed in arbitrary ways. Julia development start…

---

<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 5, 2022, 12:59pm UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/5 "2022-01-05T12:59:35Z")

</div>

> [@DNF](#):
>
> The whitespace sensitivity of Python is imo its single worst feature, and I would be very unhappy for it to become a Julia feature.

It’s a [tradeoff with some good and bad points](https://groups.google.com/g/julia-users/c/lOmwPvOKc-o/m/sAboTUTEfRoJ), but in any case it’s something that the Julia developers decided against early in the language’s development and it doesn’t make sense to revisit that decision now.

(The Julia developers also rejected my suggestion to [remove all vowels](https://groups.google.com/g/julia-users/c/bf0m6XbTDow/m/hpm66b-efgcJ) from the language to improve terseness.)

---

<div class="post-metadata">

### Author: ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)
#### Post date: [January 5, 2022, 1:55pm UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/6 "2022-01-05T13:55:31Z")

</div>

I don’t see any real arguments _for_ indentation sensitivity there. In fact, the one argument (“`end` is 3 characters”) is easily countered by "` ` is 4 characters".

I want to extend some praise here for Julia developers making the sensible choice - this is one of the reasons I have never wanted to learn Python.

---

<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 5, 2022, 2:12pm UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/7 "2022-01-05T14:12:32Z")

</div>

> [@gustaphe](#):
>
> I don’t see any real arguments _for_ indentation sensitivity there.

The arguments for indentation sensitivity, as I understand it, are not just saving typing; they are mainly (a) eliminating the “visual noise” of `end` statements to enhance readability (whereas whitespace introduces no “noise”), (b) forcing people to follow good indentation practices, and (c) eliminating [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) bugs due to indentation not matching the syntactic blocks. You can find plenty of arguments online in favor of indentation-sensitivity on these grounds, e.g. [here](https://unspecified.wordpress.com/2011/10/18/why-pythons-whitespace-rule-is-right/) and [here](https://medium.com/swlh/whitespace-ive-got-a-blank-space-449f8140011) and [this stackexchange thread](https://softwareengineering.stackexchange.com/questions/313034/why-should-a-language-prefer-indentation-over-explicit-markers-for-blocks).

There are also a lot of downsides, of course … we don’t need to re-hash the disadvantages here!

I’m pretty happy with Julia’s choice, personally, but this kind of surface-syntax issue is the least interesting question for me when comparing languages. If you wrote a “Pyulia” front end for Julia with significant indentation instead of `end` statements, it would still be essentially the same language, albeit a variant that seems unlikely to gain much traction at this point.

---

<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 5, 2022, 5:21pm UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/8 "2022-01-05T17:21:12Z")

</div>

> [@stevengj](#):
>
> (a) eliminating the “visual noise” of `end` statements to enhance readability (whereas whitespace introduces no “noise”)

I tend to think of it as ‘signal’, not ‘noise’. It carries useful information. I wouldn’t say that whitespace isn’t noisy. It certainly looks disturbing to me.

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [January 5, 2022, 5:38pm UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/9 "2022-01-05T17:38:31Z")

</div>

What about an editor plugin? In the situations where indentation matches and the `end` is on a line by itself, you could just hide the line. Editors can currently also automatically insert `end`s and indent.

That seems far more tractable — then it’s not a dialect of Julia or even an option. It’s a display option for people who want it. Your code would still be completely readable by plain old Julia (even older versions) and others.

I don’t want it, so I won’t be driving this forward, but it seems like an interesting possibility.

---

<div class="post-metadata">

### Author: ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)
#### Post date: [January 5, 2022, 5:40pm UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/10 "2022-01-05T17:40:19Z")

</div>

Fun fact: Juno displays `end` with lower opacity for this reason  
 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/2/e/2edf81eea99a3781c91e5bc17e486b60d4c95211.png)

---

<div class="post-metadata">

### Author: ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)
#### Post date: [January 6, 2022, 2:47am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/11 "2022-01-06T02:47:21Z")

</div>

My [Julia color theme](https://marketplace.visualstudio.com/items?itemName=cameronbieganek.julia-color-themes) for VS Code also colors the `end` keyword a darker color:

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

---

<div class="post-metadata">

### Author: ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)
#### Post date: [January 6, 2022, 8:36am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/12 "2022-01-06T08:36:27Z")

</div>

```julia
begin print("hi"); print("is this still in the block?");
println("What about me"?");

```

```julia
@sync @spawn ()->sleep(5) && println("a"); @spawn sleep(2); println("b"); 

```

---

<div class="post-metadata">

### Author: ![NiclasMattsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/niclasmattsson/32/21988_2.png) [@NiclasMattsson](https://discourse.julialang.org/u/NiclasMattsson)
#### Post date: [January 6, 2022, 9:20am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/13 "2022-01-06T09:20:50Z")

</div>

As far as I know I don’t suffer from OCD. But to me the lack of explicit end block markers in Python still triggers an OCD-like feeling of **wrongness**. Indented code just hangs in the sky, unsupported, in much the same way that bricks don’t. It’s quite disturbing in a vague way (sort of like reading text with unclosed brackets.

---

<div class="post-metadata">

### Author: ![paulmelis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paulmelis/32/35063_2.png) [@paulmelis](https://discourse.julialang.org/u/paulmelis)
#### Post date: [January 6, 2022, 9:48am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/14 "2022-01-06T09:48:42Z")

</div>

> [@NiclasMattsson](#):
>
> As far as I know I don’t suffer from OCD. But to me the lack of explicit end block markers in Python still triggers an OCD-like feeling of **wrongness**. Indented code just hangs in the sky, unsupported, in much the same way that bricks don’t. It’s quite disturbing in a vague way (sort of like reading text with unclosed brackets.

Interesting, for me Python code is exactly right, as it visually shows the logical tree-structure of code (class, method, blocks, etc). Having extra brackets/keywords to close blocks just seems superfluous to me 🙂

---

<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 6, 2022, 1:35pm UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/15 "2022-01-06T13:35:59Z")

</div>

That’s a very assymmetrical tree, with branches hanging on one side, and tilting dangerously.

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [January 6, 2022, 1:53pm UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/16 "2022-01-06T13:53:15Z")

</div>

To me, the `end` statement represents formality and is part of the grammar of programming Sure, you can read things just fine without it, and we type less if we drop it, but our code is simply incomplete without it Much like this post is totally readable, yet contains no `end` of sentence markers (periods)

---

<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 8, 2022, 10:58am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/17 "2022-01-08T10:58:40Z")

</div>

If Julia and Python were LISPs

Julia:

```julia
((() () ()) (() ()) ())

```

Python:

```julia
( ( ( ( ( ( ( ( (

```

---

<div class="post-metadata">

### Author: ![RogerP](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rogerp/32/17496_2.png) [@RogerP](https://discourse.julialang.org/u/RogerP)
#### Post date: [January 10, 2022, 8:15am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/18 "2022-01-10T08:15:18Z")

</div>

The end of the end statement would be the end for me. After all, where would it end?

(My main reason for disliking Python before I’d even heard of Julia.)

@TheGrowingPlant443 Obvs. Making white space a big part of Julia’s syntax would create a new and incompatible language. Just write a plugin for VSCode that _displays_ the code with Python indentation and with no end in sight. Then you can be happy without mucking up Julia. 😀 😀

---

<div class="post-metadata">

### Author: ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)
#### Post date: [January 10, 2022, 8:57am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/19 "2022-01-10T08:57:04Z")

</div>

> [@stevengj](#):
>
> (b) forcing people to follow good indentation practices,

I think this is a very important point - code which is incorrectly idented (i.e. where the identation does not match the actual code blocks) is very difficult to read and error-prone.

Is there a linter or autoformatter available in Julia which checks / enforces it?

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [January 10, 2022, 8:59am UTC](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076/20 "2022-01-10T08:59:29Z")

</div>

There is

[https://github.com/domluna/JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl)

but I haven’t tried it (although I think the VSCode extension was planning to switch to this at some point, so I might be using it unknowingly…)

[Next page](https://discourse.julialang.org/t/indentation-and-the-end-statement/74076.md?page=2)
