Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename str2var to str_to_var and similar #64367

Merged
merged 1 commit into from
Aug 26, 2022

Conversation

Mickeon
Copy link
Contributor

@Mickeon Mickeon commented Aug 13, 2022

Closes godotengine/godot-proposals#5206.

As brought up in #54161 (comment).

To make it short, the naming scheme with "2" in the middle is not always used across Godot (String.int_to_bin()), and it isn't proper English.

Affects the internal Math class, a good chunk of the audio filter code, and a lot of miscellaneous classes.

Before After
var2str var_to_str
str2var str_to_var
bytes2var bytes_to_var
bytes2var_with_objects bytes_to_var_with_objects
var2bytes var_to_bytes
var2bytes_with_objects var_to_bytes_with_objects
linear2db linear_to_db
db2linear db_to_linear
deg2rad deg_to_rad
rad2deg rad_to_deg

Added later in this PR:

Before After
dict2inst dict_to_inst
inst2dict inst_to_dict

I think it's worth noting, before merging this, that while testing I did find writing these methods to be much slower (underscore, two characters, another underscore, and the Italian keyboard requires holding Shift to access the underscores), although it may be a matter of getting used to it.

@Mickeon Mickeon requested review from a team as code owners August 13, 2022 16:14
@raulsntos
Copy link
Member

The .po and .pot files in the doc/translations/ folder are auto-generated when syncing translations from Weblate, you should not manually change them.

@fire
Copy link
Member

fire commented Aug 13, 2022

@Calinou Thoughts on this? I support this rename of 2 to "to".

@fire fire requested a review from a team August 13, 2022 16:38
@Mickeon
Copy link
Contributor Author

Mickeon commented Aug 13, 2022

The mentioned reply is among the most liked in the tracker.

@TokageItLab
Copy link
Member

TokageItLab commented Aug 13, 2022

Doesn't deg2rad/rad2deg also need to be changed?

@Mickeon
Copy link
Contributor Author

Mickeon commented Aug 13, 2022

Oopsie. Will update as soon as possible.

@Mickeon Mickeon force-pushed the rename-var-to-str branch from a729155 to 0c4bb10 Compare August 13, 2022 23:37
@Mickeon Mickeon requested review from a team as code owners August 13, 2022 23:37
@Mickeon
Copy link
Contributor Author

Mickeon commented Aug 13, 2022

Updated to include deg_to_rad and rad_to_deg.

@Mickeon Mickeon force-pushed the rename-var-to-str branch from 0c4bb10 to 638a0fb Compare August 13, 2022 23:52
@Mickeon Mickeon requested a review from a team as a code owner August 13, 2022 23:52
@YuriSizov
Copy link
Contributor

The last time this was discussed, we didn't decide how far the naming change should go. For example, with these changes it no longer makes sense to use shortened terms, e.g. str instead of string, deg instead of degree.

The 90s naming scheme is more forgiving in that regard. The new naming starts to look weird without proper renames.

@Mickeon
Copy link
Contributor Author

Mickeon commented Aug 14, 2022

I personally think that going "too" far would do the opposite of what the PR is meant to do, that is, potentially making the code too verbose and actually harder to read.

In fact, and I don't know what to make of this...
I actually prefer to read deg2rad() in the actual source code, but exposed as deg_to_rad() in GDScript (DegToRad() in C#). I don't know what the opinion of most is, but it does look nicer to me in C++.

		// Before.
		p_rotation_offset = Math::deg2rad(rotation_offset->get_value());
		p_rotation_step = Math::deg2rad(rotation_step->get_value());
		
		// After.
		p_rotation_offset = Math::deg_to_rad(rotation_offset->get_value());
		p_rotation_step = Math::deg_to_rad(rotation_step->get_value());

@MewPurPur
Copy link
Contributor

MewPurPur commented Aug 14, 2022

@YuriSizov Shortened terms, even acronyms are OK, but "2" instead of "to" or "too", and "4" instead of "for" - these are more like interwebz slang.

@MewPurPur
Copy link
Contributor

MewPurPur commented Aug 19, 2022

Missed inst2dict and dict2inst.

With these added, I'm 99% sure no methods are missed

@YuriSizov
Copy link
Contributor

Approved for the list present in this PR/linked proposal

@Mickeon
Copy link
Contributor Author

Mickeon commented Aug 25, 2022

There's some of these that have been missed in this PR. What about them? Would it still be possible to make a separate PR for them?

@YuriSizov
Copy link
Contributor

You can add inst2dict and dict2inst here, I think. I'm not sure there is anything else that needs changing. Feel free to bring it up, I guess, in the next few days or so.

@Mickeon Mickeon requested a review from a team as a code owner August 25, 2022 19:44
@Mickeon Mickeon force-pushed the rename-var-to-str branch from 0db0a99 to e1d6ff8 Compare August 25, 2022 20:47
@Mickeon

This comment was marked as resolved.

@Mickeon Mickeon force-pushed the rename-var-to-str branch 2 times, most recently from 2376508 to 311ba3a Compare August 25, 2022 23:37
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We approved this in a bikeshedding meeting.
I'll check locally to make sure everything is properly converted.

@akien-mga
Copy link
Member

C# solution fails building with:

Error: /home/runner/work/godot/godot/modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs(550,65): error CS1061: 'object' does not contain a definition for 'NativeVar' and no accessible extension method 'NativeVar' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) [/home/runner/work/godot/godot/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj]

@Mickeon Mickeon force-pushed the rename-var-to-str branch from 311ba3a to 42c3e44 Compare August 26, 2022 08:38
@Mickeon
Copy link
Contributor Author

Mickeon commented Aug 26, 2022

Epic merge fail.

@akien-mga
Copy link
Member

There seems to be some code in Mono that might still need porting:

modules/mono/glue/GodotSharp/GodotSharp/Core/DelegateUtils.cs
186:                                    NativeFuncs.godotsharp_var2bytes(var, false.ToGodotBool(), out var varBytes);

modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs
27:            NativeFuncs.godotsharp_bytes2var(varBytes, allowObjects.ToGodotBool(), out godot_variant ret);
535:            NativeFuncs.godotsharp_str2var(godotStr, out godot_variant ret);
550:            NativeFuncs.godotsharp_var2bytes((godot_variant)var.NativeVar, fullObjects.ToGodotBool(), out var varBytes);
574:            NativeFuncs.godotsharp_var2str((godot_variant)var.NativeVar, out godot_string ret);

modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs
464:        internal static partial void godotsharp_bytes2var(in godot_packed_byte_array p_bytes,
507:        internal static partial void godotsharp_str2var(in godot_string p_str, out godot_variant r_ret);
509:        internal static partial void godotsharp_var2bytes(in godot_variant p_what, godot_bool p_full_objects,
512:        internal static partial void godotsharp_var2str(in godot_variant p_var, out godot_string r_ret);

modules/mono/glue/runtime_interop.cpp
1236:void godotsharp_var2str(const godot_variant *p_var, godot_string *r_ret) {
1242:void godotsharp_str2var(const godot_string *p_str, godot_variant *r_ret) {
1259:void godotsharp_var2bytes(const godot_variant *p_var, bool p_full_objects, godot_packed_array *r_bytes) {
1271:void godotsharp_bytes2var(const godot_packed_array *p_bytes, bool p_allow_objects, godot_variant *r_ret) {
1482:   (void *)godotsharp_bytes2var,
1502:   (void *)godotsharp_str2var,
1503:   (void *)godotsharp_var2bytes,
1504:   (void *)godotsharp_var2str,

CC @godotengine/dotnet

Everything else seems good.

@Mickeon
Copy link
Contributor Author

Mickeon commented Aug 26, 2022

Oooh I did see it, I actually wasn't sure what was the naming scheme used for them (godotsharp_strtovar or godotsharp_str_to_var)?

@raulsntos
Copy link
Member

The naming scheme would be godotsharp_str_to_var.

@Mickeon Mickeon force-pushed the rename-var-to-str branch from 42c3e44 to 18c88ca Compare August 26, 2022 11:32
Copy link
Member

@raulsntos raulsntos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mono module looks good except for a few rebasing mistakes.

modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs Outdated Show resolved Hide resolved
modules/mono/glue/GodotSharp/GodotSharp/Core/GD.cs Outdated Show resolved Hide resolved
Affects the Math class, a good chunk of the audio code, and a lot of other miscellaneous classes, too.

- `var2str` -> `var_to_str`
- `str2var` -> `str_to_var`
- `bytes2var` -> `bytes_to_var`
- `bytes2var_with_objects` -> `bytes_to_var_with_objects`
- `var2bytes` -> `var_to_bytes`
- `var2bytes_with_objects` -> `var_to_bytes_with_objects`
- `linear2db` -> `linear_to_db`
- `db2linear` -> `db_to_linear`
- `deg2rad` -> `deg_to_rad`
- `rad2deg` -> `rad_to_deg`

- `dict2inst` -> `dict_to_inst`
- `inst2dict` -> `inst_to_dict`
@Mickeon Mickeon force-pushed the rename-var-to-str branch from 18c88ca to 59e1193 Compare August 26, 2022 12:58
@akien-mga akien-mga merged commit f9f2446 into godotengine:master Aug 26, 2022
@akien-mga
Copy link
Member

Thanks!

menip added a commit to menip/godot_voxel that referenced this pull request Aug 26, 2022
Zylann added a commit to Zylann/godot_voxel that referenced this pull request Aug 26, 2022
@Mickeon Mickeon deleted the rename-var-to-str branch August 28, 2022 09:55
@aXu-AP
Copy link
Contributor

aXu-AP commented Sep 2, 2022

This is a great, welcome change. As I english isn't my first language, I usually end up reading numbers in my own language (finnish), resulting in strange sounding functions (varkaksistr etc.). I'm sure I'm not the only one who had this problem. Glad it's getting changed :)

evanwalsh added a commit to evanwalsh/godot-ply that referenced this pull request Sep 18, 2022
jarneson added a commit to jarneson/godot-ply that referenced this pull request Oct 22, 2022
* Godot 4.0 beta 1 import file updates

* API rename: `update` is now `queue_redraw`

Per godotengine/godot#64377

* API rename: `x2y` functions are now `x_to_y`

Per godotengine/godot#64367

* Update types: `UndoRedo` is now an internal of `EditorUndoRedoManager`

Per godotengine/godot#59564

* beta 3

Co-authored-by: Jeff <jeffrey.arneson@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Approved
Development

Successfully merging this pull request may close these issues.

Rename str2var and similar functions to str_to_var
9 participants