godotengine / godotengine/godot-docs

Make `Array.sort_custom` callable requirements more explicit for the `a == b` case

Open
#10,816 0 comments 0 reactions 0 assignees View on GitHub
area:class reference enhancement
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

**Your Godot version:**
4.4

**Issue description:**
If the sorting function provided to `sort_custom` returns true when `a == b` (E.g. using `<=` instead of just `<`), you will get an error that reads:
```
bad comparison function; sorting will be broken
```

The existing documentation does technically describe the correct expected behavior of the callable, but it could stand to be more explicit. I propose adding the following sentence to the main part of the method description (before the first code-example) to make the expected behavior completely unambiguous:
> If the order of the two elements does not matter (E.g. they are equal), it should return `false`.

**URL to the documentation page (if already existing):**
https://docs.godotengine.org/en/stable/classes/class_array.html#class-array-method-sort-custom

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.