Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart and underscores

Tags:

dart

I decided to implement the functional underscore.js library in Dart.

I wrote the functions in 'underscore.dart' with some example functions shown below:

library underscore;

List _filter (ff, List s) => return s..retainWhere(ff);

List _dropWhile(ff,List s) => s.skipWhile(ff).toList();

In my main Dart program, I then added the import statement

import 'underscore.dart';

However, I got the persistent error on that line of 'Unused Import', and so none of the functions were recognised.

It did work, though, when I redefined 'underscore.dart' as 'part of mainProg' and made 'mainProg' a library in its own right.

Further testing shows that it is the underscores on the function names that is causing the problem.

Any ideas?

like image 297
user1721780 Avatar asked Oct 04 '13 10:10

user1721780


People also ask

What is use of _ in Flutter?

with reference to the Flutter tutorial, I encountered an underscore, _ . I know that in Java, _ is used as a naming convention for a private variable.

What do underscores mean in C++?

In C++, an underscore usually indicates a private member variable. In C#, I usually see it used only when defining the underlying private member variable for a public property. Other private member variables would not have an underscore.

Can you use underscores in variable names?

A variable name can only contain alpha-numeric characters and underscores ( a-z, A-Z , 0-9 , and _ )


1 Answers

A prepending underscore means that the function is library private. That is, you can't use it in an other library. See Libraries and Visibility.

Libraries not only provide APIs, but are a unit of privacy: identifiers that start with an underscore (_) are visible only inside the library.

like image 94
Alexandre Ardhuin Avatar answered Oct 05 '22 18:10

Alexandre Ardhuin