jesseduffield / jesseduffield/OK

equals example is dangerous and confusing

Open
#15 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
624
Forks
22
PR merge metrics
No merged PRs in 30d

Description

As you know, most modern programming languages contain at least two and sometimes three equals operators. This is because value equality and identity comparison are type specific and open up a whole can of worms.

It therefore surprised me when you suggested defining equals as:

```
let equals = fn(a, b) {
let x = a >= b;
let y = lazy b >= a;
return x && y;
}
```

This seems to over-complicate the issue by either assuming generics or duck typing? Generics are scary!

May I suggest instead defining equals for each type independently as follows:

```
let equals = fn(a : int, b: int) {
let x = a >= b;
let y = lazy b >= a;
return x && y;
}
```

```
let equals = fn(a : string, b: string) {
let x = a >= b;
let y = lazy b >= a;
return x && y;
}
```

```
let equals = fn(a : char, b: char) {
let x = a >= b;
let y = lazy b >= a;
return x && y;
}
```

```
let equals = fn(a : Person, b: Person) {
let x = a >= b;
let y = lazy b >= a;
return x && y;
}
```

This eliminates confusing ideas like duck typing (should we call it duck taping?) and scary topics like generics. Someone died once due to buying cheep generic medicine online!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.