Anonymous Functions: Lambda, Higher Order Functions, and Lexical Closures

Tags

, , , , , ,

I teach computer science and programming languages, such as C, C++, C#, Python, PHP, Java, and Dart; you may also learn PHP framework like Laravel. Just drop me a message either at my email or Skype.

E-mail - sanjib12sinha@gmail.com
Skype ID - live:sanjib12sinha

Learn Dart the Hard Way

In this article we will take a look at some special functions in Dart programming language – Anonymous Functions: Lambda, Higher Order Functions, and Lexical Closures
Lambda, Higher Order functions, and Lexical Closures have some similarities. In their namelessness and anonymity, these features of Dart are very interesting. Let us first start with Lambda. Then we will discuss Higher Order functions and Closures. In reality, you will find that Lambda actually implements Higher Order Functions.
Lambda: The Anonymous Function
As the name suggests, Lambda is a nameless function and we can use it in two ways. We can use it in a traditional method and also we can use the ‘Fat Arrow’.
Consider the first code snippet:
//code 8.1
class LambdaCode{
// here addingTwonumbers is a nameless function
Function addingTwonumbers = (int x, int y){
var sum = x + y;
return sum;
};
}
main(List arguments){
var lambdaShow = LambdaCode();
print(lambdaShow.addingTwonumbers(12, 47));
}

I will give the output after adding the ‘Fat Arrow’ method. The whole code snippet looks like this:
//code 8.2
class LambdaCode{
// here addingTwonumbers is a nameless function
Function addingTwonumbers = (int x, int y){
var sum = x + y;
return sum;
};
Function divideByFour = (int num) => num ~/ 4;
}
main(List arguments){
var lambdaShow = LambdaCode();
print(lambdaShow.addingTwonumbers(12, 47));
print(lambdaShow.divideByFour(56));
}

The output is quite expected, in the first anonymous function ‘Function addingTwonumbers’ we have passed two parameters and added them. And using the ‘Fat Arrow’ method, we have passed a number through another nameless function ‘Function divideByFour’ and divided it by 4.
//output of code 8.2
59
14

While building a native iOS or Android app, you will see how these nameless functions come to your help.

Exploring Higher Order Functions

The specialty of Higher Order functions is it can accept a function as a parameter. That is why it is named Higher Order Function. It not only can accept a function as a parameter, but it can also return it; actually, it can do both.
We will see a very simple code snippet to get accustomed to the idea.
//code 8.3
//returning a function
Function DividingByFour(){
Function LetUsDivide = (int x) => x ~/ 4;
return LetUsDivide;
}
main(List arguments){
var result = DividingByFour();
print(result(56));
}

The output is 14.
So we have passed a nameless function ‘Function LetUsDivide’ as a parameter and returned the function quite easily through a higher order function ‘Function DividingByFour()’.
The closure is a Special Function
We can define Closure in two ways. According to the first definition, we can say that Closure is the only function that has access to the parent scope, even after the scope is closed.
To understand this definition, let us see a very short code snippet:
//code 8.4
//a closure can modify the parent scope
String message = "Any Parent String";
Function overridingParentScope = (){
String message = "Overriding the parent scope";
print(message);
};
main(List arguments){
print(message);
overridingParentScope();
}
The output is:
Any Parent String
Overriding the parent scope

By the second definition, we can say that a Closure is a function object that has access to the variables in its lexical scope, even when the function is used outside of its original scope.
//code 8.5
Function show = (){
String pathToImage = "This is an old path.";
Function gettingImage(){
String path = "This is a new path to image.";
print(path);
}
return gettingImage;
};
main(List arguments){
var showing = show();
showing();
}
Here is the output: This is a new path to image.

It actually returns a function object ‘gettingImage’ that has accessed the variable in its lexical scope.

So at the end of this section, we can summarize the points about Closure.
1. In several other languages, you are not allowed to modify the parent variable.
2. However, within a closure, you can mutate or modify the values of variables present in the parent scope.
3. All together, Closure is a very special type of function.

Now we will conclude our whole journey to study the nameless functions in one single code base, and we will also see the output.
//code 8.6
//Lambda is an anonymous function
class AboutLambdas{
//first way of expressing Lambda or anonymous function
Function addingNumbers = (int a, int b){
var sum = a + b;
//print(sum);
return sum;
};
Function multiplyWithEight = (int num){
return num * 8;
};
//second way of expressing Lambda by Fat Arrow
Function showName = (String name) => name;
//higher order functions pass function as parameter
int higherOrderFunction(Function myFunction){
int a = 10;
int b = 20;
print(myFunction(a, b));
}
//returning a function
Function returningAFunction(){
Function showAge = (int age) => age;
return showAge;
}
//a closure can modify the parent scope
String anyString = "Any Parent String";
Function overridingParentScope = (){
String message = "Overriding the parent scope";
print(message);
};
Function show = (){
String pathToImage = "This is an old path.";
Function gettingImage(){
String path = "This is a new path to image.";
print(path);
}
return gettingImage;
};
}
main(List arguments){
var add = AboutLambdas();
var addition = add.addingNumbers(5, 10);
print(addition);
var mul = AboutLambdas();
var result = mul.multiplyWithEight(4);
print(result);
var name = AboutLambdas();
var myName = name.showName("Sanjib");
print(myName);
var higher = AboutLambdas();
var higherOrder = higher.higherOrderFunction(add.addingNumbers);
higherOrder;
var showAge = AboutLambdas();
var showingAge = showAge.returningAFunction();
print(showingAge(25));
var sayMessage = AboutLambdas();
sayMessage.overridingParentScope();
var image = AboutLambdas();
var imagePath = image.show();
imagePath();
}

And in the output we will see how the nameless functions work in different ways.
//output of code 8.6
15
32
Sanjib
30
25
Overriding the parent scope
This is a new path to image.

Advertisements

Static Variables and Methods in Dart Programming

Tags

, , , , , , ,

laern-dart-the-hard-way

https://leanpub.com/learndartthehardway

To implement class-wide variables and methods, we use the static keyword. Static variables are also called class variables. Let us first see a code snippet and after that we will discuss the advantages and disadvantages of static variables and methods.
//code 7.1
// static variables and methods consume less memory
// they are lazily initialized
class Circle{
static const pi = 3.14;
static Function drawACircle(){
//from static method you cannot call a normal function
print(pi);
}
Function aNonStaticFunction(){
//from a normal function ou can call a static meethod
Circle.drawACircle();
print("This is normal function.");
}
}
main(List arguments){
var circle = Circle();
circle.aNonStaticFunction();
Circle.drawACircle();
}

And here is the output:
3.14
This is normal function.
3.14

As you see, static variables are useful for class-wide state and constants. So in the main() method we can add this line at the end:
main(List arguments){
var circle = Circle();
circle.aNonStaticFunction();
Circle.drawACircle();
print(Circle.pi);
}

And get the value of constant ‘pi’ again. Here, ‘Circle.pi’ is the class variable. And the class method is: ‘Circle.drawACircle();’. The biggest advantage of using static variables and methods is it consumes less memory. An instance variable once instantiated, consumes memory whether it is being used or not. The static variables and methods are not initialized until they are used in the program. It consumes memory when they are used.
A few things to remember:

1. From a normal function you can call a static method.
2. From a static method, you cannot call a normal function.
3. In a static method you cannot use the ‘this’ keyword. It is because the static methods do not operate on an instance and thus do not have access to this.

So at the end we can conclude that using static variables and methods depend on the context and situations. In the next part of the book, where we will build native iOS and Android mobile apps with the help of Flutter framework, you will see how and when we use static variables and methods.

Maps: the Key, Value Pair in Dart Programming Language

Tags

, , , , ,

laern-dart-the-hard-way

https://leanpub.com/learndartthehardway

An unordered collection of Key-Value pair is known as Map in Dart. The main advantage of Map is the Key-Value pair can be of any type.
To begin with, let us start with some points that we should remember while working with Map.

1. Each Key in a Map should be unique.
2. The value can be repeated.
3. The Map can commonly be called hash or dictionary.
4. Size of a Map is not fixed, it can either increase or decrease as per the number of elements. In other words, Maps can grow or shrink at runtime.
5. HashMap is an implementation of a Map and it is based on a Hash table.

Let us see a code snippet to understand how a Map works in Dart.
//code 9.4
void mapFunction(){
//unordered collection of key=>value pair
Map countries = Map();
countries['India'] = "Asia";
countries["German"] = "Europe";
countries["France"] = "Europe";
countries["Brazil"] = "South America";
//1. method we can obtain key or value
for(var key in countries.keys){
print("Countries' name: $key");
}
print("-----------");
for(String value in countries.values){
print("Continents' name: $value");
}
//2. method
countries.forEach((key, value) => print("Country: $key and Continent: $value"));
//we can update any map very easily
if(countries.containsKey("German")){
countries.update("German", (value) => "European Union");
print("Updated country German.");
countries.forEach((key, value) => print("Country: $key and Continent: $value"));
}
//we can remove any country
countries.remove("Brazil");
countries.forEach((key, value) => print("Country: $key and Continent: $value"));
print("Barzil has been removed successfully.");
print("-----------");
//3. method of creating a map
Map telephoneNumbersOfCustomers = {
"John" : 1234,
"Mac" : 7534,
"Molly" : 8934,
"Plywod" : 1275,
"Hagudu" : 2534
};
telephoneNumbersOfCustomers.forEach((key, value) => print("Customer: $key and Contact NUmber: $value"));
}
main(List arguments){
mapFunction();
}

And here is the output of code 9.4
Countries' name: India
Countries' name: German
Countries' name: France
Countries' name: Brazil
-----------
Continents' name: Asia
Continents' name: Europe
Continents' name: Europe
Continents' name: South America
Country: India and Continent: Asia
Country: German and Continent: Europe
Country: France and Continent: Europe
Country: Brazil and Continent: South America
Updated country German.
Country: India and Continent: Asia
Country: German and Continent: European Union
Country: France and Continent: Europe
Country: Brazil and Continent: South America
Country: India and Continent: Asia
Country: German and Continent: European Union
Country: France and Continent: Europe
Barzil has been removed successfully.
-----------
Customer: John and Contact NUmber: 1234
Customer: Mac and Contact NUmber: 7534
Customer: Molly and Contact NUmber: 8934
Customer: Plywod and Contact NUmber: 1275
Customer: Hagudu and Contact NUmber: 2534

There are three methods that we use to retrieve the values of a Map.
//1. method we can obtain key or value
for(var key in countries.keys){
print("Countries' name: $key");
}
print("-----------");
//2. Method
for(String value in countries.values){
print("Continents' name: $value");
}
//3. method
countries.forEach((key, value) => print("Country: $key and Continent: $value"));

Besides, there are several methods to add, update or remove the elements in a Map. As we progress and build apps in native iOS or Android, we will see more features of Map. Lastly we will see another collection feature in Map, which is called Queue.

List, Set and Map : Data structures in Dart

Tags

, , , , ,

laern-dart-the-hard-way

https://leanpub.com/learndartthehardway

In Dart, a Set is an unordered collection of unique items. There are small difference in syntaxes between List and Set.
Let us see an example first to know more about the difference.
//code 2.18
main(List arguments) {
var fruitCollection = {'Mango', 'Apple', 'Jack fruit'};
print(fruitCollection.lookup('Apple'));
}
//output of code 2.18
Apple

We can search the Set using the lookup() method. If we search something else, it returns ‘null’.
//code 2.19
main(List arguments) {
var fruitCollection = {'Mango', 'Apple', 'Jack fruit'};
print(fruitCollection.lookup('Something Else'));
}
//output of code 2.19
null

Remember one key point regarding Set and Map. When we write:
var myInteger = {};
It does not create a Set, but a Map. The syntax for map literals is similar to that of for set literals. Why does it happen? Because map literals came first, the literal {} is a default to the Map type. We can prove this by a simple test:
//code 2.20
main(List arguments) {
var myInteger = {};
if(myInteger.isEmpty){
print("It is a map that has no key, value pair.");
} else print("It is a set that has no key, value pair.");
}
Watch the output:
//output of code 2.20
It is a map that has no key, value pair.

It means the map is empty. If it was a set, we would have got the output in that direction. We will see lots of examples of Sets in future, while we build our mobile application. At present just remember, in general, a map is an object that associates keys and values. The set has also keys, but that are implicit. In cases of Sets, we call it indexes.
Let us see one example of Map type by map literals. While writing keys and values, it is important to note that each key occurs only once, but you can use the same value many times.
//code 2.21
main(List arguments) {
var myProducts = {
'first' : 'TV',
'second' : 'Refrigerator',
'third' : 'Mobile',
'fourth' : 'Tablet',
'fifth' : 'Computer'
};
print(myProducts['third']);
}

The output is obvious : ‘Mobile’. Dart understands that the ‘myProducts’ has the type Map(Map); we could have made the key integers or number type, instead of a string type.
//code 2.22
main(List arguments) {
var myProducts = {
1 : 'TV',
2 : 'Refrigerator',
3 : 'Mobile',
4 : 'Tablet',
5 : 'Computer'
};
print(myProducts[3]);
}

The output is the same as before – mobile.
Can we add a Set type collection of value inside a Map? Yes, we can. Consider this code:
//code 2.23
main(List arguments) {
Set mySet = {1, 2, 3};
var myProducts = {
1 : 'TV',
2 : 'Refrigerator',
3 : mySet.lookup(2),
4 : 'Tablet',
5 : 'Computer'
};
print(myProducts[3]);
}

In the above code (2.23) we have injected a collection of Set type and we also have looked up for the defining value through the Map key. Here, inside the Map key, value pair we have added the set element number 2, this way: 3 : mySet.lookup(2), and later we have told our Android Studio editor to display the value of the Map type ‘myProducts’ .
The output is quite expected: 2.
You can create the same products lists by Map constructor. For the beginners, the term “constructor” might seem difficult. We will discuss this term in detail in our object-oriented programming category. Consider this code:
//code 2.24
main(List arguments) {
var myProducts = Map();
myProducts['first'] ='TV';
myProducts['second'] ='Mobile';
myProducts['third'] ='Refrigerator';
if(myProducts.containsValue('Mobile')){
print("Our products’ list has ${myProducts['second']}");
}
}

And here is the output:
//output of code 2.24
Our products’ list has Mobile
Since we have had an instance (in code 2.24) of Map class, the seasoned programmer might have expected ‘new Map()’ instead of only ‘Map()’.
As of Dart 2, the new keyword is optional. We will learn about these, in detail, in the coming object-oriented programming chapter.
We will also have a separate “Collections” chapter later, where we will learn more about List, Set and Map.

Why we need Constructor in Dart

Tags

, ,

Why we need Constructors
The first and the foremost task of constructors is construction of objects. Whenever we try to create an object and write this line:
var fatherBear = Bear();

laern-dart-the-hard-way

https://leanpub.com/learndartthehardway

We actually try to arrange a spot in the memory for that object. The real work begins when we connect that spot with class properties and methods.
Using ‘constructor’ we can do that job more efficiently. Not only that, Dart allows to create more than one ‘constructor’, which is a great advantage.
Let us write our ‘Bear’ class in a new way of using constructor:

//code 3.10
class Bear {
int numberOfFish;
int hourOfSleep;
int weightGain;
Bear(this.numberOfFish, this.hourOfSleep);
int eatFish(int numberOfFish) => numberOfFish;
int sleepAfterEatingFish(int hourOfSleep) => hourOfSleep;
int weightGaining(int weightGain) => weightGain = numberOfFish * hourOfSleep;
}
main(List arguments){
var fatherBear = Bear(6, 10);
fatherBear.weightGain = fatherBear.numberOfFish * fatherBear.hourOfSleep;
print(“Father bear eats ${fatherBear.eatFish(fatherBear.numberOfFish)} fishes. And he sleeps for ${fatherBear.sleepAfterEatingFish(fatherBear.hourOfSleep)} hours.”);
print(“Father bear has gained ${fatherBear.weightGaining(fatherBear.weightGain)} pounds of weight.”);
}

Creating ‘constructor’ is extremely easy. Watch this line:
Bear(this.numberOfFish, this.hourOfSleep);
The same class name works as a function or method and we have passed two arguments through that method. Once we get those values, we would calculate the third variable. Writing constructor this way is known as “Syntactic Sugar”. In the later section of the book, we will know more about the constructor.
Now it gets easier to pass the two values while creating the object. We could have done the same by creating constructor this way, which is more traditional:

//code 3.11
class Bear {
int numberOfFish;
int hourOfSleep;
int weightGain;
Bear(int numOfFish, int hourOfSleep){
this.numberOfFish = numOfFish;
this.hourOfSleep = hourOfSleep;
}
//Bear(this.numberOfFish, this.hourOfSleep);
int eatFish(int numberOfFish) => numberOfFish;
int sleepAfterEatingFish(int hourOfSleep) => hourOfSleep;
int weightGaining(int weightGain) => weightGain = numberOfFish * hourOfSleep;
}
main(List arguments){
var fatherBear = Bear(6, 10);
fatherBear.weightGain = fatherBear.numberOfFish * fatherBear.hourOfSleep;
print(“Father bear eats ${fatherBear.eatFish(fatherBear.numberOfFish)} fishes. And he sleeps for ${fatherBear.sleepAfterEatingFish(fatherBear.hourOfSleep)} hours.”);
print(“Father bear has gained ${fatherBear.weightGaining(fatherBear.weightGain)} pounds of weight.”);
}

In both cases, the output is same as before:

//output of code 3.11
Father bear eats 6 fishes. And he sleeps for 10 hours.
Father bear has gained 60 pounds of weight.

In the above code, you can even get the object’s type very easily. We can change the type of value quite easily. Watch the main() function again:

//code 3.12
main(List arguments){
var fatherBear = Bear(6, 10);
fatherBear.weightGain = fatherBear.numberOfFish * fatherBear.hourOfSleep;
print(“Father bear eats ${fatherBear.eatFish(fatherBear.numberOfFish)} fishes. And he sleeps for ${fatherBear.sleepAfterEatingFish(fatherBear.hourOfSleep)} hours.”);
print(“Father bear has gained ${fatherBear.weightGaining(fatherBear.weightGain)} pounds of weight.”);
print(“The type of the object : ${fatherBear.weightGain.runtimeType}”);
String weightGained = fatherBear.weightGain.toString();
print(“The type of the same object has changed to : ${weightGained.runtimeType}”);
}

And here is the output:

//output of code 3.12
Father bear eats 6 fishes. And he sleeps for 10 hours.
Father bear has gained 60 pounds of weight.
The type of the object : int
The type of the same object has changed to : String

Continue with For Loop in Dart

You have just seen how we have explicitly broken the inner loop and stopped one cycle of the inner loop. So ‘break’ is a very important concept while using ‘for loop’. At the same breath the ‘continue’ keyword also plays a very key role in ‘for loop’.
Let us consider this code snippet:

void loopContinue(){
for(var num = 1; num <= 5; num++){
if(num % 2 == 0 ){
print("These are all even numbers. $num");
continue;
} print("These are all odd numbers. $num");
}
}
main(List arguments){
loopContinue();
}

Watch the output and you will understand how the keyword ‘continue’ works.

These are all odd numbers. 1
These are all even numbers. 2
These are all odd numbers. 3
These are all even numbers. 4
These are all odd numbers. 5

Let us change the above code a little bit.

void loopContinue(){
for(var num = 1; num <= 5; num++){
if(num % 2 == 0 ){
//print("These are all even numbers. $num");
continue;
} print("These are all odd numbers. $num");
}
}

Here is the output:

These are all odd numbers. 1
These are all odd numbers. 3
These are all odd numbers. 5

According to the context, the keyword ‘continue’ means when the value is divisible by 2 and there is no remainder, just skip printing.
Let us change the code again and see the output.

void loopContinue(){
for(var num = 1; num <= 5; num++){
if(num % 2 == 0 ){
print("These are all even numbers. $num");
continue;
} //print("These are all odd numbers. $num");
}
}

Have a look at the output:

These are all even numbers. 2
These are all even numbers. 4

Now our context has changed. When the value is divisible by 2 and there is no remainder, the keyword ‘continue’ tells the program to continue with printing the value as long as the ‘if clause’ stays true.
‘Break and Continue’ are two very important concepts not only in Dart, but in every programming language.

Control the flow of your code in Dart

Tags

, , , ,

laern-dart-the-hard-way

https://leanpub.com/learndartthehardway

Controlling the flow of your code is very important. Every programmer wants to control the logic for many reasons; one of the main reasons is the user of the software should have many options open to them.
You do not know the conditions beforehand. You can only guess and as a developer, you should open as many avenues before the user as possible. There are several techniques adopted for controlling the flow of the code. The ‘if and else’ logic is very popular.
If and Else
Let us see an example where it works to control the flow of the code:

//code 2.37
main(List<String> arguments) {
bool firstButtonTouch = true;
bool secondButtonTouch = false;
bool thirdButtonTouch = true;
bool fourthButtonTouch = false;
if(firstButtonTouch) print("The giant starts running.");
else print("To stop the giant please touch the second button.");
if(secondButtonTouch) print("The giant stops.");
else print("You have not touched the second button.");
print("Touch any button to start the game.");
if(thirdButtonTouch) print("The giant goes to sleep.");
else print("You have not touched any button.");
if(fourthButtonTouch) print("The giant wakes up.");
else print("You have not touched any button.");
}
//output of code 2.38
The giant starts running.
You have not touched the second button.
Touch any button to start the game.
The giant goes to sleep.
You have not touched any button.

Now you can make this small code snippet more complicated.

//code 2.39
main(List<String> arguments) {
bool firstButtonTouch = true;
var firstButtonUntouch;
bool secondButtonTouch = false;
bool thirdButtonTouch = true;
bool fourthButtonTouch = false;
firstButtonUntouch ??= firstButtonTouch;
firstButtonUntouch = false;
if (firstButtonUntouch == false || firstButtonTouch == true) print("The giant is sleeping.");
else print("You need to wake up the giant. Touch the first button.");
if(firstButtonTouch == true && firstButtonUntouch == false) print("The giant starts running.");
print("To stop the giant please touch the second button.");
if((secondButtonTouch == true && thirdButtonTouch == true) || fourthButtonTouch == false) print("The giant stops.");
else print("You have not touched the second button.");
print("Touch any button to start the game.");
if(thirdButtonTouch) print("The giant goes to sleep.");
else print("You have not touched any button.");
if(fourthButtonTouch) print("The giant wakes up.");
else print("You have not touched any button.");
}

According to your complexity of the code, you should arrange your ‘if and else’ logic. And your output varies.

//output of code 2.39
The giant is sleeping.
The giant starts running.
To stop the giant please touch the second button.
The giant stops.
Touch any button to start the game.
The giant goes to sleep.
You have not touched any button.

For ‘if and else’ logic always remember these golden rules.

    1. 1. When both conditions are true, the result is true.

 

    1. 2. When both conditions are false, the result is false.

 

    1. 3. When one condition is true and the other condition is false, the result is false.

 

    4. When one condition is true or one condition is false, the result is true.

In the above code, I just try to give you an idea about how you can use ‘if and else’ logic where you really need it. However, this example is too simple. It can be complex when relational operators get added and the logic may become complex.
Finally before leaving this section, I would like to show you another code snippet where the existing set of rules or principles has been changed.


//code 2.40
main(List<String> arguments) {
bool firstButtonTouch = true;
var firstButtonUntouch;
bool secondButtonTouch = false;
bool thirdButtonTouch = true;
bool fourthButtonTouch = false;
firstButtonUntouch ??= firstButtonTouch;
firstButtonUntouch = false;
if (firstButtonUntouch == false || firstButtonTouch == true) print("The giant is sleeping.");
else if (thirdButtonTouch) print("You need to wake up the giant. Touch the first button.");
else if(firstButtonTouch == true && firstButtonUntouch == false) print("The giant starts running.");
else if (secondButtonTouch) print("To stop the giant please touch the second button.");
else if((secondButtonTouch == true && thirdButtonTouch == true) || fourthButtonTouch == false) print("The giant stops.");
else if (thirdButtonTouch) print("You have not touched the second button.");
else if (secondButtonTouch) print("Touch any button to start the game.");
else if(thirdButtonTouch) print("The giant goes to sleep.");
else if (firstButtonUntouch) print("You have not touched any button.");
if(fourthButtonTouch) print("The giant wakes up.");
else print("You have not touched any button.");
}

And here is the output of code 2.40:

The giant is sleeping.
You have not touched any button.
You can change the pattern and see what happens.

Learn Dart the Hard Way

Tags

, , , ,

laern-dart-the-hard-way

https://leanpub.com/learndartthehardway

Just published!

Just get the feel:

1. Why Dart Language?

You can answer this question in one sentence.
Dart is a great fit for both – Mobile Apps and Web Apps. Dart is free and open source and the repository is available at https://github.com/dart-lang. And at the same time you may get the feel of the language at the official website: https://www.dartlang.org/.
In this introductory chapter, let us try to understand why learning Dart language is important for us to build a mission critical Mobile Apps on iOS and Android.
It is important to note, in the very beginning, the developers around the world use Dart to create high-quality apps for iOS and Android and the web. It is feature rich so that client-side development is also possible. As we progress step-by-step, we will see how correct this statement is.

Continue reading

Interfaces and Method Injection in Laravel 5.8

Tags

, ,


Get my all books here….

https://leanpub.com/u/sanjibsinha

Laravel Authentication

Abstraction in OOP involves extraction of relevant details. Consider the role of a car salesman. There are many types of consumers. Everyone wants to buy a car, no doubt, but each one has differences in their criteria. Each of them is interested in one or two certain features. This attribute varies accordingly. Shape, color, engine power, power steering, price … the list is endless. The salesman knows all the details of the car but does he repeat the list one by one until someone finds his or her choice?
No.
He presents only the relevant information to the potential customer. As a result the salesman practices “Abstraction” and presents only relevant details to customer. Now consider abstraction from the perspective of a programmer who wants a user to add items to list.
Abstraction does not mean that information is unavailable but it assures that the relevant information is provided to the user. PHP 5 had introduced abstract classes and methods much before. And PHP 7 enhances it now making the general purpose language completely object oriented. Classes defined as abstract may not be instantiated and any class that contains at least one abstract method must also be abstract.
Remember that abstract methods can not define the implementation. On the other hand, object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.
Interfaces are defined with the interface keyword, in the same way as a standard class, but without any of the methods having their contents defined.
All methods declared in an interface must be public; this is the nature of an interface. In Laravel, you will find the injection of interfaces to the classes quite frequently. In Laravel Interface is considered as a Contract.
Contract between whom? And why? Because an interface does not contain any code but it only defines a set of methods that an object implements. In SOLID design principle we have talked about maintaining a library of small classes with clearly defined scopes, and it is achievable with the help of Interfaces.

NASA scientists, engineers, and technologists: are they spies?

Tags

, , , , , ,

Spies in the Skies

Spies in the Skies


No.
They are not spies. Conventionally.
However, they have indirect links. From the very beginning.
The American Spy and Intelligence agencies CIA and NRO have recently published tons of declassified documents that support that notion.
Tehelka has published a cover story. Spies in the Skies.
I am giving the link below.
Declassified documents released by US government agencies like CIA, NRO are saying so. The truth has an official seal. NASA had designed shuttles that carried US spy satellites to orbit. Declassified documents depict a disgraceful relationship between NASA and CIA, the US Department of Defense (DoD), and National Reconnaissance Office (NRO). These agencies took part in designing NASA’s Shuttles throughout the 1970s.

Spies in the Skies