godotengine / godotengine/godot-docs

How do we avoid falling into line by line translation from GDScript to C#?

Open
#6,622 4 comments 2 reactions 0 assignees View on GitHub
discussion topic:dotnet
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

Hey 🙂

I was reading through the recent updates in the documentation and stumbled on a C# example that IMHO warrants a bit of discussion. I noticed it due to the recent PR on the CharacterBody2D page (#6614), but the part that bugs me was already there in the 3.x documentation.

So, on this page, we find the following snippet of code.

```cs
public override void _PhysicsProcess(double delta)
{
var collision = MoveAndCollide(Velocity * (float)delta);
if (collision != null)
{
Velocity = Velocity.Bounce(collision.GetNormal());
if (collision.GetCollider().HasMethod("Hit"))
{
collision.GetCollider().Call("Hit");
}
}
}
```

It is (as almost always) a direct translation of the GDScript example. More often than not, converting examples this way is fine. However, here, we are taking a very "duck typing-y" approach of what was returned by `collision.GetCollider()`... And I'd argue presenting this as a good approach in C# could be harmful (I lack a better word here) to the reader. In this particular instance, I guess most people would write this using an interface. But we don't really elaborate on what the object containing that `Hit()` method would be on this page, so I don't know if there's a point.

Anyway, I'm of course not saying we need to tailor every single C# code block completely differently than their GDScript counterpart. But I was curious of other people's opinion about this, if we should try to "correct" this kind of thing when we see them or if I'm just entirely delusional.

Edit: this was tagged automatically by GH, but it should probably be "discussion" instead of "enhancement"?

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.