<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog.farly</title>
	<atom:link href="http://blog.farly.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.farly.de</link>
	<description>distorted noise</description>
	<lastBuildDate>Tue, 24 Mar 2015 12:42:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.42</generator>
	<item>
		<title>A Sass Module Syntax</title>
		<link>http://blog.farly.de/sass-module-syntax/</link>
		<comments>http://blog.farly.de/sass-module-syntax/#comments</comments>
		<pubDate>Tue, 24 Mar 2015 12:40:06 +0000</pubDate>
		<dc:creator><![CDATA[jan]]></dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[modular]]></category>
		<category><![CDATA[sass]]></category>
		<category><![CDATA[scss]]></category>

		<guid isPermaLink="false">http://blog.farly.de/?p=57</guid>
		<description><![CDATA[<p>Complex CSS projects became way more elegant since the availability of pre processors.  Nevertheless some stuff always bugged me. We define variables on a global scope inside some project-wide _variables.scss file and include those everywhere. References are scattered everywhere. If you ever tried to comprehend a 2000+ line, not that well documented, non-bem scss file, nested up to &#8230; <a href="http://blog.farly.de/sass-module-syntax/" class="more-link">Continue reading <span class="screen-reader-text">A Sass Module Syntax</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.farly.de/sass-module-syntax/">A Sass Module Syntax</a> appeared first on <a rel="nofollow" href="http://blog.farly.de">blog.farly</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Complex CSS projects became way more elegant since the availability of pre processors.  Nevertheless some stuff always bugged me. We define variables on a global scope inside some project-wide _variables.scss file and include those everywhere. References are scattered everywhere. If you ever tried to comprehend a 2000+ line, not that well documented, non-bem scss file, nested up to 9 levels you&#8217;ll know.</p>
<p>Lets modularize our Sass to make it more reusable and easier to understand.</p>
<p>Before we start, please take a look at some <a href="http://alistapart.com/article/a-vision-for-our-sass" target="_blank">best practices</a> and <a href="https://css-tricks.com/sass-style-guide/" target="_blank">style guides</a> that&#8217;ll enable you to write more beautiful sass. Also even if not absolutely necessary for the described approach I&#8217;d highly recommend looking into <a href="https://en.bem.info/method/" target="_blank">BEM</a> structures. <a href="http://mikefowler.me/2013/10/17/support-for-bem-modules-sass-3.3/" target="_blank">A super nice syntax for that is supported since Sass 3.3</a>. (I&#8217;ll use <code>.block__element--modifier</code> here.)</p>
<p>Each of our modules (or blocks) will live inside it&#8217;s own file. Ideally we&#8217;ll have to write the module name only once inside that file. All variables used inside the module have to be defined by the module itself and must be scoped to it.<br />
Global variables can be passed down to the module. Listing all of them in the beginning acts like some kind of pseudo-constructor feeding data into the module. If the module is adapted to another project chances are only the variable declarations have to be touched.</p>
<p>My first thought was to use Sass&#8217; build in block scope: A variable defined within a block is scoped to that block. (Unless it has a !global flag.)<br />
I went ahead created a block named after our module(<code>.button {}</code>). Next I redeclared all needed variables inside it&#8217;s scope (<code>$button-border-width: 4px; $button-background-color: $some-global-color; …</code>). Even though this works I personally do not like that solution. There is no distinction between globals and non-globals. It&#8217;s quite easy to accidentally use a global var somewhere inside a module and create an unwanted dependency. Also there is no possibility to store the module name to reuse it and keep things DRY.</p>
<p>My favorite approach is to fake scope. I decided to reserve a global variable for the scope. I went with <code>$this</code> to make it look a little OO. Meaningful names for this (no pun intended) might also be <code>$scope</code> or <code>$module</code>. The variable is set to a map, containing all configurable data. It also has the module name. After all module definitions <code>$this</code> is set to null to clear it. The next module will then reuse <code>$this</code>.</p>
<p>To access the scoped data one could simply use the build in <code>map-get()</code> function. In my opinion it is a little verbose to always call <code>map-get()</code> passing it <code>$this</code> and the desired data-key. Therefore I created a little helper function: <code>this($key)</code> is as simple as it gets. It always <code>map-get()</code>&#8216;s the key from the <code>$this</code> map.</p>
<p>A reference to scoped data inside a module then looks like this:<br />
<code>color: this(color);</code></p>
<p>Sass&#8217; <a href="http://sass-lang.com/documentation/file.SASS_REFERENCE.html#interpolation_" target="_blank">interpolation feature</a> and the fact that were stored the module name in $this allows this selector syntax at our modules root:<br />
<code>.#{this(module)} {</code> …</p>
<p>And even comments can be fed with <code>this()'</code> data:<br />
<code>/* #{this(module)} Module */</code></p>
<p>Let&#8217;s take a look at all of that put together.</p>
<div class="codepen" data-height="739" data-theme-id="0" data-slug-hash="MYLbeL" data-default-tab="css" data-user="farly">
<pre><code>// layout.scss
@function this($key) {
 	@return map-get($this, $key);
}

$some-global-color: hotpink;

// _button.scss
$this: (
	module:						          button,
  
  border-width:               3px,

	background-color:			      white,
	color:						          $some-global-color,

	background-color-hover:	    $some-global-color,
	color-hover:				        white,

	background-color-disabled:	mix(white, lightgrey),
	color-disabled:				      mix($some-global-color, lightgrey),
);

/* #{this(module)} Module */

.#{this(module)} {
	background-color: this(background-color);
	color: this(color);
  display: inline-block;
  padding: 10px 20px;
  border: this(border-width) solid this(color);
  margin: 10px;
  text-transform: uppercase;

  &amp;:not(#{&amp;}--disabled):hover {
		background-color: this(background-color-hover);
		color: this(color-hover);
	}

	&amp;--disabled {
		background-color: this(background-color-disabled);
		color: this(color-disabled);
    border: this(border-width) solid this(color-disabled);
	}
}


// unset this
$this: null;
</code></pre>
<p>See the Pen <a href="http://codepen.io/farly/pen/MYLbeL/">Sass module /w faked scope</a> by Jan Willem Henckel (<a href="http://codepen.io/farly">@farly</a>) on <a href="http://codepen.io">CodePen</a>.</p>
</div>
<p><script src="//assets.codepen.io/assets/embed/ei.js" async=""></script></p>
<p>Don&#8217;t be afraid to store the same value in different keys. I like to think of the $this declaration as some kind of constructor. The time will come to reuse the button module, call it the fancy-button module and have the hover colors be something completely different. Because there is a map-key for all states all that has to be modified is the <code>$this</code> definition.</p>
<p>I&#8217;d love to hear your thoughts about this idea.</p>
<p>The post <a rel="nofollow" href="http://blog.farly.de/sass-module-syntax/">A Sass Module Syntax</a> appeared first on <a rel="nofollow" href="http://blog.farly.de">blog.farly</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.farly.de/sass-module-syntax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A modular approach (pt. 1)</title>
		<link>http://blog.farly.de/modular-approach-pt-1/</link>
		<comments>http://blog.farly.de/modular-approach-pt-1/#comments</comments>
		<pubDate>Tue, 20 Jan 2015 16:26:55 +0000</pubDate>
		<dc:creator><![CDATA[jan]]></dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.farly.de/?p=48</guid>
		<description><![CDATA[<p>Okay, I admit: I love php. People apparently don&#8217;t like hate it but I kinda grew up with that language. I just watched The Social Network http://t.co/kzMW1ch6EF&#10;&#10;No wonder Facebook is awful, he did it all in PHP &#38; Emacs. &#8212; I Am Devloper (@iamdevloper) January 4, 2015 Let&#8217;s see what we can do for a change. The recent versions &#8230; <a href="http://blog.farly.de/modular-approach-pt-1/" class="more-link">Continue reading <span class="screen-reader-text">A modular approach (pt. 1)</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.farly.de/modular-approach-pt-1/">A modular approach (pt. 1)</a> appeared first on <a rel="nofollow" href="http://blog.farly.de">blog.farly</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Okay, I admit: I love php. People apparently <del>don&#8217;t like</del> hate it but I kinda grew up with that language.</p>
<blockquote class="twitter-tweet" width="550"><p>I just watched The Social Network <a href="http://t.co/kzMW1ch6EF">http://t.co/kzMW1ch6EF</a>&#10;&#10;No wonder Facebook is awful, he did it all in PHP &amp; Emacs.</p>
<p>&mdash; I Am Devloper (@iamdevloper) <a href="https://twitter.com/iamdevloper/status/551871751047880705">January 4, 2015</a></p></blockquote>
<p><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p>
<p>Let&#8217;s see what we can do for a change. The recent versions of php gained some beautiful features as well as some syntactic sugar. Let&#8217;s build a slim framework, that allows any kind of server application to be fragmented into modules. In this part we will look into how we want our modules to look and feel. Here are some design goals:</p>
<ul>
<li>modularity</li>
<li>dependency injection</li>
<li>event based</li>
</ul>
<p><em>Note: This code requires at least php 5.4.</em></p>
<p>Each module is a standard php class. A singleton of that class is kept inside the main module loader. The module loader is also the factory for all modules. Everything is sitting nicely inside folders using and is included using a <a href="https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md" target="_blank">PSR-0 autoloader</a>. Every time a module depends on another module the module loader kicks in and sees if that module instance already exists. If not it <code>init()</code>-ializes it. Either way, the module will be there &#8211; ready to use. That process is called dependency injection. To define dependencies we will just have the required modules names as parameters.</p>
<p><script src="https://gist.github.com/djfarly/3a69d55bd2a304030323.js"></script></p>
<p>Let&#8217;s not worry how the module loader would handle dependency injection for now. But what are we going to do if we need parameters for that function? Yes you guessed right: Returning a function!</p>
<p><script src="https://gist.github.com/djfarly/4b0c3d6f370b36a6a733.js"></script></p>
<p>By returning a function we have the ability to sneak variables into it via the <code>use</code> keyword.  Let&#8217;s take this one more step further before we dig into the module loader.</p>
<p>Our module system is supposed to be event based. Here is our convention for events. If an event is triggered the module loader finds all registered modules, that respond to that type of event. A module responds to an event type if it implements an <code>on&lt;EventType&gt;()</code>-method. There is one problem though. Some modules need to do work before other can.</p>
<p><strong>Example</strong>: Two modules are registered for the <code>request</code>-event. Authentication and FileSystem. Authentication checks if we are allowed to do what we want to do. FileSystem simply responds with the requested file. Neither of those modules knows what the other one does. Authentication can opt out of the chain simply be throwing an Exception. But what if for some reason the module loader choose to execute FileSystems event handler first?</p>
<p>Event handlers need to be prioritized. And again you guessed correctly: We return an object that has a function and a priority build in. What else?</p>
<p><script src="https://gist.github.com/djfarly/c9d42f0982a64b23930c.js"></script></p>
<p>This is a way simplified implementation of what I currently use inside my Authentication module. <code>(object)[]</code> cast the returned array into an stdClass object. This is simply for looks. The the value of that objects link parameter is a function. And it is the same old function we already used earlier. The priority parameter holds a number. The way this syntax looks made me call the returned object &#8220;link object&#8221;.</p>
<p>The module loader will execute all available event handlers for all registered modules. It&#8217;ll then sort the link objects by priority. Higher priority will execute first. (At the moment no-priority defaults to 100, but I guess this is to be discussed.) Then all link functions are executed in order.</p>
<p>Here is a complete module before we discuss how the module loader works internally in the next post. (Notice: <strong>calm</strong> is the name of my current application.)</p>
<p><script src="https://gist.github.com/djfarly/8a8dd17d5f2489d8ae89.js"></script></p>
<p>Pew. The <code></code><code>init()</code> method is executed as soon as the module is first loaded. It is used because <code>__construct()</code> always returns <code>$this</code>. For dependency injection to work, we need to be able to return our link object. Therefore this additional step is necessary to set up stuff that requires stuff from other modules. Yay!</p>
<p>Part 2 will cover the internal workings of the module loader.</p>
<p>The post <a rel="nofollow" href="http://blog.farly.de/modular-approach-pt-1/">A modular approach (pt. 1)</a> appeared first on <a rel="nofollow" href="http://blog.farly.de">blog.farly</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.farly.de/modular-approach-pt-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Captain on the bridge</title>
		<link>http://blog.farly.de/captain-on-the-bridge/</link>
		<comments>http://blog.farly.de/captain-on-the-bridge/#comments</comments>
		<pubDate>Thu, 15 Jan 2015 20:00:19 +0000</pubDate>
		<dc:creator><![CDATA[jan]]></dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[swift]]></category>
		<category><![CDATA[Swift]]></category>

		<guid isPermaLink="false">http://blog.farly.de/?p=36</guid>
		<description><![CDATA[<p>How to fix &#8220;Method does not override&#8221; when subclassing UIGestureRecognizer So I tried to create an UI Element in Swift that responds to a specific Gesture. Easy enough let&#8217;s look up how that works. The almighty Internet has answers for everything: Subclass UIGestureRecognizer and override the methods touchesBegan, touchesMoved and touchesEnded. Okay, I can do that &#8211; but wait, &#8230; <a href="http://blog.farly.de/captain-on-the-bridge/" class="more-link">Continue reading <span class="screen-reader-text">Captain on the bridge</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.farly.de/captain-on-the-bridge/">Captain on the bridge</a> appeared first on <a rel="nofollow" href="http://blog.farly.de">blog.farly</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h2>How to fix &#8220;Method does not override&#8221; when subclassing UIGestureRecognizer</h2>
<p>So I tried to create an UI Element in Swift that responds to a specific Gesture. Easy enough let&#8217;s look up how that works. The almighty Internet has answers for everything:</p>
<p><em>Subclass UIGestureRecognizer and override the methods <code>touchesBegan</code>, <code>touchesMoved</code> and <code>touchesEnded</code>.</em></p>
<figure id="attachment_40" style="width: 660px;" class="wp-caption alignnone"><a href="http://blog.farly.de/wp-content/uploads/2015/01/Bildschirmfoto-2015-01-14-um-21.14.15.png"><img class="wp-image-40 size-large" src="http://blog.farly.de/wp-content/uploads/2015/01/Bildschirmfoto-2015-01-14-um-21.14.15-1024x68.png" alt="override func touchesBegan - Method does not override any method from its superclass" width="660" height="44" /></a><figcaption class="wp-caption-text">Method does not override any method from its superclass &#8211; wat?</figcaption></figure>
<p>Okay, I can do that &#8211; but wait, what?</p>
<p>It seems like the most recent version of Swift is missing some <code>public</code> declarations for those override-able methods. Probably because access control has just landed for Xcode/Swift the other day. At least <a href="http://blog.jaredsinclair.com/post/93992930295/for-subclass-eyes-only-swift">Jared Sinclair supports this theory</a>.</p>
<p>He also offers a Solution: Import UIGestureRecognizerSubclass.h in your Bridging-Header. I am new to this, how do you do that? Turns out Xcode creates the Bridging-Header file for you if you create an Objective-C file in your project. Due to some back and forth I learned that it unfortunately only does that once. If you ever deleted the file it will not come back. So how do you create it manually?</p>
<ol>
<li>Create a new Objective-C Header file and name it <code>&lt;projectName&gt;-Bridging-Header.h</code></li>
<li>Go to your Project Root and then find &#8220;Build Settings&#8221;</li>
<li>Scroll all the way down and locate the &#8220;Swift Compiler &#8211; Code Generation&#8221; section</li>
<li>Insert the path to your header file into the &#8220;Objective-C Bridging Header&#8221; field (Notice that the file might be in the root folder [like mine] or somewhere else)</li>
<li>Set &#8220;Install Objective-C Compatibility Header&#8221; to true</li>
</ol>
<figure id="attachment_41" style="width: 660px;" class="wp-caption alignnone"><a href="http://blog.farly.de/wp-content/uploads/2015/01/Bildschirmfoto-2015-01-14-um-21.30.49.png"><img class="size-large wp-image-41" src="http://blog.farly.de/wp-content/uploads/2015/01/Bildschirmfoto-2015-01-14-um-21.30.49-1024x158.png" alt="Objective-C Bridging Header" width="660" height="102" /></a><figcaption class="wp-caption-text">My Settings for the Bridging Header</figcaption></figure>
<p>Back to the actual solution. Insert this one line into the header file:</p>
<p>https://gist.github.com/552655716a2016b11566</p>
<p>And voila &#8211; it works. Suddenly all the desired Methods are avaiable. Well, that was simple.</p>
<p>The post <a rel="nofollow" href="http://blog.farly.de/captain-on-the-bridge/">Captain on the bridge</a> appeared first on <a rel="nofollow" href="http://blog.farly.de">blog.farly</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.farly.de/captain-on-the-bridge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hashtag Swift</title>
		<link>http://blog.farly.de/hashtag-swift/</link>
		<comments>http://blog.farly.de/hashtag-swift/#comments</comments>
		<pubDate>Wed, 14 Jan 2015 16:14:07 +0000</pubDate>
		<dc:creator><![CDATA[jan]]></dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[swift]]></category>
		<category><![CDATA[Swift]]></category>

		<guid isPermaLink="false">http://blog.farly.de/?p=12</guid>
		<description><![CDATA[<p>I recently started developing for iOS using Swift. I did a little project creating a simple tic tac toe app nearly a year ago. Written in Objective-C obviously, because Swift hasn&#8217;t been around back then. I remember being stunned by the weirdness the language had to offer; especially coming from a php and javascript background. Let &#8230; <a href="http://blog.farly.de/hashtag-swift/" class="more-link">Continue reading <span class="screen-reader-text">Hashtag Swift</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.farly.de/hashtag-swift/">Hashtag Swift</a> appeared first on <a rel="nofollow" href="http://blog.farly.de">blog.farly</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>I recently started developing for iOS using Swift. I did a little project creating a simple tic tac toe app nearly a year ago. Written in Objective-C obviously, because Swift hasn&#8217;t been around back then. I remember being stunned by the weirdness the language had to offer; especially coming from a php and javascript background. Let me give you a little example:</p>
<p>https://gist.github.com/1448a92686ee40cb7db6</p>
<p>For people that do not know Objective-C let me guide you through this a litte. This is the implementation of a class method named <code>getFieldTextAtRow:andCol:</code>. It takes to Integers (row and col) and returns an NSString. In the return statement the class method <code>getFieldAtRow:andCol:</code> is called passing the two variables into it. It then asks for the <code>.text</code> property of the returned object. Wow. Calling Methods on an object requires some strange square bracket syntax. Accessing parameters on the other hand is just a plain simple <code>Object.parameter</code>. A dash defines a method. A simple String is a NSString (which is written as <code>@"String"</code>) and method name and parameters are entangled. I could go on&#8230; but, lets not ramble about dem ol&#8217; days too much: Along comes Swift.</p>
<blockquote><p>Swift is an innovative new programming language for Cocoa and Cocoa Touch. Writing code is interactive and fun, the syntax is concise yet expressive, and apps run lightning-fast.</p></blockquote>
<p>Let&#8217;s look at the example Method again &#8211; this time written in Swift:</p>
<p>https://gist.github.com/d61634ebbf747715e0cd</p>
<p>A String is a string; A method is defined with a <code>func</code> keyword and a method is called just like a function. The name of the method is just <code>getFieldText</code>. Because of backwards compatibility (I guess) parameter names are still in the call. Exception to the rule is the first parameter. Objective-C had it inside the first part of the method name, so Swift &#8220;needs&#8221; to do that too. <code>func getFieldTextForRow(row: Int, col: Int) -&gt; String</code> would be called like <code>getFieldTextForRow(13, col: 37)</code>. The hash symbol in front of the first parameter tells the compiler, that you do want to explicitly name it. So basically that number sign makes stuff more consistent and a little less awkward. I tend to use it all the time.</p>
<p>After all Swift lets you do very cool stuff and in some aspects it is miles ahead of other languages. But some of the &#8220;I-need-to-support-all-the-weirdness-of-my-grumpy-father&#8221;-aspects just leave me scratching my head.</p>
<p>The post <a rel="nofollow" href="http://blog.farly.de/hashtag-swift/">Hashtag Swift</a> appeared first on <a rel="nofollow" href="http://blog.farly.de">blog.farly</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.farly.de/hashtag-swift/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
