support private _main in Dart? #12460
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-not-planned
Closed as we don't intend to take action on the reported issue
type-enhancement
A request for a change that isn't a bug
This bug is more a channel for discussion. I ran recently into this situation and it made me ponder things a bit.
I was wondering if there are any reasons why 'main' has to be public, or if it should actually be private (for example, suppose we call it '_main').
The rationale for this is that it would make it easy to write libraries that serve both as libraries and entrypoints, without having to hide their 'main' method.
For example:
a.dart:
library a;
x = 1;
_main() => print(x);
b.dart:
import 'a.dart';
y = x + 1;
_main() => print(y);
The idea is that these programs would have no conflicts in their imports and could be run as entrypoints ("dart a.dart" prints '1', "dart b.dart" prints '2').
This sounds like a minor improvement because you could write this with 'hide' directives today:
a.dart:
library a;
x = 1;
main() => print(x);
b.dart:
import 'a.dart' hide main;
y = x + 1;
main() => print(y);
But it brings up two questions:
- what is more appropriate: a public or private method?
- should we support this in the future?
The text was updated successfully, but these errors were encountered: