<?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>Oliver Joseph Ash</title>
    <atom:link href="http://oliverash.me/feed.xml" rel="self" type="application/rss+xml" />
    <link>http://oliverjash.me</link>
    <description>I care about making great software.</description>
    <lastBuildDate>Mon, 24 Nov 2014 13:23:11 +0100</lastBuildDate>
    <language>en</language>
    <copyright>Oliver Joseph Ash</copyright>

    

      

      

      <item>
        <title>Comment Your CSS&amp;#58; Relationships</title>
        <link>
        http://oliverjash.me/2014/11/20/comment-your-css-relationships.html
      </link>
        <pubDate>Thu, 20 Nov 2014 00:00:00 +0100</pubDate>
        <guid>
        http://oliverjash.me/2014/11/20/comment-your-css-relationships.html
      </guid>
        <description>
        
          &lt;p&gt;In this post, I will demonstrate situations in which we create relationships between rules in our CSS, before arguing for more discipline when authoring CSS to make such relationships explicit in our code.&lt;/p&gt;

&lt;h1 id=&#39;resets&#39;&gt;Resets&lt;/h1&gt;

&lt;p&gt;A DOM element can have multiple rules as the result of four different design patterns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the HTML is configured, classes can be composed together on a single element, or the way the HTML is configured to create a DOM tree could result in elements inheriting styles from rules applied to parents.&lt;/li&gt;

&lt;li&gt;At runtime, media queries can augment elements with additional rules.&lt;/li&gt;

&lt;li&gt;When the CSS is authored, class inheritance results in an element having multiple rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When an element has multiple rules, conflicting style declarations between these rules can result in &lt;em&gt;style resets&lt;/em&gt;. The following examples demonstrate how style resets can occur when an element is rendered with multiple rules.&lt;/p&gt;
&lt;!-- in some predictable and some unpredictable ways --&gt;
&lt;h2 id=&#39;class_composition&#39;&gt;Class composition&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;.widget {
    border: 1px solid black;
    padding: 1rem;
}

.widget--alt {
    border: initial;
}

&amp;lt;div class=&amp;quot;widget widget--alt&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;img alt=&#39;The reset, as seen by Chrome DevTools’ style inspector&#39; src=&#39;/images/posts/override-1.png&#39; /&gt;
&lt;p&gt;In this example, when these classes are composed together on an element, &lt;code&gt;.widget-alt&lt;/code&gt; &lt;em&gt;resets&lt;/em&gt; &lt;code&gt;border&lt;/code&gt; back to its &lt;em&gt;initial&lt;/em&gt; value, &lt;code&gt;initial&lt;/code&gt;. Thus, there is a relationship between &lt;code&gt;.widget&lt;/code&gt; and &lt;code&gt;.widget--alt&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;(I have used BEM as an example of class composition because it is a realistic example given the best practices of the day.)&lt;/p&gt;

&lt;h2 id=&#39;style_inheritance&#39;&gt;Style inheritance&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;body {
    text-align: center;
}

.widget {
    border: 1px solid black;
    padding: 1rem;
}

&amp;lt;body&amp;gt;
    &amp;lt;div class=&amp;quot;widget&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;img alt=&#39;The inherited style, as seen by Chrome DevTools’ style inspector&#39; src=&#39;/images/posts/inheritance-1.png&#39; /&gt;
&lt;p&gt;Style inheritance means that elements can inherit &lt;a href=&#39;http://www.w3.org/TR/CSS21/propidx.html&#39;&gt;some styles&lt;/a&gt; from rules applied to parent elements. In this example, the &lt;code&gt;div.widget&lt;/code&gt; element will inherit a &lt;code&gt;text-align&lt;/code&gt; style from the parent &lt;code&gt;body&lt;/code&gt; element.&lt;/p&gt;

&lt;p&gt;In many ways, style inheritance is a powerful feature of CSS because it allows you to easily scope styles. For example, we could use style inheritance to give the whole page a &lt;code&gt;font-family&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If we don’t want to inherit a style that is by default inherited, we must opt-out. In the following example, &lt;code&gt;.widget&lt;/code&gt; &lt;em&gt;resets&lt;/em&gt; &lt;code&gt;text-align&lt;/code&gt; back to its &lt;em&gt;initial&lt;/em&gt; value, &lt;code&gt;initial&lt;/code&gt;. Thus, there is a relationship between the &lt;code&gt;.widget&lt;/code&gt; and &lt;code&gt;body&lt;/code&gt; rules.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.widget {
    border: 1px solid black;
    padding: 1rem;
    text-align: initial;
}&lt;/code&gt;&lt;/pre&gt;
&lt;img alt=&#39;The reset, as seen by Chrome DevTools’ style inspector&#39; src=&#39;/images/posts/override-4.png&#39; /&gt;
&lt;p&gt;Because of style inheritance, &lt;code&gt;.widget&lt;/code&gt; could be penetrated with other styles depending on the DOM configuration, forgoing any hope of encapsulation. Why should &lt;code&gt;.widget&lt;/code&gt; care about styles that it &lt;em&gt;might&lt;/em&gt; inherit if it is used in a specific position in the DOM (in this case, a child of the &lt;code&gt;body&lt;/code&gt; element)? With the addition of the &lt;code&gt;text-align&lt;/code&gt; reset, &lt;code&gt;.widget&lt;/code&gt; makes assumptions about what styles will appear on a parent somewhere. A truly ecanspulated class would not have to care about its environment. Our CSS shouldn&amp;#8217;t need to know about how the HTML will be configured, because classes should be work whereever they reside in the DOM hierachy.&lt;/p&gt;

&lt;p&gt;Fortunately, the forthcoming &lt;a href=&#39;http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-201/#toc-style-scoped&#39;&gt;Shadow DOM&lt;/a&gt; features real encapsulation for CSS, requiring explicit opt-in to style inheritance (instead of having to explicitly opt-out like we do today).&lt;/p&gt;

&lt;h2 id=&#39;media_queries&#39;&gt;Media queries&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;.widget {
    border: 1px solid black;
    padding: 1rem;
}

@media (min-width: 500px) {
    .widget {
        border: initial;
    }
}&lt;/code&gt;&lt;/pre&gt;
&lt;img alt=&#39;The reset, as seen by Chrome DevTools’ style inspector&#39; src=&#39;/images/posts/override-2.png&#39; /&gt;
&lt;p&gt;Media queries can augment elements with additional rules at runtime. In this example, &lt;code&gt;.widget&lt;/code&gt; &lt;em&gt;resets&lt;/em&gt; &lt;code&gt;border&lt;/code&gt; back to its &lt;em&gt;initial&lt;/em&gt; value, &lt;code&gt;initial&lt;/code&gt;. Thus, there is a relationship between the two &lt;code&gt;.widget&lt;/code&gt; rules.&lt;/p&gt;

&lt;h2 id=&#39;class_inheritance&#39;&gt;Class inheritance&lt;/h2&gt;

&lt;pre&gt;&lt;code&gt;.heading-1 {
    font-size: 2rem;
    text-decoration: underline;
}

.page-title {
    @extend .heading-1;
    text-decoration: initial;
}

&amp;lt;body&amp;gt;
    &amp;lt;div class=&amp;quot;page-title&amp;quot;&amp;gt;Home&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Many CSS pre-processors enable fake class inheritance with the help of some sugar syntax. (I&amp;#8217;m using Sass here; others may differ slightly in syntax.) Our pre-processor transpiles this by extending the &lt;code&gt;.heading-1&lt;/code&gt; ruleset to add the &lt;code&gt;.page-title&lt;/code&gt; selector. For reference, the output CSS we are really interested in looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.heading-1,
.page-title {
    font-size: 2rem;
    text-decoration: underline;
}

.page-title {
    text-decoration: initial;
}

&amp;lt;body&amp;gt;
    &amp;lt;div class=&amp;quot;page-title&amp;quot;&amp;gt;Home&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;img alt=&#39;The reset, as seen by Chrome DevTools’ style inspector&#39; src=&#39;/images/posts/override-3.png&#39; /&gt;
&lt;p&gt;As a result of class inheritance, subclasses are given two rules in the CSS. In this example, the &lt;code&gt;.page-title&lt;/code&gt; subclass &lt;em&gt;resets&lt;/em&gt; &lt;code&gt;text-decoration&lt;/code&gt; back to its &lt;em&gt;initial&lt;/em&gt; value, &lt;code&gt;initial&lt;/code&gt;. Thus, there is a relationship between the two &lt;code&gt;.page-title&lt;/code&gt; rules.&lt;/p&gt;

&lt;h1 id=&#39;positioning&#39;&gt;Positioning&lt;/h1&gt;

&lt;p&gt;Relationships can also occur between elements when a parent element creates a new &lt;em&gt;positioning context&lt;/em&gt; or &lt;em&gt;stacking context&lt;/em&gt;. This happens when you use a value of &lt;code&gt;relative&lt;/code&gt; or &lt;code&gt;absolute&lt;/code&gt; for the &lt;code&gt;position&lt;/code&gt; style.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.hero-image {
    background-image: url(…);
    position: relative;
}

.hero-image__text {
    position: absolute;
    bottom: 0;
    left: 0;
}

&amp;lt;div class=&amp;quot;hero-image&amp;quot;&amp;gt;
    &amp;lt;div class=&amp;quot;hero-image__text&amp;quot;&amp;gt;Some text on top of the hero image&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In this example, &lt;code&gt;.hero-image__text&lt;/code&gt; positions itself at the absolute bottom left of its &lt;em&gt;current positioning context&lt;/em&gt;, which is defined by the parent &lt;code&gt;.hero-image&lt;/code&gt;. Thus, there is a relationship between &lt;code&gt;.hero-image&lt;/code&gt; and &lt;code&gt;.hero-image__text&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Likewise, any child of a relative or absolutely positioned element that has a &lt;code&gt;z-index&lt;/code&gt; will also have a relationship because this position setting creates a new stacking context.&lt;/p&gt;

&lt;h1 id=&#39;comment_your_css&#39;&gt;Comment Your CSS&lt;/h1&gt;

&lt;p&gt;If we model these relationships in our head when we author CSS, why don&amp;#8217;t we model them in our code? We&amp;#8217;re likely to forget these relationships exist at all if they are not documented.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.widget {
    /* border: 1px solid black; */
    padding: 1rem;
}

.widget--alt {
    border: initial;
}

&amp;lt;div class=&amp;quot;widget widget--alt&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Imagine you revisit a BEM “block class” (in this example, &lt;code&gt;.widget&lt;/code&gt;) to remove its &lt;code&gt;border&lt;/code&gt; (now commented out). In this example, a relationship has been broken between &lt;code&gt;.widget&lt;/code&gt; and &lt;code&gt;.widget--alt&lt;/code&gt;. Previously the BEM “modifier class” reset the &lt;code&gt;border&lt;/code&gt; style back to its initial value. It&amp;#8217;s easy to see that we can now remove the &lt;code&gt;border&lt;/code&gt; declaration from &lt;code&gt;.widget--alt&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In a large codebase, it could be difficult to see when you have broken relationships. Furthermore, and as we have seen, relationships can exist in several other forms, which could be manifested like spaghetti across your codebase. In my experience, this can lead to stray CSS. &lt;strong&gt;Any change you make in CSS could deem other styles redundant.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;CSS is write only. You need to know every possible configuration of HTML you will ever render to know when it&amp;#8217;s safe to delete a rule &lt;span&gt;or style&lt;/span&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;– &lt;a href=&#39;http://youtu.be/VkTCL6Nqm6Y?t=23m41s&#39;&gt;Pete Hunt&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The big problem with stray CSS is that, if left undocumented, it can self-perpetuate: you overcome the stray CSS with a quick fix by resetting it, yet resets were the problem that lead to stray CSS in the first place. Alternatively, you can manually challenge each style to test its prevailing relevance given the current usage, but this can only be done by CSS experts. I call this phenomenon “reset culture”, whereby resets are constantly hacked into the codebase as a quick fix.&lt;/p&gt;
&lt;img alt=&#39;The reset, as seen by Chrome DevTools’ style inspector&#39; src=&#39;/images/posts/override-1.png&#39; /&gt;
&lt;p&gt;When I look at my CSS, I want to know why styles exist so I know what&amp;#8217;s safe to delete or change. Developer tools can show us how our CSS plays together, but we can&amp;#8217;t see it in our codebase.&lt;/p&gt;

&lt;p&gt;&lt;a href=&#39;https://gist.github.com/OliverJAsh/aeb5bf62e062ecc294d7&#39;&gt;I have long wished for an IDE to show me the result of my CSS&lt;/a&gt; in the same way browser developer tools do. For now, I&amp;#8217;ve resorted to discipline in the form of commenting all relationships.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;.widget {
    border: 1px solid black;
    padding: 1rem;
}

.widget--alt {
    // Reset: .widget
    border: initial;
}

&amp;lt;div class=&amp;quot;widget widget--alt&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If a relationship is broken in a future version of this CSS and the author forgets to clean up, anyone who does revisit the redundant style will see, because of the comment, that it is no longer needed. If the stray CSS was left undocumented, it would likely never be removed (unless manually challenged), adding bloat to the codebase and creating a culture of fear in the CSS whereby the solution is to always override unusual looking styles. The same is true for all the other relationships I demonstrated previously.&lt;/p&gt;

&lt;p&gt;Ultimately, resets are a side effect of the cascade. We should ask ourselves whether the cascade works for or against us for the sort of websites (or web apps, rather) that we build today. I hope we will see more research into the relevance of CSS today.&lt;/p&gt;

&lt;h1 id=&#39;postscript&#39;&gt;Postscript&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;In the resets section I used the &lt;code&gt;initial&lt;/code&gt; and &lt;code&gt;inherit&lt;/code&gt; keywords. This could be improved by using the &lt;code&gt;unset&lt;/code&gt; keyword, which evaluates to &lt;code&gt;inherit&lt;/code&gt; for styles that are inherited by default, and &lt;code&gt;initial&lt;/code&gt; for all other styles. Unfortunately, &lt;code&gt;unset&lt;/code&gt; was not widely supported at the time of writing.&lt;/li&gt;

&lt;li&gt;We will see more relationships between our rules as we begin to use CSS flexbox.&lt;/li&gt;

&lt;li&gt;Disclaimer: the CSS for this site is very old.&lt;/li&gt;
&lt;/ol&gt;
        
        </description>
      </item>

    

      

      

      <item>
        <title>Hybrid Creatives</title>
        <link>
        http://oliverjash.me/2014/03/13/hybrid-creatives.html
      </link>
        <pubDate>Thu, 13 Mar 2014 00:00:00 +0100</pubDate>
        <guid>
        http://oliverjash.me/2014/03/13/hybrid-creatives.html
      </guid>
        <description>
        
          &lt;p&gt;A common attitude I’ve noticed amongst “people who code” is that the code is “just a means to an end.” I can sympathise with this attitude. Personally, I am far more interested in great products than I am in code.&lt;/p&gt;

&lt;p&gt;With this attitude, I think one is perceiving them-self to be less of a programmer and more of a designer. “If I take the shortest path to getting the job done, I can free up more time to think of the bigger picture!”&lt;/p&gt;

&lt;p&gt;Whoever has to maintain your code next could well share your philosophy. Unfortunately for them, however, their job is going to take longer because your code is not easy to maintain.&lt;/p&gt;

&lt;p&gt;If you’re touching a codebase, you should be fully committed to sustaining that codebase’s maintainability. Positioning yourself above programmers — because, for you, the code is “just a means to an end” — is not too different from shooting yourself in the foot. By jeopardising the codebase, you’re making the job harder for the next programmer (and that could be you).&lt;/p&gt;

&lt;p&gt;Whether you’re a designer, a niche programmer, or anything else, I believe you should always give your best effort when engineering. Soon you will turn over faster and cleaner software in less time, &lt;em&gt;and&lt;/em&gt; you will free up more time to think of the bigger picture. By giving our most, we can meld great programming with great design. We can be great creatives.&lt;/p&gt;

&lt;p&gt;These thoughts are provoked by my attempts to steer away from becoming someone who is just a code monkey, and towards someone who makes great products through the marriage of design and development.&lt;/p&gt;
        
        </description>
      </item>

    

      

      
        
      

      <item>
        <title>IMG_4953</title>
        <link>
        http://www.flickr.com/photos/oliverjash/8542032681/
      </link>
        <pubDate>Sat, 09 Mar 2013 00:00:00 +0100</pubDate>
        <guid>
        http://www.flickr.com/photos/oliverjash/8542032681/
      </guid>
        <description>
        
          
          &lt;a href=&quot;
        http://www.flickr.com/photos/oliverjash/8542032681/
      &quot;&gt;
            &lt;img class=&quot;post-image&quot; src=&quot;http://farm9.staticflickr.com/8522/8542032681_2e26fe94bd_h.jpg&quot; alt=&quot;&quot;&gt;
          &lt;/a&gt;
        
        
        </description>
      </item>

    

      

      

      <item>
        <title>There Is No Path</title>
        <link>
        http://oliverjash.me/2013/03/07/there-is-no-path.html
      </link>
        <pubDate>Thu, 07 Mar 2013 00:00:00 +0100</pubDate>
        <guid>
        http://oliverjash.me/2013/03/07/there-is-no-path.html
      </guid>
        <description>
        
          &lt;p&gt;When I think about the skills I have acquired to date, I realise that they all came about unexpectedly, without making conscious learning decisions.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve learnt everything by mistake. I know they say, “you learn with mistakes,” but quite literally, everything in web development that I&amp;#8217;ve learnt to date has been by mistake.&lt;/p&gt;

&lt;p&gt;Humans like to think that we have control. Choose your path. If you do x then you&amp;#8217;ll end up at y. But my career so far in web development has taught me that you can&amp;#8217;t have control. In this world, curiosity replaces control. Fulfil it, and you&amp;#8217;ll end up somewhere you never expected, but it will inevitably be in the right direction, because that&amp;#8217;s the essence of curiosity.&lt;/p&gt;

&lt;p&gt;I wanted to learn how to make awesome web apps. Many Google searches, Stack Overflow issues, IRC pester sessions, and iterations later, and wow, much to my surprise, I know how to: build and design a REST API in Node.js, write scalable and maintainable CSS at over 10,000 LOC, build Backbone.js applications, and &lt;em&gt;so&lt;/em&gt; much more.&lt;/p&gt;

&lt;p&gt;I killed my curiosity, and I &lt;em&gt;accidentally&lt;/em&gt; learnt a set of new technologies and tools. Instead of worrying about learning the right things… do.&lt;/p&gt;

&lt;p&gt;(This is a lesson for myself as much as it is for anyone else.)&lt;/p&gt;
        
        </description>
      </item>

    

      

      
        
      

      <item>
        <title>IMG_2386</title>
        <link>
        http://www.flickr.com/photos/oliverjash/8359028693/
      </link>
        <pubDate>Tue, 08 Jan 2013 00:00:00 +0100</pubDate>
        <guid>
        http://www.flickr.com/photos/oliverjash/8359028693/
      </guid>
        <description>
        
          
          &lt;a href=&quot;
        http://www.flickr.com/photos/oliverjash/8359028693/
      &quot;&gt;
            &lt;img class=&quot;post-image&quot; src=&quot;http://farm9.staticflickr.com/8217/8359028693_d5ff7a72d0_h.jpg&quot; alt=&quot;&quot;&gt;
          &lt;/a&gt;
        
        
        </description>
      </item>

    

      

      

      <item>
        <title>2012 in Review</title>
        <link>
        http://oliverjash.me/2013/01/04/2012-in-review.html
      </link>
        <pubDate>Fri, 04 Jan 2013 00:00:00 +0100</pubDate>
        <guid>
        http://oliverjash.me/2013/01/04/2012-in-review.html
      </guid>
        <description>
        
          &lt;p&gt;Looking back on 2012, I:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;built my first computer (with thanks to Mike);&lt;/li&gt;

&lt;li&gt;got an acoustic guitar, and learned how to make it talk (sort of; with thanks to Mike, again);&lt;/li&gt;

&lt;li&gt;worked in my first proper role as a web developer at Clock&lt;/li&gt;

&lt;li&gt;… during which I worked on two of my biggest projects, which involved conquering OOCSS and, finally, Backbone;&lt;/li&gt;

&lt;li&gt;travelled to Paris, Berlin, the Lake District, and many UK towns and cities – some I forget, and the others are too many to list;&lt;/li&gt;

&lt;li&gt;got my first personal website online;&lt;/li&gt;

&lt;li&gt;got fairly comfortable with Vim, and much more comfortable with the command line, shell scripting, Git, etc.;&lt;/li&gt;

&lt;li&gt;dauntingly, yet contentedly, continued to realise how much I actually do not know (and maybe never will);&lt;/li&gt;

&lt;li&gt;sadly lost my best friend – our Irish Setter, Claudia (aged 12);&lt;/li&gt;

&lt;li&gt;met and acquainted with Paddy, our new rescued Irish Setter, and also now my father&amp;#8217;s best friend.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My New Year’s resolution will be to discover, try, and like at least four things I never thought I would try. (Music, outdoor activities… whatever!)&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;em&gt;In memory of Claudia.&lt;/em&gt;&lt;/p&gt;
&lt;img alt=&#39;Claudia&#39; class=&#39;post-image&#39; src=&#39;http://farm9.staticflickr.com/8064/8264037455_44d251d53a_k.jpg&#39; /&gt;
        
        </description>
      </item>

    

      

      
        
      

      <item>
        <title>IMG_4751</title>
        <link>
        http://www.flickr.com/photos/oliverjash/8261594123
      </link>
        <pubDate>Mon, 10 Dec 2012 00:00:00 +0100</pubDate>
        <guid>
        http://www.flickr.com/photos/oliverjash/8261594123
      </guid>
        <description>
        
          
          &lt;a href=&quot;
        http://www.flickr.com/photos/oliverjash/8261594123
      &quot;&gt;
            &lt;img class=&quot;post-image&quot; src=&quot;http://farm9.staticflickr.com/8204/8261594123_a27a5e12c8_k.jpg&quot; alt=&quot;&quot;&gt;
          &lt;/a&gt;
        
        
        </description>
      </item>

    

      

      

      <item>
        <title>CSS Exceptions&amp;#58; Object Modifiers or Extensions?</title>
        <link>
        http://oliverjash.me/2012/11/23/css-exceptions-object-modifiers-or-extensions.html
      </link>
        <pubDate>Fri, 23 Nov 2012 00:00:00 +0100</pubDate>
        <guid>
        http://oliverjash.me/2012/11/23/css-exceptions-object-modifiers-or-extensions.html
      </guid>
        <description>
        
          &lt;p&gt;Harry Roberts recently published his thoughts on &lt;a href=&#39;http://csswizardry.com/2012/11/code-smells-in-css/&#39;&gt;code that smells&lt;/a&gt;. In this article, Harry included a section on &lt;em&gt;undoing styles&lt;/em&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Any CSS that unsets styles (apart from in a reset) should start ringing alarm bells right away. The very nature of CSS is that things will, well, cascade and inherit from things defined previously. Rulesets should only ever inherit and add to previous ones, never undo.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This made me think about my own practices for undoing styles. In this article, I will look at methods for coding CSS exceptions with undoing styles, and then without undoing styles, to see what is the better method with regards to OOCSS.&lt;/p&gt;

&lt;h2 id=&#39;introduction&#39;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;Imagine we have a &lt;code&gt;widget&lt;/code&gt; object. Our &lt;code&gt;widget&lt;/code&gt; has a border, some padding, and some font sizing:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/* Object */
.widget {
  border: 1px solid #ccc;
  padding: 0.5em;
  font-size: 12px;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Let’s just say that &lt;code&gt;widget&lt;/code&gt; object is used &lt;strong&gt;four times&lt;/strong&gt; on the page. Our design also has another kind of widget, which has all the same properties as &lt;code&gt;widget&lt;/code&gt;, but no padding or border. This widget, however, only appears &lt;strong&gt;one time&lt;/strong&gt; on the page.&lt;/p&gt;

&lt;h2 id=&#39;using_object_modifiers&#39;&gt;Using Object Modifiers&lt;/h2&gt;

&lt;p&gt;What we could do is add an &lt;em&gt;object modifier&lt;/em&gt; for the exception (that, remember, only appears once on the page). Let’s call ours &lt;code&gt;widget-secondary&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/* Object */
.widget {
  border: 1px solid #ccc;
  padding: 0.5em;
  font-size: 12px;
}

/* Object modifier (Exception) */
.widget-secondary {
  /* unset */
  border: none;
  /* unset */
  padding: 0;
  font-size: 12px;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Our object, &lt;code&gt;widget&lt;/code&gt;, assumes that all widgets will have a border and padding. Our object modifier, &lt;code&gt;widget-secondary&lt;/code&gt;, just unsets the properties that are not needed for the exception.&lt;/p&gt;

&lt;p&gt;This method requires the developer to analyse the design and decide on &lt;em&gt;defaults&lt;/em&gt;. For instance, here we recognised that 4/5 widgets had a padding and border, so the &lt;code&gt;widget&lt;/code&gt; object inherited those styles, whereas &lt;code&gt;widget-secondary&lt;/code&gt; opts-out of those styles to create the exceptions.&lt;/p&gt;

&lt;p&gt;By creating a modifier for the exception, we only have to concatenate additional classes in our HTML for the exceptions:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;div class=&amp;quot;widget&amp;quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;div class=&amp;quot;widget&amp;quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;div class=&amp;quot;widget&amp;quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;div class=&amp;quot;widget&amp;quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;!-- Exception --&amp;gt;
&amp;lt;div class=&amp;quot;widget widget-secondary&amp;quot;&amp;gt;…&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#39;using_object_extensions&#39;&gt;Using Object Extensions&lt;/h2&gt;

&lt;p&gt;Going back to Harry’s argument that CSS which unsets properties is smelly code, Harry instead argues that ‘rulesets should only ever inherit and add to previous ones, never undo’. To adhere to this principle, we must replace our object modifier with an &lt;em&gt;object extension&lt;/em&gt;. In this example, we will call it &lt;code&gt;widget-primary&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;/* Object (Exception) */
.widget {
  font-size: 12px;
}

/* Object extension */
.widget-primary {
  border: 1px solid #ccc;
  padding: 0.5em;
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here we are not undoing any styles, so our CSS is shorter. Maintenance is easier because we don’t have to remember that any styles we add to &lt;code&gt;widget&lt;/code&gt; also need to be undone by a modifier. But because we now have to opt-in for even the most common styles (border and padding), we have more classes in our HTML:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;div class=&amp;quot;widget widget-primary&amp;quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;div class=&amp;quot;widget widget-primary&amp;quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;div class=&amp;quot;widget widget-primary&amp;quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;div class=&amp;quot;widget widget-primary&amp;quot;&amp;gt;…&amp;lt;/div&amp;gt;
&amp;lt;!-- Exception --&amp;gt;
&amp;lt;div class=&amp;quot;widget&amp;quot;&amp;gt;…&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id=&#39;conclusion&#39;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;In conclusion, it seems that by analysing the design to decide on defaults, and undoing styles for any exceptions that occur thereafter, our CSS becomes more complex. We have to remember that any styles added to an object might also have to be maintained (modified or undone) in any object modifiers. This can be overcome by replacing object modifiers with object extensions, but then we have to concatenate additional classes in our HTML.&lt;/p&gt;

&lt;p&gt;In the past, I have always used object modifiers (undoing styles) myself in an attempt to refrain from adding more classes in my markup. However, this appears to be &lt;a href=&#39;/2012/09/07/methods-for-modifying-objects-in-oocss.html&#39;&gt;just another reason why you should defer work to your HTML&lt;/a&gt; in order to keep your CSS tidy and maintainable. In the future I will be using object extensions instead. If you’re still uncomfortable littering your HTML with classes, then have a look at &lt;a href=&#39;https://gist.github.com/4136435&#39;&gt;this case study by Harry Roberts&lt;/a&gt; which demonstrates how small of a difference it makes to file sizes.&lt;/p&gt;
        
        </description>
      </item>

    

      

      
        
      

      <item>
        <title>IMG_0798</title>
        <link>
        http://www.flickr.com/photos/oliverjash/8131333624
      </link>
        <pubDate>Sun, 28 Oct 2012 00:00:00 +0200</pubDate>
        <guid>
        http://www.flickr.com/photos/oliverjash/8131333624
      </guid>
        <description>
        
          
          &lt;a href=&quot;
        http://www.flickr.com/photos/oliverjash/8131333624
      &quot;&gt;
            &lt;img class=&quot;post-image&quot; src=&quot;http://farm9.staticflickr.com/8056/8131333624_587425269f_b.jpg&quot; alt=&quot;&quot;&gt;
          &lt;/a&gt;
        
        
        </description>
      </item>

    

      

      
        
      

      <item>
        <title>Summit Awesome – Leeds</title>
        <link>
        http://www.flickr.com/photos/oliverjash/8036578489
      </link>
        <pubDate>Tue, 23 Oct 2012 00:00:00 +0200</pubDate>
        <guid>
        http://www.flickr.com/photos/oliverjash/8036578489
      </guid>
        <description>
        
          
          &lt;a href=&quot;
        http://www.flickr.com/photos/oliverjash/8036578489
      &quot;&gt;
            &lt;img class=&quot;post-image&quot; src=&quot;http://farm9.staticflickr.com/8453/8036578489_24f1d26530_b.jpg&quot; alt=&quot;&quot;&gt;
          &lt;/a&gt;
        
        
        </description>
      </item>

    
  </channel>

</rss>