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

Several edits to the GDScript docs #43959

Merged
merged 1 commit into from
Dec 3, 2020
Merged

Conversation

dalexeev
Copy link
Member

  • More consistent look of examples.
  • Clarification about int / float.
  • Corrected a couple of wording.

I also noticed the following problems (I have not looked for relevant issues yet):

  1. Some functions return a type depending on the type of the argument(s), while others always return float:

    print(var2str(sign(1))) # 1
    print(var2str(sign(1.0))) # 1.0
    print(var2str(abs(2))) # 2
    print(var2str(abs(2.0))) # 2.0
    print(var2str(clamp(3, 4, 5))) # 4
    print(var2str(clamp(3, 4.0, 5.0))) # 4.0
    print(var2str(min(6, 6))) # 6
    print(var2str(min(6.0, 6.0))) # 6.0
    print(var2str(max(7, 7))) # 7
    print(var2str(max(7.0, 7.0))) # 7.0
    
    print(var2str(floor(8))) # 8.0
    print(var2str(floor(8.0))) # 8.0
    print(var2str(ceil(9))) #  9.0
    print(var2str(ceil(9.0))) # 9.0
    print(var2str(round(10))) # 10.0
    print(var2str(round(10.0))) # 10.0
    print(var2str(pow(11, 1))) # 11.0
    print(var2str(pow(11, 1))) # 11.0

    At the same time, the documentation indicates that the function returns float, for example float abs(s: float), although these are like two functions (int abs(s: int) and float abs(s: float)).

  2. The print() function does not distinguish between "the same" int and float:

    print(1) # 1
    print(1.0) # 1

    Accordingly, the wording print(EXPR) # Prints 1 used in some examples doesn't answer what EXPR is: 1 or 1.0.

@dalexeev dalexeev requested a review from vnen as a code owner November 29, 2020 14:59
@Calinou Calinou added this to the 4.0 milestone Nov 29, 2020
@dalexeev dalexeev requested a review from a team as a code owner December 1, 2020 13:05
@dalexeev dalexeev requested review from aaronfranke and removed request for a team December 1, 2020 14:24
Copy link
Member

@aaronfranke aaronfranke left a comment

Choose a reason for hiding this comment

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

I will give this a ✔️ because I don't see any obvious problems, and also the documentation about int/truncation/etc is good.

However, I don't necessarily approve of moving the comments to the end of the lines, the GDScript style guide doesn't have an opinion on this, and if I had to pick I'd say the old way is better since it would be more consistent with long comments that definitely belong on their own line. Anyway, it's up to @godotengine/documentation to decide which way is preferred.

@dalexeev
Copy link
Member Author

dalexeev commented Dec 1, 2020

I don't necessarily approve of moving the comments to the end of the lines, the GDScript style guide doesn't have an opinion on this

The fact is that the examples in the documentation are already done in different styles. I was just trying to reduce this chaos.

Examples

a = atan(0.5) # a is 0.463648

# Prints 1.543081
print(cosh(1))

# a = 59
a = dectime(60, 10, 0.1))

# r is 3.141593
r = deg2rad(180)

a = exp(2) # Approximately 7.39

print(hash("a")) # Prints 177670

pow(2, 5) # Returns 32

the old way is better since it would be more consistent with long comments that definitely belong on their own line

I left the really long comments on a separate line, for example:

# c is 0.523599 or 30 degrees if converted with rad2deg(s)
c = acos(0.866025)

Multiline examples IMO should be as compact as possible:

# n is 0
n = step_decimals(5)
# n is 4
n = step_decimals(1.0005)
# n is 9
n = step_decimals(0.000000005)

n = step_decimals(5) # n is 0
n = step_decimals(1.0005) # n is 4
n = step_decimals(0.000000005) # n is 9

@akien-mga akien-mga merged commit 9a0610c into godotengine:master Dec 3, 2020
@akien-mga
Copy link
Member

Thanks!

@akien-mga akien-mga added the cherrypick:3.x Considered for cherry-picking into a future 3.x release label Dec 3, 2020
@dalexeev dalexeev deleted the gds-doc branch December 3, 2020 12:36
@akien-mga
Copy link
Member

Cherry-picked for 3.2.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants