Sider Fra The Definitive Guide To Power Query M Kode
Sider Fra The Definitive Guide To Power Query M Kode
Formal Classification
An impure programming language allows side effects, which are actions that
cause changes outside the scope of a function's return value. In the case of M, it
is commonly used for data transformation and retrieval tasks, which often
involve interacting with external data sources, performing operations on data,
and producing output. These actions constitute side effects because they affect
the state of the data source or produce output beyond the function's return
value.While M provides functional programming constructs and supports
immutability, allowing for the creation of pure functions, the language is not
purely functional due to its impure nature. It embraces a combination of
functional and imperative programming paradigms to facilitate efficient and
practical data manipulation and retrieval.
Higher-order – For lower order languages, such as machine code an
assembly language, each programming statement corresponds to a single
instruction for the computer while in higher order languages each statement
corresponds to multiple instructions for the computer.
Higher order languages typically allow such things as functions, objects, and
modules to be used as values within the program. Higher order languages often
treat functions as first-class citizens. Specifically, this means that functions can
be assigned to variables, passed as arguments to other functions, and returned as
values from functions.Power Query M supports higher-order programming by
allowing you to define and manipulate functions as values. You can assign
functions to variables, pass functions as arguments to other functions, and return
functions as results. This enables you to create more modular and flexible code
by abstracting and reusing function logic.With higher-order programming
capabilities, M allows you to apply transformations and computations
dynamically based on input parameters, control flow, and data characteristics.
You can write functions that operate on other functions, enabling powerful data
manipulation and transformation scenarios.For example, you can use higher-
order functions in M to dynamically apply a series of transformations to a
dataset based on user-defined criteria or to create reusable function pipelines for
data processing.By providing higher-order programming features, M empowers
developers to write expressive and modular code, making it easier to work with
complex data transformations and customize the behavior of functions to suit
specific requirements.
This code would not generate an error in Python even though two different data
types are assigned to the variable a. However, similar code is not possible in M
since variables, once calculated are immutable (cannot be changed).The
flexibility in data typing allows Power Query M to handle a wide range of data
sources and perform various data transformations effectively. It simplifies the
process of working with heterogeneous data sets that may contain different data
types and structures.It is important to note that even though Power Query M is
weakly typed, it still performs type checking during execution (runtime) to
ensure the consistency of operations. If a particular operation is not compatible
with the inferred type of a value, an error may occur at runtime.Overall, the
weakly typed nature of Power Query M strikes a balance between flexibility and
data integrity, providing users with a versatile language for data transformation
tasks.
The term "partially lazy" refers to a specific feature within M called lazy
evaluation, which is distinct from the overall evaluation strategy of the language.
In M, lazy evaluation is applied to expressions within some specific constructs,
specifically List, Record, and Table expressions as well as the let expression.
These constructs allow you to define expressions that are evaluated only when
needed, providing a form of on-demand or lazy evaluation within those
contexts.M also allows you to define optional arguments for functions. These
optional arguments are evaluated lazily, meaning they are not computed unless
explicitly used within the function body. Lazy evaluation of optional arguments
helps optimize performance by avoiding unnecessary computations for optional
values that are not actually used within the function. It ensures that the
computations for optional arguments are deferred until their values are required
within the function's execution.M also supports conditional branching constructs
like if-then-else statements. Only the branch that matches the condition is
evaluated, while the other branch is not computed, resulting in lazy evaluation.
This is in contrast to an eager evaluation strategy where both branches are
evaluated regardless of the condition’s outcome. This form of lazy evaluation
within the if-then-else construct allows for efficient computation by avoiding
unnecessary evaluations of expressions in the non-matching branch.It is
important to note that while M has these partially lazy features, the overall
evaluation strategy of the language remains predominantly eager. Most
expressions in Power Query M are eagerly evaluated, ensuring that data
transformations occur promptly, and results are immediately available for further
processing. Thus, M is primarily an eager programming language, but it
incorporates partial lazy evaluation in specific constructs, such as for List,
Record, Table, and the let expressions as well as optional function arguments
and conditional branching. These partially lazy evaluations offer flexibility and
optimize performance within those contexts.
M encourages immutability, meaning that data values are not modified in place
but transformed into new values. This promotes the functional programming
principle of avoiding side effects.M supports higher-order functions, allowing
functions to be treated as first-class values. You can pass functions as arguments
to other functions, return functions from functions, and store functions in
variables.M facilitates function composition, enabling you to combine multiple
functions to create more complex transformations. This composability is a
characteristic of functional programming.M promotes the use of pure functions,
which have no side effects and produce the same output for the same input. Pure
functions make code more predictable and easier to troubleshoot.M supports
recursion. While recursion is not as extensively supported as in some other
functional languages, M does offer limited support for recursive functions,
allowing developers to solve problems through recursive techniques.In terms of
comparison with other languages, M is perhaps most similar to F#, a
programming language developed and implemented by Don Syme of Microsoft
Research, Cambridge UK. Now that we have covered the formal classification of
the M language, let’s next take a look at some more informal characteristics of
M.
Informal Characteristics of M
History of M
The history of the M language, is closely tied to the evolution of Microsoft's data
transformation and integration technologies. Here is a brief overview of the
history of M:
The query language was thought of as a mashup language (hence the M for
mashup).
Throughout its history, the M language has evolved to become a key component
of Microsoft's data transformation and integration tools, including Power Query,
Power BI, Excel, and more. Its versatility and extensibility have made it a
valuable language for data professionals seeking efficient data manipulation
capabilities.Let’s now turn our attention to who should learn M.