In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. It is a declarative programming paradigm, which means programming is done with expressions and declarations instead of structured statements.

Functional programming:

By using functional programming we enable code optimization technique not available for structured programming. This is an optional feature that is implemented by alternative compilers to generate better executable code.

 function rules.

  1. A function is pure if is deterministic and do not have side effects;
  2. A function that is pure can be optimized by the compiler using internal cache and tail recursion;
  3. A function that use or modify a state variable or receive parameters by reference is not pure;
  4. A function that call another function that is not pure it is also not pure;

Design principles

Level is designed for _sage code_ programming. To use Level correctly developers must understand some basic design principles. These are part of _sage code_  good practice.

#The principleDetails
1When in doubt, parameterizeWhen you are not sure make a new parameter instead of shared state variable.
2Local is better then globalWe use let to define local scope to avoid global scope declarations.
3Group globals into recordsAvoid using global variables. If you have them group several into a global record.
4Favor loops over recursionRecursive functions are hard to debug. Loops are more efficient and safe to use.
5Avoid side-effectsSide-effects are difficult to comprehend. Pure functions are more safe.
6Do not stay astray from left sideDeep code indentation makes code unreadable.
7Do not be afraid of long programsDo not create functions and libraries if not necessary. Level has support for very large program files.
7Initialize early rather then laterAvoid differed initialization. Working with uninitialized references can be a source of run-time errors.

Language Features

In this chapter we will explain several additional features that makes Level a versatile language.

01dynamic functionsdefine functions using dynamic expressions
02recursive functionsfunctions that can call themselves
03dispatchcreate multiple functions using same name and different signatures
04closuresfunction that encapsulate another function
05generatorsfunction that can be interrupted and resumed to generate result on demand
06type methodsbound methods to types using single dispatch
07dynamic collectionslist, map, set
08set operatorsunion, intersection …
09slicing techniqueextract a subset from a set
10new typestext, json, complex, rational
11type castingconvert one type into other
12type inferenceuse deduction to infer variable type
13introspectionprogram know about himself (description, trace, type inquery)
14regular expressionsfor parsing a text or string
15text templatesinsert variable values into text
16system storageto create and open files
17web servicesapplication servers and back-end programming
18internet servicesinternet and cloud based applications

You need to login to view the rest of the content. Please . Not a Member? Join Us