Skip to content
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

Please consider for a version 3.0 #33104

Closed
Ing-Brayan-Martinez opened this issue May 12, 2018 · 5 comments
Closed

Please consider for a version 3.0 #33104

Ing-Brayan-Martinez opened this issue May 12, 2018 · 5 comments
Labels
type-enhancement A request for a change that isn't a bug

Comments

@Ing-Brayan-Martinez
Copy link

Ing-Brayan-Martinez commented May 12, 2018

Greetings to the development team of the language dart, I am someone from Latin America, I do not speak English, but I apollo in Google translator and been helping in the promotion of this language to Latin America through this group of Facebook, the reason for this is to find a way to contribute to the improvement of the language through three proposals which seek to help readability and security of the code.

The first is to consider including the words reserved Public Private and Proteted this parese something much needed for a more readable code and to relizar a better encasulation of the data or properties, this will be actrativo approvers coming from the world of .NET Java PHP and TypeScript this to increase the popularity of the language of that estoi sure.

The second proposal is to have a better abstraction of the data types already in Dart 2.0, we have been working on that, what I propose is the following if we have the primitive types int, double, char, bol, dynamic, among others. I think we should have its complex version like Integer, Double, String, Bol, Dynamic to perform things like Integer.of ("1,500"); Dynamic.of ("2,000"). ToInteger (); that I look great, and hasi can be static or dynamic when we want.

The tersera proposal following the same order of ideas is borrowed from the golang language that deals with when we create a variable that comes preloaded with a value avoiding null variables and the classic example nullpointerexcections if we show a varible tipada bol x; its default value is false, the other to consider only have cycles for forget the while and do while the end result is a more concurrent language.

To finish I wanted to tell you a reflection, that google should bet more on this language as well as microsoft bet on c # o oracle by java google should bet on dart, google should stop supporting typescript and java or similar and switch to using dart as a language Principal this to grow your popularity, these are my proposals are easy but I know there is a lot of work behind you I hope you like them and I would like to be able to collaborate more actively especially with people who speak Spanish greetings to all

@lrhn lrhn added the type-enhancement A request for a change that isn't a bug label May 12, 2018
@lrhn
Copy link
Member

lrhn commented May 13, 2018

I'll try summarizing the requests here:

  • Add public/private/protected access controls. Dart currently only has library privacy (selected by starting the name with an underscore), not class based privacy. In most situations this is sufficient, and some would say preferable, to class based privacy (that's obviously a matter of both taste and habit), but there is nothing in Dart that corresponds to "protected" (accessible only in subclasses), and that can be inconvenient. I speak as a library writer, and I have sorely missed protected access when writing reusable super-classes.

  • Not sure what the request is. Adding Integer doesn't seem to be able to do anything the int class can't. Dart does not have "primitive" types, so int is a full class type with static methods like int.parse already.

  • Allow classes/types to declare a "default value" use to initialize variables of that type that does not have an initializer expression. Common choices would be false for bool and zero for numeric types. This is a convenience only (since obviously you can just write the initializer), but it would probably be very convenient if/when we introduce non-nullable types.

  • Not sure what the other request is ... removing "while" and "do/while"?

@Ing-Brayan-Martinez
Copy link
Author

Ing-Brayan-Martinez commented May 13, 2018

If you approach what I am requesting, as it has helped me to better understand how the language works internally I can define the requests in the following way:

  1. The idea of ​​including modifiers at the class level is able to make a better encasulacion of class properties, and avoid madificacion internal data with external agents, if I want to write a class that follow the pattern DTO or Command I do not want the data changes during transport of information, is to treat objects as simple more message, is follow what is known as POJO, it is ideal to implement things like patron Redux for more intete information to create a class Person with the properties name, last name and age utilize the Guetter and setters language and their own instantiate setter can create the Person class and Empiese to notice that you have access to all properties and methods and can change the data without going through the Guetter and this is my main concern, I see this as a need to write code, people who come from the world C#, Java, TypeScript, PHP think the same they are the public to whom this language should be addressed, Dart should be thought with a more business vision, as from-end this very good with angullar and flluter for back-end you have to work on this as a programmer I would be grateful if this were a reality. Example
      class Person {

           private String firstName;  
           private String lastName;   
           private Int age;           
 
           public String getFirstName() {
               return this.firstName;
          }

          public void setFirstName(String firstName) {
              this.firstName = firstName;
          }
          /*.....*/
       }

       final Person x = new Person();

       x.setFirstName("Brian");  //Correct
       x.firstName = "Dilan";    //Error. property is private

By this I mean the visibility of the properties of a class only not of the class with what exists at the library level with the reserved words Export, Import, As and Show is sufficient.

  1. As a language user I did not know that there were no primitive types, this forces me to rethink the proposal to the following: Since all types are complex since they have properties and methods, a clean language must be created to the names of methods of each type of data to have a library as standard as possible that need not be a sperto speaking English to understand what each method is that can help this are the names of functions Haskell style or libraries like undescore.js or ramda.js that has an api where each function is self-explanatory I wish that all data types of the Dart language have a function of() that from it can transform the data inroduced. Example
       print(String.of(540,000).toLowerCase().trim());

       Math.pow(Dynamic.of("20").toInt());

       List.of(['a','b','c','d','e']).map(/*....*/).reduce(/*.....*/);

this syntax is beautiful does not require further explanation what else is to include more operators see the case of javascript with.

       Array.prototype.*    Whatever you want.
       String.prototype.*    Whatever you want.
  1. If the data types of the language would be the only ones that would have a preassigned value to avoid null and be able to be more concurrent. For example: bol = false, int = 0, String = "" this helps a lot. For the objects it is only convenient to use the final operator to the instance of the example object:
       class Person {

            private String firstName;  //It is assumed ""
            private String lastName;   //It is assumed ""
            private Int age;           //It is assumed 0
            private bol state          //It is assumed false

        }

        final Person x = new Person();

this is what I always ago, there could be a way to make this syntax mandatory, this would avoid values null what I am not sure if it applies to all cases. Immutability is being used a lot in these times.

  1. If that is to delete while do / while already I could have all that with a cycle for there is this golang if you see that type are not necessary cycles, I think that this type of syntax are being obseletas. because we already have functions like forEach(), map(), filter(), takeWhile() and reduce() to iterate in collections, we must weigh in a safe and fast code and for is an expected cycle that avoids side effects.

  2. This is new note recently is to include a reserved word that forces me to implement an exception called throws this forces me to use a sintasix like this:

     public void read() throws Exception;
    

These improvements in the language if they are brought to reality will convert the language dart into the best language that I could use, it will be better than java, javascript and php and as I said before, Dart should be the star language of google as it is C# for Microsoft and Java for Oracle Dart must be there with that vision and Google must let it give support to things thrown with Java with TypeScript and even with JavaScript so that Dart can replace all that and take the role that deserves.

To have this, there is a lot of work but this is the future without saying anything else, I say goodbye.

@lrhn
Copy link
Member

lrhn commented May 14, 2018

For the examples here, Dart is a different language than, say Java, and it has chosen different designs for some things.

Dart does have privacy, and it has getter and setter members as well, so there is never any reason to write code like:

class Person {

   private String firstName;  
   private String lastName;   
   private Int age;           

  public String getFirstName() {
      return this.firstName;
 }

  public void setFirstName(String firstName) {
      this.firstName = firstName;
  }
  /*.....*/
}

In Dart, you should just write:

class Person {
  String firstName;
  String lastName;
  int age;
}

There is no functional difference between this and the code you wrote, you can still change the first name. Whether you do person.setFirstName("Bob") or person.firstName = "Bob"; is not changing that, and the latter is the preferred style in Dart. If you do want a private field, and, say, a public getter and private setter, you can do:

class Person {
  String _firstName;
  String _lastName;
  int _age;
  Person(String firstName, String lastName, int age) 
      : _firstName = firstName, _lastName = lastName, _age = age;
  String get firstName => _firstName;
  String get lastName => _lastName;
  int get age => _age;
}

This gives you (library) private mutable fields and public getters only, so any code from a different library can only read the values, but your own library can change the fields.

In other words, in Dart you don't need "getter methods", you use actual getters, and you can make fields private (but, alas, not "protected", that is still missing).

You ask for methods on all types that can convert from one type to another. The examples are somewhat curious, though.

print(String.of(540,000).toLowerCase().trim());

Math.pow(Dynamic.of("20").toInt());

List.of(['a','b','c','d','e']).map(/*....*/).reduce(/*.....*/);

These would just be written as:

print(540000.toString().toLowerCase().trim());
Math.pow(("20 as dynamic).toInt());
['a','b','c','d','e'].map(/*....*/).reduce(/*.....*/);

I'm not absolutely sure what the of functions (or constructors) should do. We can't promise conversion from any one type to any other type. Some classes do have an of type, mainly collections.

Dart does not have overloading, so we can't have multiple functions with the same name and different argument types. Instead you need to choose a meaningful name for each function. That's why functions that take and interpret a String to create a new object of some type are usually called parse (int.parse, double.parse, DateTime.parse). Objects that create something from something of a different type are usually constructors named something like .fromList or .fromElements (or, for collections, just .from and .of).

As for allowing users to add more functions, that is something we are considering (perhaps something like traits or scoped extension methods).

Having default values for variables that is different from null is not something that makes sense until we have non-nullable types. Currently the type of a variable like int x; is actually int or null, and null is a reasonable default value for that type. If/when we get non-nullable types as well, so int x; can only contain integers, and int? x; would be a variable for null or integers, then it makes sense to also have default values for the non-nullable types. So, unlikely to happen on its own.

I'm very dubious about the claim that "while" loops are obsolete. They are a tool, like any other, and they have advantages and disadvantages. The forEach exactly has the issue that you cannot do side effects (like breaking early). Trying to remove while will likely just force us to introduce a forEachWhile(bool action(E element) function instead.

Dart is single-threaded, and I seriously doubt that is going to change any time soon (it's possible, but definitely not easy, to change at this point, too much code assumes that there is no real concurrency). That makes arguments that while doesn't parallelize well moot, since it won't ever get to parallelize anyway.

Adding throws declarations on interfaces would be purely documentation. Java made the experiment of having throws declarations for checked exceptions on interfaces, with mandatory propagation and handling. That experiment was ... not convincing. Checked exceptions in Java are generally considered a bigger hassle than they are a benefit, and we see users catch-and-ignore'ing checked exceptions, or wrapping them in unchecked exceptions, to avoid overloading their API with IOException and SQLException that then user can't really do anything about anyway. So, Java-like checked exceptions is not something we plan, or want, in Dart.

@vsmenon
Copy link
Member

vsmenon commented May 14, 2018

@Ing-Brayan-Martinez - closing this as it's difficult to manage / triage such a broad request. Please feel free to file more specific requests (along the lines of the 2nd / 3rd comment breakdown) and reference the discussion here. You may also find existing bugs on some of those. Thanks!

@vsmenon vsmenon closed this as completed May 14, 2018
@Ing-Brayan-Martinez
Copy link
Author

Good morning to all, I have been analyzing the answers and I will summarize it in a single proposal, which I consider a necessity and the most important one, as the translation is not exact I will explain it with a couple of examples:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants