-
Notifications
You must be signed in to change notification settings - Fork 1
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
Less punctuation? #3
Comments
The syntax was chosen to not match existing Dart expression syntax too much, because it isn't an expression and we don't want users to think that it is. This suggestion is better. It is slightly non-Dart'ish in that you can use expressions in the case part, but it's still readable, and it matches the colon well. |
This is always the tricky choice. Do we make it similar to an existing construct to highlight the similarities or different to highlight the differences? In this case, I think we can do better than using |
Benefits:
(do I really need the |
I like the idea of the condition being "postfix", after the import. I considered something like import "some_uri.dart" when dart.feature.html
or "other_uri.dart" when dart.feature.io
otherwise "default_uri.dart"; The import "a.dart" when dart.feature.html "b.dart" when dart.feature.io; |
How about something like this? browser import "a.dart";
local import "b.dart"; // I'm unsure about `local` |
The set of configurations ( |
All variants proposed above, including original one, look foreign and artificial in a context of dart IMO. I think the choice of ?: would be preferable, just because it's familiar and natural. Syntax of it can be restricted in this directive. But that doesn't mean one needs completely different notation. If you do want to choose a different notation, please think of other examples where new syntax can be reused in the future. If you can find a pattern, it will be a good argument. |
Another approach to deriving this syntax. Following the pattern, we get something like this |
BTW, if we are unwilling to use ?: just because it looks like expression, same argument applies to ==. But it turns out, || means something completely different in a new syntax. |
Any arguments against import 'package:somepackage/somelib_[browser|standalone].dart'; which imports in case of import 'package:somepackage/somelib_browser.dart'; in case of import 'package:somepackage/somelib_standalone.dart'; in case of import 'package:somepackage/somelib_default.dart'; This just uses some convention like
I don't think there are situations where "don't import at all for a specific platform" makes sense. It is probably useful to have an indication (at the beginning?) of the import whether there is a platform selection involved to know if the import path needs to be parsed for platform part. If this is not an option I like @tatumizer s approach better than the original proposal. |
Won't it be better to just use package-spec (see another proposal) for this? One may have 2 or 3 package specs (e.g. browser spec, standalone spec, test spec) and configure stuff there like Another concern: we currently know 2 options for certain: standalone and browser. If people start adding custom options, this will lead to a mess: libraries can use options no one knows about. On the other hand, if options are fixed, syntax of package spec can be extended slightly so that we can specify the choices in a single package spec, e.g, (just making it up): Names of sections can be predefined, to avoid collisions in conventions across different libraries I just feel that the complexity of proposal and all variants discussed above is not proportionate to the problem (in other words, we are shooting sparrows from cannon) |
I think it is more common to just have different libraries for each platform within one package instead of a package for each implementation. |
Another variant for the case we go with naming conventions: It uses existing string interpolation syntax. |
I thought of this as well and like it but it doesn't allow to specify which platforms are supported. Not sure if this is necessary though. |
If you want explicit choices hardcoded, I think the variant of "select" can be simplified as |
I'm convinced. Maybe for is enough and select can therefore be omitted? |
Maybe. Though it won't fit into pattern "every clause starts with keyword". |
I was a bit tired when I wrote my last comment... |
If we remove "select", then comma wants to be inserted between variants: |
I still interpreted your approach wrong but I think I got it now. |
The central question for this discussion, IMO, is this: is the following a valid program? Logically, condition "if (false)" is equivalent to "if (false==true)", but if false==true, then any statement is true, so it's even true that "abracadabra" exists - why complain about its non-existence? |
That isn't actually the problem. Because of the way Dart is speced, code that isn't executed can refer to things that don't exist just fine. The problem is that the import of a library like "dart:html" on the standalone VM statically prevents the program from running at all. You don't even get to |
I understand that. But suppose you define a simplest form of conditional import, like this: What I'm trying to understand is this: why this is not a good idea? |
I'm leaning towards:
for now. Extra punctuation isn't really necessary. |
Two questions:
|
Oh, sorry, you kind of answered question 2 in another thread. |
There's a problem with "if (imported..." though. The syntax of this expression is not easy to restrict. So analyzer has to be able to evaluate arbitrary constant expressions. (In which case there's no point to restrict the syntax of condition in "import "some.dart" if condition" either). No idea if analyzer can easily handle arbitrary const expressions. It's all equivalent to full-blown preprocessor. Plus, maybe some extra hint is needed in the code, e.g. if (const(imported("some.dart") && somethingElse || "foo"!="bar")) { |
The
||
and:
seem strange and arbitrary to me. I don't think a random Dart user could easily intuit what they do, especially since their meaning is different from how those operators are understood in other contexts.However, there is already a language feature that:
How about we leverage that?
What do you think?
The text was updated successfully, but these errors were encountered: