Showing posts with label Functions. Show all posts
Showing posts with label Functions. Show all posts

Monday, February 3, 2014

My note: Dart. Functions. A bunch of instructions, which executes sequentially.


Class. You can pick class methods one at a time, and execute it.

Function. wikipedia; Function: (subroutine)

In computer programming, a subroutine is a sequence of program instructions that perform a specific task, packaged as a unit.

...................


Commands are fullfilled in sequential order. Nothing can stop functions execution. "When a function that returns a Future is invoked, two things happen:

The function queues up work to be done and returns an uncompleted Future object immediately.
Later, when the value is available, the Future object completes with that value or with an error."

spec 1.1 Functions abstract over executable actions. Because Dart is optionally typed, we cannot guarantee that a function that does not return a value will not be used in the context of an expression. Therefore, every function must return a value. A return without an expression returns null.
A function declaration is a function that is neither a member of a class nor a function literal. Function declarations include library functions, which are function declarations at the top level of a library, and local functions, which are functions declarations declared inside other functions. Library functions are often referred to simply as top-level functions.


If a function does not declare a return type explicitly, its return type is dynamic.


From: https://www.dartlang.org/articles/event-loop/
Once a Dart function starts executing, it continues executing until it exits. In other words, Dart functions can’t be interrupted by other Dart code.




https://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html
A closure is a function object that has access to variables in its lexical scope, even when the function is used outside of its original scope. Functions can close over variables defined in surrounding scopes.

Typedefs
In Dart,functions are objects, just like strings and numbers are objects. A typedef, or function-type alias, gives a function type a name that you can use when declaring fields and return types. A typedef retains type information when a function type is assigned to a variable.


My note: Nowhere (or where?) in Dart doc is clearly said "Function is a collection of elements/code, which are all evaluated in sequence"
".. bunch of logic".

Published originally  in  etdart.blogspot.fi   

Friday, March 15, 2013

About Dart functions and Closures, Dart funktiot ja sulkemiset

Understanding Closures.. hard.. and Functions. (spec: Functions abstract over executable actions)

This conversation is from:
https://groups.google.com/a/dartlang.org/forum/?fromgroups=#!topic/misc/NOuoGrxW2nE

https://groups.google.com/a/dartlang.org/d/msg/misc/NOuoGrxW2nE/DHTVT-_qq40J
Direct link to just this piece of conversation.. Great!!

Alex Tatumizer Mar 14 (16 hours ago)

@Ladislav:

Somehow, I overlooked the fact that whatever is called Function in dart in fact doesn't correspond to javascript notion of Function - it's really a closure, e.g.
Function f="abcd".substring;
print(f(0,2));


This is a great feature, so I withdraw my sarcasm. I thought dart makes distinction between Function (as pointer to function "codes") and Closure, but it probably doesn't.
Won't it be better to call it Closure, not Function then, to avoid confusion?

Ladislav Thon asvered:

Function is just something that can be called. Even this, I believe:

class Answer {
call() => 42;
}


main() {
var a = new Answer();
print(a());
print(a is Function);
}


Some Functions are in fact closures, meaning that they carry their lexical environment, but not all of them. I'm not sure about renaming Function to Closure, I think it would make some situations more clear and some less.


Tatumizer ansvered:


Probably you are right, but then things get a bit confusing indeed for anyone coming from javascript (huge army of potential dart users).
Look at "Tour of the dart language" - they are talking about functions AND closures, without elaborating on subtleties - but this are very important subtleties, deserved to be featured much more prominently.
Needs to be better documented maybe?


Check link for more conversation...

And next theme: Orthogonal Wikipedia:

Computer scienceOrthogonality in programming language design is the ability to use various language features in arbitrary combinations with consistent results.[9] This usage was introduced by von Wijngaarten in the design of Algol 68:


The number of independent primitive concepts has been minimized in order that the language be easy to describe, to learn, and to implement. On the other hand, these concepts have been applied “orthogonally” in order to maximize the expressive power of the language while trying to avoid deleterious superfluities.[10]

Orthogonality is a system design property which guarantees that modifying the technical effect produced by a component of a system neither creates nor propagates side effects to other components of the system. Typically this is achieved through the separation of concerns and encapsulation, and it is essential for feasible and compact designs of complex systems. The emergent behavior of a system consisting of components should be controlled strictly by formal definitions of its logic and not by side effects resulting from poor integration, i.e. nonorthogonal design of modules and interfaces. Orthogonality reduces testing and development time because it is easier to verify designs that neither cause side effects nor depend on them.

An instruction set is said to be orthogonal if it lacks redundancy (i.e. there is only a single instruction that can be used to accomplish a given task)[11] and is designed such that instructions can use any register in any addressing mode. This terminology results from considering an instruction as a vector whose components are the instruction fields. One field identifies the registers to be operated upon, and another specifies the addressing mode. An orthogonal instruction setuniquely encodes all combinations of registers and addressing modes.[citatio


Published originally   in etdart.blogspot.fi