Why write functions: void?

I have a habit of writing:

function functionName():void
{

}

If my function does not have a return type (": void"), however, I notice that my function will work if I write:

function functionName()
{

}

... without specifying a return type. Why is it considered a good form to display the return type as: void?

+3
source share
4 answers

Long and short is that every object in Flash has a data type. It can be a native data type, such as "String" or "Number" or "Array" or "int", or it can be a custom data type, such as "MyCustomClass" or "ICustomInterface".

Flash , , , . , , , Array - , , - . , , IWhatever , .

, : void . AS3 . - , Flash Player, , .

, . , . : int String, . - , , .

: void, , , , . , - , .

, !:)

+4

, :void, . ( .)

.

(: , , , , .)

+5

:

var expectedValue:String = functionName();

(, , ).

. .

0

" : void", C- , .

, Pascal, (void) , Pascal "". :

procedure sayHello();
begin
  writeln("Hello, from pascal!");
end;

function addTogether(a, b: integer);
begin
  Result:=a+b;
end;

Edit: Languages ​​like PHP also do not indicate what to return, in which case the default value (miracle of miracles ...) null. Critics claim that PHP does not have a type system, so a full functional signature may not be needed. I would give you a point for this, but the problem still persists, the return type is not considered the expected, not the value null.

-3
source

Source: https://habr.com/ru/post/1789137/


All Articles