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

Type Hints #757

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft

Type Hints #757

wants to merge 3 commits into from

Conversation

Jason2605
Copy link
Member

@Jason2605 Jason2605 commented Nov 15, 2024

Type Hints

Resolves: #670

What's Changed:

  • Allow the compiler to recognise (and ignore) type hints. This will allow third party type checkers to be created

The hints themselves are essentially a comment, but will need to be a valid identifier token otherwise the compiler will fail.

Syntax

def test(): string {
    return "test";
}

class Test {
    someMethod(): number {
        return 10;
    }
}

const test: string = "Hello!";

// `?int` could denote int OR nil
var multiple: ?int, variables: number = 10;

const [unpacking: list] = [["nested list"]];

Type of Change:

  • Bug fix
  • New feature
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Housekeeping:

  • Tests have been updated to reflect the changes done within this PR (if applicable).
  • Documentation has been updated to reflect the changes done within this PR (if applicable).

Screenshots (If Applicable):

@Jason2605
Copy link
Member Author

Dunno what your guys thoughts are on this @liz3 @briandowns ?

Would allow us to create a static analyser outside of the Dictu codebase (potentially written in Dictu :O) similar to MyPy and others

@liz3
Copy link
Contributor

liz3 commented Nov 16, 2024

I don't mind something like that as long as its optional. Good static analysers are able to do this without hints by inferring based on default values, assignments etc. By the point good static analysers start failing because of dynamic evaluation those types usually are not helping.
Amongs my peers i have the unpopular opinion of not liking typescript for example. Imo it does not add actual value since most bugs are logic errors which a static analyser cannot catch.
That being said i do like them once the vm(runtime) can use them to provide a performance advantage through making assumptions it cannot do otherwise.

The TL'DR for me is: I think in the current form(optional) they are okay but nothing i would put too much value on.

@briandowns
Copy link
Contributor

I'm with @liz3 . I don't think I'd use them much unless I'm writing a huge code base and it'd be a pain to track back through a ton of files to figure out what's what. Super cool feature though from a parser / language perspective though.

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

Successfully merging this pull request may close these issues.

[FEATURE] Type Hints (Discussion)
3 participants