# My Brain Is Hard-Wired Against ==; Help Me, Julia

**URL:** <https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532>\
**Category:** New to Julia\
**Tags:** question, syntax\
**Created:** [June 25, 2021, 6:16am UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532 "2021-06-25T06:16:33Z")\
**Posts on this page:** 18\
**Page:** 5

<div class="post-metadata">

**Author:** ![viraltux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/viraltux/32/15236_2.png) [@viraltux](https://discourse.julialang.org/u/viraltux)\
**Post date:** [July 2, 2021, 2:58pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/83 "2021-07-02T14:58:17Z")

</div>

> [@DNF](#):
>
> Multiple dispatch has to do with the types used, not with the context.

In a wide sense the type is also “context”, a==b has a boolean type, which provides context in this sense.

> [@DNF](#):
>
> But how would the compiler know whether the user deliberately used assignment, or _intended_ to use comparison, but misspelled it?

I am actually wondering, I am not sure it’s possible, I am not an expert in compilers but I can’t imagine a normal situation where a compiler could not decide out of context what to do or, at the very least, throw a ambiguity error, could you provide an example of such impossibility in Julia?

---

<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:** [July 2, 2021, 3:19pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/84 "2021-07-02T15:19:01Z")

</div>

> [@viraltux](#):
>
> In a wide sense the type is also “context”, a==b has a boolean type, which provides context in this sense.

But you are not talking about deciding this based on types, as far as I can tell. Types are a kind of context, but context is not a kind of type.

> [@viraltux](#):
>
> could you provide an example of such impossibility in Julia?

The example we are discussing in this thread. I’m not talking about what is possible for a compiler, I a technical sense, but from a philosophical standpoint. I’m saying there is no way to tell if the user intended something other than what was written here. Throwing an ambiguity error, or trying to ‘interpret’ and change the meaning of

```julia
if (x = a) 

```

would be bad, because the user could intend this exact thing, and it makes sense to do, even if it’s less common.

---

<div class="post-metadata">

**Author:** ![viraltux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/viraltux/32/15236_2.png) [@viraltux](https://discourse.julialang.org/u/viraltux)\
**Post date:** [July 2, 2021, 3:24pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/85 "2021-07-02T15:24:48Z")

</div>

> [@DNF](#):
>
> ```julia
> if (x = a) 
> 
> ```
> 
> would be bad, because the user could intend this exact thing, and it makes sense to do, even if it’s less common.

I think this case is already handled by context in Julia when not a bool:

```julia
julia> if (x=a)
       print(1)
       end
ERROR: TypeError: non-boolean (Int64) used in boolean context

```

and if `x` and `a` are both **bool** then the **if** could set the context for an equality test, which is not what Julia does, but it could.

> [@DNF](#):
>
> Types are a kind of context, but context is not a kind of type.

Well, this context is kind of Boolean.

```julia
ERROR: TypeError: non-boolean (Int64) used in boolean context

```

But there are also other problematic cases like:

`a=b=c` vs `a=(b=c)`

The first case assigns `c` to `b` and `a` and so does the second case even if the intent is to assign a **bool** to `a`. So if not impossible in other languages I don’t think it’s gonna happen in Julia… However, I still don’t see insurmountable problems for a compiler to set rules for context, at least in those two basic examples.

---

<div class="post-metadata">

**Author:** ![heetbeet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heetbeet/32/20958_2.png) [@heetbeet](https://discourse.julialang.org/u/heetbeet)\
**Post date:** [July 2, 2021, 10:15pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/86 "2021-07-02T22:15:48Z")

</div>

What would the context of

```julia
if (a=b) < 5

```

then be? VBA does what you are proposing (it uses = for assignment and for equality checking), but it’s syntax is very poor and constrained. You can special-case all the places where one choice is made over the other, but that just makes things inconsistent and takes away some of the expressionness of the language.

Also, what about

```julia
a = b = (c = 3)

```

---

<div class="post-metadata">

**Author:** ![viraltux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/viraltux/32/15236_2.png) [@viraltux](https://discourse.julialang.org/u/viraltux)\
**Post date:** [July 3, 2021, 7:21am UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/87 "2021-07-03T07:21:26Z")

</div>

If we go down the path of actually just using `=` then we need to agree on some convention to break ambiguities. For instance, let’s agree that in a Boolean context `=` is always an equality test, and in your example

> [@heetbeet](#):
>
> ```julia
> if (a=b) < 5
> 
> ```

(a=b) would be an equality test, and if we meant it to be an assignment then we do:

```julia
a=b
if a<5

```

For your second example:

> [@heetbeet](#):
>
> `a = b = (c = 3)`

Just like we use parenthesis to adjust conventions in expression like `a*(b+c)` we can do likewise here and establish something like “in a non Boolean context = is an assignment unless between parenthesis”. Then

`a = b = c = 3` assigns 3 to a,b and c  
`a = b = (c=3)` assigns the bool (c=3) to a and b

Let me say that I am not really pushing for a change in Julia, I am just curious about if using `==` is more of a historical thing we do because pioneers did it and we go along with it, or if there is a deeper technical reason for it.

---

<div class="post-metadata">

**Author:** ![doit](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@doit](https://discourse.julialang.org/u/doit)\
**Post date:** [July 3, 2021, 12:09pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/88 "2021-07-03T12:09:59Z")

</div>

At what point does the cognitive load of interpreting what `=` might mean in whatever context become greater than simply remembering and applying different operators, however they may look? It is arguably easier (and more efficient) for humans to parse different symbols.  
Then, this discussion becomes one of which symbols to use and that is arguably a subjective matter and thus comes down to personal preference or your willingness to learn and apply new syntax.

Julia is already great insofar that it allows you to define your own operators. It was proposed by OP and demonstrated later that you can personally define whatever unicode alternative to `==` that you wish. It is thus strictly not necessary to fix this operator but let anybody choose according to their own personal preference. (Differing styles really become only a problem in projects with lots of contributers. But they have to discuss style-guides anyway.)

Albeit, I’m not even sure how exchanging `==` for `⩵` is going to help OP in any way. If they can’t remember to use `==`, why would they magically remember `⩵`? They even look exactly the same in this specific case… genuinely curious to hear the thought process behind this.

And to be clear, I have stake in this discussion. I would love to use `**` instead of `^` (albeit for completely esthetic reasons) but in this very specific case Julia actually actively disallows me to define `**`. Do I ask, let alone demand anything? Even for 2.0? No, I understand why this was done and Julia has the syntax it has, like any other language. (The “hardwire issue” is of course a different one. This is not meant as a direct comparison.)

---

<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:** [July 3, 2021, 1:02pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/89 "2021-07-03T13:02:48Z")

</div>

Irrespective of how good or bad `==` is (I’m pro), please never write `if (flag = booleanfunction())`. Even if it’s intentional, you are just making the code harder to interpret. For what, a single line less of code? Why don’t we just go back to the `C` hacks like `while(*a++ = *b++)`? Contrary to popular belief this is not good programming, because it’s impossible to read.

---

<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:** [July 3, 2021, 3:50pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/90 "2021-07-03T15:50:25Z")

</div>

> [@doit](#):
>
> I would love to use `**` instead of `^`

Wooow, what? That’s interesting. Would you mind explaining? I always found this to be one of the most bizarre things in python.

The `^` is almost universally used as the superscript/exponentiation symbol, to the point where I’m pretty sure most people who know nothing of maths or programming will recognize it (just think of ‘m^2’ or ‘E=mc^2’).

So I always found the decision in python utterly confounding. But, you actually prefer this? What’s the story?

(To ramble on: the `**` is particularly annoying in math-heavy code with lots of exponentiation, since it’s more verbose, and less visually distinct from multiplication).

---

<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:** [July 3, 2021, 4:04pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/91 "2021-07-03T16:04:43Z")

</div>

I just had a thought: were you talking about string concatenation?

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [July 3, 2021, 6:37pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/92 "2021-07-03T18:37:25Z")

</div>

You could take the Python route of disallowing

```julia
if (a = b)

```

and instead requiring the more visually distinctive walrus operator, which is also much harder to mistype:

```julia
if (a := b)

```

This wouldn’t really affect many people’s programs, I don’t think, but it would definitely avoid bugs.

---

<div class="post-metadata">

**Author:** ![viraltux](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/viraltux/32/15236_2.png) [@viraltux](https://discourse.julialang.org/u/viraltux)\
**Post date:** [July 3, 2021, 7:04pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/93 "2021-07-03T19:04:53Z")

</div>

> [@doit](#):
>
> At what point does the cognitive load of interpreting what `=` might mean in whatever context become greater than simply remembering and applying different operators, however they may look? It is arguably easier (and more efficient) for humans to parse different symbols.

Mathematicians have been using **=** and switching its context with symbols like **∀** for hundreds of years, none of them seemed to ever had a cognitive need for **==**

> [@doit](#):
>
> Do I ask, let alone demand anything? Even for 2.0? No

With all due respects, I find this comment unwelcoming and discourages discourse

---

<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 4, 2021, 4:03pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/95 "2021-07-04T16:03:54Z")

</div>

> If they can’t remember to use ==, why would they magically remember ⩵?

It’s not that I don’t know the proper operator or syntax – it’s that a slip is made when the right pinky finger goes to type == and only types =.

A Unicode alias for == would be entered as, say, \ie – so pinky never hits = key and no slip is possible. Currently already type \ne for not equals.

---

<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 4, 2021, 4:08pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/96 "2021-07-04T16:08:09Z")

</div>

\*\* originated with FORTRAN I believe. Many languages use it.

Neither \*\* nor ^ look great in long formulas.

---

<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:** [July 4, 2021, 4:14pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/97 "2021-07-04T16:14:03Z")

</div>

> [@blackeneth](#):
>
> the right pinky finger goes to type == and only types =

I don’t understand that at all. I could empathize with the version where your brain goes “equals” so your fingers go `=`, which a unicode alias would do nothing against. I really can’t imagine _knowing_ to write two signs and accidentally just writing the one. Do you often misspell other double characters?

---

<div class="post-metadata">

**Author:** ![ParadaCarleton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paradacarleton/32/20005_2.png) [@ParadaCarleton](https://discourse.julialang.org/u/ParadaCarleton)\
**Post date:** [July 4, 2021, 4:19pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/98 "2021-07-04T16:19:44Z")

</div>

> Albeit, I’m not even sure how exchanging `==` for `⩵` is going to help OP in any way. If they can’t remember to use `==` , why would they magically remember `⩵` ? They even look exactly the same in this specific case… genuinely curious to hear the thought process behind this.

I’m going to come clean here: I have a Unicode addiction. If I have the option to use either Unicode or ASCII, I will always use Unicode, and I will never forget. I don’t understand why my brain works this way, but it does, and we’ll probably need a crack team of brain surgeons to figure both me and the OP out.

---

<div class="post-metadata">

**Author:** ![jessymilare](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jessymilare/32/13750_2.png) [@jessymilare](https://discourse.julialang.org/u/jessymilare)\
**Post date:** [July 4, 2021, 8:37pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/99 "2021-07-04T20:37:35Z")

</div>

> [@viraltux](#):
>
> Let me say that I am not really pushing for a change in Julia, I am just curious about if using `==` is more of a historical thing we do because pioneers did it and we go along with it, or if there is a deeper technical reason for it.

IMO, the technical reason is: in Julia, ANY expression is valid after an `if`. If `=` was to be treated differently, then what about other operators, keywords and syntaxes (e.g. `let`, `begin`, `try ... catch ... end`)?

Of course you could argue that only a few expressions should be used in test context, but a whole new set of rules would have to be made.

---

<div class="post-metadata">

**Author:** ![jessymilare](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jessymilare/32/13750_2.png) [@jessymilare](https://discourse.julialang.org/u/jessymilare)\
**Post date:** [July 4, 2021, 8:43pm UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/100 "2021-07-04T20:43:53Z")

</div>

> [@viraltux](#):
>
> Mathematicians have been using **=** and switching its context with symbols like **∀** for hundreds of years, none of them seemed to ever had a cognitive need for **==**

A more appropriate comparison, IMO, would be formal languages. Usually Math articles don’t use formal language to prove theorems, but programming languages are formal languages, even if they are made more complex in order to be more human-readable.

---

<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 5, 2021, 1:38am UTC](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532/101 "2021-07-05T01:38:23Z")

</div>

It is explained [here](https://discourse.julialang.org/t/the-hegemony-of-must-end-welcome-the-upstart/63605)

[Previous page](https://discourse.julialang.org/t/my-brain-is-hard-wired-against-help-me-julia/63532.md?page=4)
