-
Notifications
You must be signed in to change notification settings - Fork 209
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
Allow punctuation based alternatives to keywords? #4275
Comments
It is only harder to read as long as one doesn't know that it means. Even so, people can still often deduce what it means by context. I don't think we should refrain from using symbols because someone will find it hard to read. Anyone can learn APL, so using |
Can The Edit: I saw the idea to write |
I'm mainly interested in the overall preferences, I don't claim that anything I mentioned would be a well-designed proposal for actual syntax. If we want to enable this more concise kind of syntax then we'd need to sort out the details, but I'm sure we can do that. That said, those two declarations would be
True, but this might even be a non-problem: Mixin application does create a class which is a subtype of the superclass and also a subtype of the mixin, which makes it yet another kind of intersection type. Next, You could of course say that |
It'll make class declaration shorter. That's always nice. I do feel the pain when writing many class declarations at the same time, but it's not something I do that often. I'm not opposed to the idea on any principled ground, but I don't see it as big win, and therefore not as a high priority. Primary constructors will save much more typing than this, and that's eliminating actual repetitions. (I'd save more characters total if we allow |
I suggest a simpler nomenclature - let's just introduce shortcuts:
Related: in type arguments, we use the keyword |
I don't like this. One of Dart's strength is its simplicity and its similarity to other popular languages. Lots of Dart developers come from JS or Java. And I doubt we'd be removing the ability to use |
As someone who had a (mis)fortune to code in java for approx. 20 years (before gotten kicked out for good, which ended the torture), I can tell you that the last thing java programmer wants is another java. The additional rationale for a more concise notation comes from the static interfaces: saying |
I know this was kind of just an afterthought, but
I think that's my favorite idea from this proposal :) |
I think in cases like this, it's important to remember that any given line of code is written basically once but read over and over again. Of course, one could get used to cryptic punctuation and develop mnemonics that work for them, but I feel it's undeniable that human-speakable words make code drastically more accessible. It's not even about coming from language X or Y. Python is considered one of the most beginner-friendly languages ever, and it's filled with keywords you won't find in other languages, not to mention abandoning some very common punctuation like Dart is already using punctuation a lot, with a large increase since null safety. While it's true that class modifiers are really pushing the boundaries of keyword-to-meaningful-token ratios, it shouldn't be ignored that there was extensive discussion around the exact naming and ordering of those modifiers. Replacing them with punctuation would fly in the face of all meaning associated with those choices. There is nothing about
Again, true, but it's that transition period I'm wondering about. Is it really worth alienating so many just to save some characters when typing? Class declarations aren't expressions, and they don't need to look like it. They currently have a ton of valid combinations, and that's not even including In other words, while it's true that humans can easily get used to some symbols and use them sparingly to save space, there's an extreme gap between rules like "use ? for nullability" and |
@eernstg: I think you made a mistake by presenting the case in an overly abstract form. // Hypothetical Dart.
class C<X : B<X>> : S & M<X> : I, J {} Indeed, this can scare off even the most hardcore user. In practice, the components would not be cryptic at all. // Hypothetical Dart.
class C<X : num> :Comparable<num> with MyMixin<X> static Decodable<C> {} There's nothing controversial about the syntax. Compare it with the alternative: class C<X extends num> implements Comparable<num> with MyMixin<X> static implements Decodable<C> {} Does anybody think the latter is more readable? |
Considering the issue title, another case to take into account: for (var number in numbers) {} versus for (var number : numbers) {} |
I also think we could benefit from providing concise alternatives to commonly used syntaxes. I believe concepts that are both (1) widely understood from people coming from all sorts of languages, and (2) frequently occurable would benefit the most from becoming shorter and symbolic e.g. the I disagree with the idea that this approach should be avoided because other languages do not do it. This is because it can be a stylistic choice, much of which I also disagree with the notion that more concise syntax only benefits the writer. Conciseness is also for the reader. By shortening the words and symbols necessary to convey an idea, the reader can (1) take in more information at a glance and (2) have to map semantics to less symbols (less cognitive overhead). Of course it can be overdone, but it can definitely be underdone as well and as of now it is currently underdone given the lack of shorthand syntaxes. I think conventional mathematics is a great example to follow in this regard. Symbolize simple and widely used concepts while using names for less common ones. Although, I think many symbols are already in use so shortening keywords is primarily the way to. |
I mean, it starts with the very simple
If the question here is to just make |
Dart syntax relies on keywords in many situations. For example:
We could introduce punctuation based alternatives to some of the most frequently used keywords. The rationale would be that this is more concise, and it would very quickly be established as a notation for the given purpose. In other words,
extends
might arguably be more self-explanatory than:
, but it won't take long before they are equally readable if we see them all the time.One example of a language using punctuation for several of the elements shown above is Kotlin:
Kotlin uses
:
to indicate that the following type is the bound of the type variable, and also to indicate that the supertypes of the class are specified (that is, an optional superclass which is extended, and zero or more interfaces which are implemented).Dart cannot directly use the same syntax for superinterfaces because the superclass can be composite (consisting of a superclass and one or more mixins), and the implemented superinterfaces cannot be recognized by being interfaces (it can be an
interface class
, but it can also be any other kind of class).However, we could use two colons (one to replace
extends
and the next one to replaceimplements
):If a class implements something and doesn't specify a superclass then we'd have the two colons together:
class A :: I {}
. Similarly,class A {}
meansclass A : Object {}
.There are many other locations in Dart code where a similar thing could be done. For example,
required
in a declaration of a named parameter could be written as!
(for example, immediately before the name of the parameter). AlsoFunction
in a function type could be abbreviated (perhapsFun
, or maybe a plainF
would do).What do you think? The conciseness can be striking, but the punctuation based notation will surely be considered harder to read by some developers..
The text was updated successfully, but these errors were encountered: