Latex Presentation Template
This is going to be a short post, but thanks to Lorna Jane & Matthew Weier O`Phinney I've been using Latex to generate PDF slides for my upcoming talks. Over the last few weeks I've been doing a lot of learning in regards to how it works and how to use it more efficiently. Lorna has an excellent entry in her blog that shows how to actually run latexmk to generate the slides here and another excellent entry on markup here. Matthew Weier O`Phinney and I have been talking about an awesome program on github called pdf-presenter-console which makes life easier as a presenter, it seems like an interesting tool and I'll be covering it at some point more in depth.
On Ubuntu these are the packages you will need:
-
texlive-publishers texlive-latex-recommended latemk texlive-fonts-extra latex-fonts-recommended
(I may have forgotten one or two but will add if I discover any more)
And here is my template:
-
\usepackage{listings}
-
\usepackage{color}
-
\usepackage{textcomp}
-
-
% Code Listing Stuff
-
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
-
\lstset{
-
language=PHP,
-
tabsize=2,
-
backgroundcolor=\color{lbcolor},
-
rulecolor=,
-
extendedchars=true,
-
frame=single,
-
breakatwhitespace=true,
-
breaklines=true,
-
identifierstyle=\ttfamily,
-
keywordstyle=\color[rgb]{0,0,1},
-
commentstyle=\color[rgb]{0.133,0.545,0.133},
-
stringstyle=\color[rgb]{0.627,0.126,0.941},
-
morekeywords={class, interface, namespace, abstract, new, return, function, public, protected, private, implements, extends, use, as, throws, catch}
-
}
-
% Presentation Metadata
-
\title{Title}
-
\author{Shawn Stratton}
-
\date{\today}
-
\begin{document}
-
\maketitle
-
\begin{slide}{Slide Title}
-
\begin{itemize}
-
\item Item1
-
\item Item2
-
\end{itemize}
-
\end{slide}
-
\section{Section Title}
-
\begin{slide}{New}
-
\vspace*{\fill}
-
\begin{figure}
-
\centering
-
\includegraphics[width=0.6\slidewidth]{images/sample.eps}
-
\caption{This is a centered (both horizontal & vertical image}
-
\end{figure}
-
\vspace*{\fill}
-
\end{slide}
-
\begin{note}
-
This is a note
-
\end{note}
-
\begin{slide}{Source Inclusion}
-
\vspace*{\fill}
-
\lstinputlisting{src/file.php}
-
\vspace*{\fill}
-
\end{slide}
-
\end{document}
The command to run to generate the presentation:
-
latexmk -f -pdfps presentation.tex
Accesors and Religion
Today I'm going to become flame bait, I'm going to talk about something that's highly controversial, not because most view points on it are wrong but because everyones differ and they're all wrong besides mine. Well there went my attempt at being sarcastic, but seriously, this is one of those discussions that will always be highly controversial.
The Problem
Objects have properties which sometimes need special logic on how they are retrieved and set. There are several solutions to this and everybody has a different view point about which is correct, none are pretty and all have drawbacks which range from writing extra code, creating something that has poor extensibility, or has issues with consistency. These don't even breach the issues with IDE code completion and analysis. Lets look at some of these solutions.
The Solutions
Direct Access to properties
So when you first start getting into objects the very first thing that most people do is create a whole bunch of public properties that are accessed like this
-
public $whatever;
-
}
-
$obj->whatever = 'whatever';
This works well, you can set things outside of the object and then have the object act on it, the problem comes in when you need to modify the way the data is handled when it's set or retrieved without hanging client code. That's generally when people start writing accessor methods and changing client code which leads to our second solution.
Mixture of Accessors and Direct Property Accessors
Once you start seeing needs of modifying data as it's being assigned you'll start seeing code like this:
-
public $whatever;
-
public $stuff;
-
public function setWhatever($value);
-
public function getWhatever();
-
}
-
$obj->stuff = 'stuff';
-
$obj->setWhatever('whatever');
Usually this only lasts a little while, usually someone will completely forget about the accesor methods and work with the property directly and cause some great inconsistencies, then as an act of paranoia someone will mark the property as protected or private. This is still a problem as it leads to great inconsistencies, then the next step comes up.
Accessors for everything
This is usually the level most hit and stay at, they start writing accessors for every property that's supposed to be publicly accessible, your code here will start to look like this:
-
protected $stuff;
-
protected $whatever;
-
public function getStuff();
-
public function setStuff($value);
-
public function getWhatever();
-
public function setWhatever($value);
-
}
-
$obj->setStuff('stuff');
-
$obj->setWhatever('whatever');
At this level consistency is no longer a problem and you can easily extend the functionality of your getters/setters which is awesome, some even figure out to return $this in the setters so they can do chaining, at which point you client code can look like this
-
$obj->setStuff('stuff')->setWhatever('whatever'):
There are downsides with this though, you'll have to write two methods that have to be compiled and referenced for every property you have, this makes the code very verbose and very long. Some people have solved this issue with __call which is called every time you call a function that doesn't exist. This usually looks like:
-
protected $stuff;
-
protected $whatever;
-
public function __call($name, $params)
-
}
With some logic you can easily have the function check for get/set at the beginning of the method name; it works but it's slow and it means that IDE's won't detect the setters/getters and magic is generally not the best thing. The even worse case of this is people use __get and __set to overwrite everything, but it does work on every protected/public property and it's an easy way to centralize getters and setters. This leads us to our last idea, which I personally think is the best way to handle the situation.
My Solution
Obviously we want the ability to overwrite the way things are set, we also need consistency so that we're backwards compatible and the developers don't get confused by what's set via setter and what's set via direct property access, ultimately we don't want to write a bunch of functions just to set and get the values of our properties, it's kinda silly actually, thinking of all those function calls and completely discarding PHP's Property Setting also seems a little foolish. Anyway, ultimately I came up with the following solution and it works really well for me and the people I work with.
-
{
-
//check if a accessor function exists
-
$accessor = 'set'.ucfirst($key);
-
if (method_exists($this, $accessor))
-
{
-
return $this->$accessor($value);
-
}
-
}
-
public function __get ($key)
-
{
-
$accessor = 'get'.ucfirst($key);
-
if (method_exists($this, $accessor))
-
{
-
return $this->$accessor();
-
}
-
}
With this code in our Model Abstract we are able to call everything via the default method of setting properties i.e.
-
$object->property = $value;
Most properties would then be marked public, with properties meant to be accessed in this way being set to protected and having set/get functions written for them (that are then marked protected to keep the api clean and to keep interaction sane.) There is one obvious glaring downside to this though, this does not work with IDE auto-completion, and boy do I wish it did, but out of all things to sacrificed that's pretty minimal. Also I should mention that the above code does not do any error setting which has been omitted in my example.
Conclusion
There are many ways you can skin this metaphorical cat, however, they each have trade-offs. Ultimately I went with the methodology that made the most sense to me and that passed our architectural standards (consistency) but you may have a different use case and that's fine.