Logo

Programming-Idioms

  • Perl
  • Js

Idiom #3 Create a procedure

Like a function which doesn't return any value, thus has only side effects (e.g. Print to standard output)

function bli() { 
	console.log('Hello World!!!');
}
const greet = who => console.log(`Hi ${who}!`)

Arrow function syntax. It consists of three parts: arguments, arrow and code block.
var bli = function() { 
	console.log('Hello World!!!');
}
let dog = 'Poodle';
const dogAlert = () => alert(dog);
sub some_procedure {
    print 'some side effect';
    return;
}

Due to context sensitivity and automatic value conversions on assignment, it is de facto not possible to not return a value. Even a naked `return;` will result in `undef` or empty list at the caller. A naive attempt to fix the problem by omitting the return statement does not help: then the return value of the last statement before exiting the subroutine will be used instead; in the example, that would be the return value of `print`.
procedure Finish (Name : String) is
begin
   Put_Line ("My job here is done. Goodbye " & Name);
end Finish;

New implementation...
< >
programming-idioms.org