Newer
Older
Master_thesis / thesis / parts.tex
\section{\zfit{} implementation}
\label{sec:parts}
\label{sec:concepts}

\textit{~~~~Things should not be easy or hard. But consistent.}
\bigbreak

In Sec. \ref{sec:quickstart} an example of a complete fit with 
\zfit{} was shown. While this was a rather simple example, \zfit{} generalizes 
to more complicated, custom model or 
higher dimensional fits in a consistent manner. The guiding principles that 
facilitate this generalization are

\begin{description}
	\item[One thing] The library is meant to do one thing: model fitting. 
	Additional capabilities like advanced 
	plotting, statistics etc. are intentionally left to other libraries.
	\item[Simplicity] As often stated, easy cases should be easy or at least 
	straightforward and not hard. For simple, one dimensional models and fits, 
	no extended knowledge about advanced concepts or pitfalls should be 
	necessary. Making mistakes can only happen when clearly leaving the 
	known grounds.
	\item[Consistency] When going from the simple to the more complex case, it 
	should not be necessary to learn a whole new set of rules and behaviour. 
	Instead,
	enough generality should be contained also in the simple case, even if it 
	means to slightly heighten the knowledge required for it. The overall
	difficulty should gradually increase, and expert knowledge should only be 
	required for expert problems.
	\item[Flexibility] No library can ever cover everything, so special cases 
	will need to be implemented specially, but most elements of the library 
	should nonetheless be usable and only the special part has to be 
	implemented specially.
\end{description}

These requirements can be conflicting. Especially flexibility and simplicity 
are 
hard to reconcile. A conflict arises with the potential of creating bugs: since 
not every case is the most complicated one, not every user will know about all 
peculiarities of the library and may uses the freedom in the wrong way. To 
avoid mistakes due to the lack of knowledge of the library but also incorporate 
the flexibility, \zfit{} follows the pythonic way, a term used to describe the 
philosophy behind Python and its usage. 

While the Python language itself, as any other language, consist of syntax 
specifications, a non-neglectable part of Python consists of its 
philosophy, the Zen of Python. A commonly used phrase in this context is the 
expression 
\textit{``We're all adults here"}. It refers for example to the absence of 
enforced private class attributes in Python. In its essence it means that 
anyone should be able to change anything, which offers a great flexibility. 

A complementary strong guidance is given by \textit{``There should be one -- 
and 
preferably only one -- obvious way to do it"}. This encourages to discuss 
problems appearing in the Python community and finding one ``best" way to solve 
a specific problem. And even if there is no ``best" solution, at least a 
convention should be agreed on. Combining these two ideas, \zfit{} provides 
a lot of freedom and allows to implement any part of the fit flow. To counter 
unintentional mistakes, clear guidelines and examples on \textit{how} to 
accomplish 
something specific are provided. This is especially important for the simpler 
cases, in which one clear way is shown.

In the following, we will go through a few essential pieces of the library that 
allow to extend the workflow naturally to more complex fits and discuss them in 
more detail.