Giter VIP home page Giter VIP logo

learn-dart's People

Contributors

luchoturtle avatar miguelmartins17 avatar nelsonic avatar simonlab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

learn-dart's Issues

How to define functions?

Add a functions section in the README to describe how to create functions.

  • simple function example:
String hello() {
  return 'hello';
}

We can see that the value's type returned by the function is the specify at the beginning of the function declaration. From some manual test I'm not sure however that the type is required as Dart might determine it automatically (need more searching on this). However I think this is always a good idea to specify it as it describes what the function returns.

  • void function type. The void keywords for a functions means that the function doesn't return any value.
void hello() {
  print('hello');
}

However I've tested with return null; and the code compiled without error. I'm not sure if void is a specific type (where null is consider a value of void, or a synonym?)

void hello() {
  print('hello');
  return null;
}
  • the main function. Entry point for Dart/flutter program
  • Arrow function: String hello() => 'hello'. I understand arrow function as a shortcut for functions with one returning line.

Other questions to search:

  • Research how to use parameters

    • give name to parameters
    • give default value to parameters
    • are parameters optional
  • Add a section on metada which allow us to add more information about a function, for example deprecated, required, override...

  • Does Dart allow anonymous functions? https://dart.dev/guides/language/language-tour#anonymous-functions

The `const` constructor

I recently blocked on a line similar to:

final myList = const [1,2,3];

I wan't sure about the meaning of const when initialising a final variable.
In this situation const is used to instanciate (create) a new immutable object.
This means that the list object [1, 2, 3] can't be changed, and the following code won't work:

final myList = const [1, 2, 3];
myList.add(4); // error

If we ignore const then we are able to use the function add on the list, and this following code will work:

final myList = [1, 2, 3]
myList.add(4) // myList contains now the value [1, 2, 3, 4]

ref:

String with single or double quotes?

You can represent a string with either single quotes or double quotes without any difference.

const hello1 = "hello";
const hello2 = 'hello';
hello1 == hello2; //true

To escape specific characters in a string use \

Dart style guide let you decide which one you prefer to use, just be consistent.
Flutter style guide recommend to use single quote: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#prefer-single-quotes-for-strings

ref:

How to work with asynchronous events?

We can use async, await keywords and the class Future to manage asynchronous operation.
For example when retrieving data from an API the returned values might take a bit of time depending on the API server, network status...

  • Read https://dart.dev/codelabs/async-await and summarise how to manage asynchronous events
  • The keyword then is also sometimes used with asynchronous function, what is the difference with async/await and then

The cascade operator ..

In Elixir we are use to apply multiple functions on a value with the pipe operator |>

"Hello there" 
|> String.upcase() 
|> String.split()

The pipe operator takes the returned value of the function and apply the next function. This works nicely because of Elixir values are immutable and functions return a new value with the updated change from the functions.

Dart is object oriented. This means that the following doesn't work:

var l = [1,2,3];
l.add(4).add(5);

Here l is an list and the add function change the state of the list directly, it doesn't create a new list value. Moreover the add function as the following declaration:

void add(E value) 

So add returns a void value and not the list itself.

One solution to add multiple values in a list could be:

void main(){
  var a = [1,2,3];  
  a.add(4);
  a.add(5);
  print(a);
}

However the cascade operator .. is here to make the code a be nicer.
The operator apply a method on the receiver/object, discard the returned value of that method and instead returns the receiver/object itself.

void main(){
  var a = [1,2,3]
    ..add(4)
    ..add(5);
  print(a);
}

ref:

Add Beginner Friendly Examples

At present #efc23154 this repo is a good start but it does not have any code.
Our objective with any learn-xyz repo is to make it first place a person needs to go for learning that topic. E.g: https://github.com/dwyl/learn-elixir has everything the person needs to start learning Elixir including the syntax/semantics and code examples.

I propose that we:

  • re-work this repo such that all code examples can be run offline provided the reader has the Dart VM installed on their computer OR
  • alternatively if they are using a computer that cannot install Dart (e.g. a Chromebook or iPad), we provide links to examples on Dart Pad so they can run and play with the code online.

Dart track on Exercism

Dart exercises with mentor feedback

image

We could add this link in a "read more" section in the Readme.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.