question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataType 'returns' is Potentially Misleading

See original GitHub issue

While discussing some details yesterday over another project, it came up that the form of writing a DataType rule could mislead new users into thinking it returns a primitive type, rather than the DataType itself. I believe this goes against the notion of having a low barrier to entry for newcomers, as it could confuse and frustrate them.

For example, the following produces a value of the type SomeDataType, but is in itself a subtype of string. To make this work, we write ‘returns’ like so.

SomeDataType returns string: ID

For somebody unfamiliar with Langium, they may come to believe that SomeDataType actually returns string, given the literal wording. This is further reinforced by our consistent usage of ‘returns’ elsewhere for parser rules & terminals, where this is always the case.

My suggestion is that we at least consider whether we should:

  • use a different keyword than returns to signify a subtyping relationship (although internally we just use a type alias).
  • allow dropping returns type, and being able to infer the super type from utilized keywords, terminal rules, and data type rules
  • utilize highlighting to distinguish between DataType and ParserRules (this is present in Xtext)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
montymxbcommented, Aug 10, 2022

@luan-xiaokun thanks for chiming in! It’s of particular interest to make sure that new users are able to pick up Langium quite easily 🙂 . We will also be updating our documentation to hopefully make this clearer going forward as well.

If you haven’t read it yet, we do have an entry on Semantic Model Inference that goes more into how Types can declared, or inferred from rules. That may help clear up the difference between the two.

0reactions
spoenemanncommented, Dec 16, 2022

We release the current syntax as v1.0; we should keep it unless we find good reasons to change it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypedJSON.parse without type can be confusing #13
Therefore due to the potentially misleading 'Typed' part in the call ... This is how the return type of TypedJSON.parse is determined:.
Read more >
prevent users from entering wrong data types [duplicate]
I am returning '0' if the condition is failed and '1' if the condition is false.. Collect the return value in the main...
Read more >
True or False: Boolean Is a Data Type?
A boolean, as you might have guessed, is a data type that represents “true” or “false”.
Read more >
True or False: Boolean Is a Data Type : 6 Steps
1. In a broad sense, data types are ways to represent different kinds of information in a computer processor or FPGA. Today we...
Read more >
Algebraic data types - CS 242
The basic idea behind algebraic data types (ADTs) is to represent relations ... After all, we could have introduced potentially incorrect/breaking changes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found