# Best practice for avoiding line break bugs in long expressions

**URL:** <https://discourse.julialang.org/t/best-practice-for-avoiding-line-break-bugs-in-long-expressions/7475>\
**Category:** General Usage\
**Created:** [December 3, 2017, 12:53pm UTC](https://discourse.julialang.org/t/best-practice-for-avoiding-line-break-bugs-in-long-expressions/7475 "2017-12-03T12:53:53Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![blackeneth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blackeneth/32/10353_2.png) [@blackeneth](https://discourse.julialang.org/u/blackeneth)\
**Post date:** [July 15, 2021, 7:34am UTC](https://discourse.julialang.org/t/best-practice-for-avoiding-line-break-bugs-in-long-expressions/7475/21 "2021-07-15T07:34:34Z")

</div>

Thanks for the pointer to `logsumpexp.`

Would you compute it in the log space and then exp() it at the end?

Not sure how I would apply [logsumexp()](http://www.nowozin.net/sebastian/blog/streaming-log-sum-exp-computation.html) in this case, as all the terms have multiplicative factors against the exp() functions.

Would appreciate your coaching on this topic.

---

<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:** [July 15, 2021, 7:57am UTC](https://discourse.julialang.org/t/best-practice-for-avoiding-line-break-bugs-in-long-expressions/7475/22 "2021-07-15T07:57:08Z")

</div>

I would try to keep everything in logs, if possible. You can use

a e^b = e^{log(a) + b}

for the coefficients.

---

<div class="post-metadata">

**Author:** ![jt1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jt1/32/38331_2.png) [@jt1](https://discourse.julialang.org/u/jt1)\
**Post date:** [November 5, 2021, 12:42pm UTC](https://discourse.julialang.org/t/best-practice-for-avoiding-line-break-bugs-in-long-expressions/7475/23 "2021-11-05T12:42:15Z")

</div>

Honestly, I strongly disagree with this not throwing an error.  
Splitting equations in multiple lines and starting each line with a + or - is so prevalent (eg. see almost any long equation in a paper) that it should throw an error if it is done  
Imo the fact that writing a long equation in julia in the most logical way (starting with + or -) is a silent bug is very wrong.

- “Your editor should see this” is noncence imo because afaik julia doesn’t care about indentation (you can write the inner part of a function on the same indentation as the outer part). My editor doesn’t warn me here.
- “You shouldn’t write such long equations anyway” is also noncence imo because long equations are something naturally happening in for example dynamic equations of physical systems. Why should they be avoided? Atleast an error should be thrown when it is done wrongly.

(not trying to diss here on julia, I strongly love julia)

---

<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:** [November 15, 2021, 6:23am UTC](https://discourse.julialang.org/t/best-practice-for-avoiding-line-break-bugs-in-long-expressions/7475/24 "2021-11-15T06:23:04Z")

</div>

Consider this in a repl section:

```julia
julia> a = 5
5
julia> + 3 - 1
2
julia> println(a)
5

```

Now write it in a script

```julia
a = 5
       + 3 - 1
println(a)

```

Do you want this to print `7`? That adds a lot of parser complexity, and makes the code run differently in repl and as a script.

An editor warning is the correct level for something like this.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 15, 2021, 8:06am UTC](https://discourse.julialang.org/t/best-practice-for-avoiding-line-break-bugs-in-long-expressions/7475/25 "2021-11-15T08:06:51Z")

</div>

That is what brackets are also made for, for grouping:

```julia
a = (5
   + 3 - 1)
println(a)

```

Do not understand why @dfdx’s answer above was not marked as the solution.

---

<div class="post-metadata">

**Author:** ![Lilith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lilith/32/27492_2.png) [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Post date:** [December 7, 2021, 12:52am UTC](https://discourse.julialang.org/t/best-practice-for-avoiding-line-break-bugs-in-long-expressions/7475/26 "2021-12-07T00:52:49Z")

</div>

I use Juno with Atom, and

```julia
x = 5 + 7
  + 8 + 9
  - 1 * 2
println(x)

```

Does not produce an editor warning. Should this be reported as an issue with Juno?

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [December 7, 2021, 4:22pm UTC](https://discourse.julialang.org/t/best-practice-for-avoiding-line-break-bugs-in-long-expressions/7475/27 "2021-12-07T16:22:30Z")

</div>

No, Juno is in maintenance mode. This is technically valid code… and I tried it in VS Code. It has a linter, I think (enabled by default?), and seems it would be an excellent addition to it. Rather file an an issue at VS Code and/or (its?) linter? Link many other sections, the one on it in the docs is empty:

[https://www.julia-vscode.org/docs/stable/userguide/linter/#Linter](https://www.julia-vscode.org/docs/stable/userguide/linter/#Linter)

[Previous page](https://discourse.julialang.org/t/best-practice-for-avoiding-line-break-bugs-in-long-expressions/7475.md?page=1)
