-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Idea: print('a', 'b', 'c') without varargs #49084
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
Comments
cc @lrhn |
This will be a breaking change if it requires a change to I don't think it's necessary. You can already do |
I don't think it will, we could just modify
I agree, but Dart supports 20 parameters in hash that is used everywhere, I think print would be fine, it is usually not even recommended to go to production code. It would be an additional if for most of the cases (no second variable, stop here). |
I don't see the point of this, for hash that you are comparing to it is not possible to do anything similar to string interpolation, and this syntax gives no extra value to the user over string interpolation? |
i like use |
My dream: void print2(
[Object? arg1,
Object? arg2,
Object? arg3,
Object? arg4,
Object? arg5,
Object? arg6,
Object? arg7,
Object? arg8,
Object? arg9,
Object? arg10,
Object? arg11,
Object? arg12,
Object? arg13,
Object? arg14,
Object? arg15,
Object? arg16,
Object? arg17,
Object? arg18,
Object? arg19,
Object? arg20]) {
// Helper method to convert each object to a string.
String objectToString(Object? object) => object?.toString() ?? 'null';
// Combine the string representations of all objects separated by spaces.
String combinedString = [
arg1,
arg2,
arg3,
arg4,
arg5,
arg6,
arg7,
arg8,
arg9,
arg10,
arg11,
arg12,
arg13,
arg14,
arg15,
arg16,
arg17,
arg18,
arg19,
arg20
].where((obj) => obj != null).map(objectToString).join(' ');
// Call the original print function.
print(combinedString);
} |
You can just use that dream code yourself, now that you already have it. (But you might consider whether you want |
You are right, probably the sentinel idea will work better. I can use, but I can't replace print, so it is one more thing to remember :( |
Another one found a way different way to do this. Still feels hacky, but you can see people clearly miss this feature: |
What if we changed
print
to work likeObject.hash
?Instead of
we could have
The text was updated successfully, but these errors were encountered: