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

Not at all. Just \ will drive me crazy. I always confused it with /. Furthermore, at least three keystrokes (autocomplete considered) are needed to type the left arrow. Maybe you have a better way?

1 Like

I am more interested to see a well designed operator for explicitly carrying out float number comparison.

If ≈ isn’t good enough then let’s talk about it (in a separate thread please).

1 Like

I was kidding, hence the winking emoji.

2 Likes

I know Julia is not going to change, and I do not expect it to.
I learned Pascal early on (on punched cards) The assignment operator is :=
I still think ‘becomes equal to’ when writing code

The comparison operator could be ?=
I would read that as ‘query equals’

4 Likes

If it’s been 20 years, how much sleep do I need?

2 Likes

Perhaps alternate back and forth between an hour of programming and an hour of deep, meditative trance. :slight_smile:

One style I have seen to reduce the problem is to flip the sides of the equality test. That often places something that cannot be assigned to and gives an error.

julia> a = 20
20

julia> 0 == a
false

julia> 0 = a
ERROR: syntax: invalid assignment location "0" around REPL[3]:1
8 Likes

Shoot, usually “try turning it off and on again” is enough to fix these things, I’m out of ideas!

2 Likes

To join the bikeshed, I think linter integration into IDEs will be the most value for effort mitigation for this. Maybe JET.jl can handle it - try it out!

Every LanguageServer.jl compatible editor already emits a warning in this case, as demonstrated upthread.

4 Likes

Ah, I think I just scrolled past that. Awesome!

My brain is hard-wired against = copying by reference.
Why do we need to use copy() every time we want to copy the content of an object.
I think most of the time users want to copy the content, not create references.
= should be the default way to copy object content.

1 Like

The unfortunate thing is that negation has become inconsistent because of this choice. The negation of most operations are

!<op>

but the negation of == is !=. And this is blocking a feature I’d really like to see: ! for infix operators · Issue #25512 · JuliaLang/julia · GitHub

A possible way out would be to have !== and !===, but they would be really long. Also, it’s of course never going to happen.

Assignment as := would be wonderful, and not too long at all.

2 Likes

What about using espanso or just remap a key (that you don’t press with your pinky) to input == ?

I usually think similarly, but not in Julia where I’ve gotten used to another way of doing things. My experience with Matlab made me very happy with copy-on-write, but now Instead of

b = copy(a)
b[someelement] = newvalue

I’ve gradually learned to copy and mutate simultaneously, e.g. using map, generators, and broadcasting. Quick anonymous functions make this easy. I don’t even do much piping |> but that can even be more concise. It’s nice to borrow some approaches from functional programming without having to go all the way.

2 Likes

Yes, those are called Yoda Conditions and were mentioned before in this thread.

1 Like

Hi blackeneth,

People do seem to have strange names on the internet. Anyway, I was just wondering how old you are? I’m 68 and this really isn’t a big problem. There are many languages that do the same thing, it’s not special to Julia.

I can offer you a simple suggestion which may help. PostIt notes, just stick one to your monitor with:

= for assignment
== for test

After a while, I’m sure you will break your habit. It’s like most things “practice makes perfect” or in this case “improves your memory”. But, one thing that won’t help is to get overstressed by it. Relax, have a drink and just go “oops did it again no big deal”.

Kindest regards

Jeremy

6 Likes

I dislike ← in R almost as much as I do := in Pascal…

3 Likes

I agree: “==” is an abomination upon mankind. I once spent six months trying to find why an error recovery routine blew up in a C program. It was because a programmer had written “if (a = b) { … }” which always resolved as true.

I can’t tell you how many times I looked at that code and saw what I thought rather than what was actually being done.

3 Likes