thingsinjars

  • 29 Jul 2011

    Vendor-prefix questions

    There's something that's always niggled me about vendor-specific prefixes on CSS.

    Vendor prefix background

    Just in case you don't know about vendor prefixes, there's a good summary on A List Apart.

    Best practice dictates that you should always include non-prefixed properties last. This is so that when the property does become standard and the browser implements the non vendor-prefix version, it will use the standard rule as it comes later in the stylesheet than the prefixed one. The thing that has been bugging me is the assumption that the agreed standard version produces the same or better results than the prefixed one.

    A convulted and completely made-up example

    Imagine you have a paragraph:

    <p>Made-up text.</p>

    And you want it to have a white border with rounded corners. I'm fully aware you now don't need the vendor prefixes here but bear with me.

    p {
      border:1px solid white;
      -webkit-border-radius:5px;
      -moz-border-radius:5px;
      -ms-border-radius:5px;
      -o-border-radius:5px;
      border-radius:5px;
    }

    In this scenario, the non-prefixed border-radius hasn't been implemented by any browser but you're following best practice so you include the values matching the current specification. Okay, now imagine that for Webkit's implementation of -webkit-border-radius, they decided that the radius value was actually to be divided by two. No problem, you can include the required value for Webkit. Again, not a real example but stick with me.

    p {
      border:1px solid white;
      -webkit-border-radius:10px;
      -moz-border-radius:5px;
      -ms-border-radius:5px;
      -o-border-radius:5px;
      border-radius:5px;
    }

    You launch the site and send it out into the world.

    Six months later, the standard is set, it turns out developers agree on Webkit's implementation. It becomes standard to double your radius value. A month after that, browsers start recognising the non-prefix version of the rule and rendering with the new standard. At this point, webkit, moz, ms and o are all rendering wrong because they are ignoring their vendor-specific implementation and using the non-prefixed standard. Even though webkit currently has the right value, it's being overwritten. If the rules had been included the other way round, they'd still be rendering the same as they were.

    p {
      border:1px solid white;
      border-radius:5px;
      -webkit-border-radius:10px;
      -moz-border-radius:5px;
      -ms-border-radius:5px;
      -o-border-radius:5px;
    }

    Eventually,support for the prefixed version will be dropped and the browsers will only use the standard but that will be a little way down the line and gives you more time to correct your code or your client's code or wherever the code happens to be. Basically, prefix-last order buys the developer more time to correct any potential issues. I know that by using the vendor-prefixed rules, the developer is implicitly accepting the fact that they are using experimental properties which could change but in this scenario, it is not the prefixed properties that change but the non-prefixed one.

    The reason I chose border-radius here is just because it was easier that typing up an example that might actually happen in real-life involving gradients or masks.

    Open to suggestions

    I'm open to any explanation as to why this scenario might never happen or comments on how I've misunderstood something.

    Geek, CSS

  • 27 Jul 2011

    Feed the RSS

    For no real reason and definitely not to prove once again that RSS isn't dying, I just thought I'd write about a couple of the nice bits about the RSS feeds on this site so that readers could get the maximum amount of awesome per unit of blog.

    There's a handy trick you can do with the feeds if you don't want posts from every category. You can subscribe to an individual category by using the link http://thingsinjars.com/rss/categoryname.

    But that's not all.

    If, for instance, you like the JS and CSS stuff but can't stand the rest, just list the categories you want with a plus and you'll get those feeds combined and nothing else. Like this: http://thingsinjars.com/rss/js+css. Nifty, eh?

    Also, the RSS link changes depending on which category you're in.

    Geek

  • 25 Jul 2011

    Psychopathic megalomaniac vs Obsequious sycophant?

    - or -

    Tabs vs Spaces?

    Which are you? Is there any middle ground?

    In any modern, code-friendly text editor, you can set tab size. This means that one tab can appear to be as wide as a single space character or - more commonly - 2 or 4 spaces. It's even possible in some to set any arbitrary size so there's nothing stopping you setting tabs to be 30 spaces and

    format() {
                                  your code() {
                                                                like;
                                  }
                                  this;
    }

    However you do it, the point is that using tabs allows the reader personal preference.

    Indenting your code using spaces, however, is completely different. A space is always a space. There's actually a simple conversion chart:

    • 1 = One
    • 2 = Two
    • 3 = Three
    • and so on.

    The fundamental difference here is that the person reading the code has no choice about how it's laid out. Tabs means you get to read the code how you want to, spaces means you read the code how I want you to. It's a subtle difference but an important one.

    Space indenting is therefore perfectly suited to psychopathic megalomaniacs who insist their way is right while tab indenting is for obsequious sycophants who are putting the needs of others above themselves. Sure, there may be lots of grades in-between but why let moderation get in the way of a barely coherent point?

    Curiously, neither of these extremes feels a great need to comment their code. One sees no need as their code is for themselves and they already understand it, the other assumes that if they can understand it, its purpose is so obvious as to be trivial. Both are wrong here.

    There's unfortunately no real middle ground here. Teams must agree amongst themselves what side of the fence they fall down on. It is entirely possible to set many text editors to automatically convert tabs to spaces or spaces to tabs on file save but if you're doing that, you'd better hope your favourite diff algorithm ignores white space otherwise version control goes out the window.

    This article is modified from a chapter in a book Andrew and I were writing a couple of years ago about web development practical advice. Seeing as we both got too busy to finish it, I'm publishing bits here and there. If you'd like to see these in book form, let me know.

    Opinion, Development, Geek, Guides

  • 11 Jul 2011

    Torch

    Concept

    Another proof-of-concept game design prototype. This is kind of a puzzle game. Ish. It's mostly a simple maze game but one in which you can't see the walls. You can see the goal all the time but you are limited to only being able to see the immediate area and any items lit up by your torch. You control by touching or clicking near the torch. The character will walk towards as long as you hold down. You can move around and it'll follow.

    Torch v0.1

    The first 10 levels are very easy and take practically no time at all. After that, they get progressively harder for a while before reaching a limit (somewhere around level 50, I think). The levels are procedurally generated from a pre-determined seed so it would be possible to share high scores on progression or time taken without having to code hundreds of individual levels.

    Items that could be found around the maze (but aren't included in this prototype) include:

    • Spare torches which can be dropped in an area and left to cast a light
    • Entrance/exit swap so that you can retrace your steps to complete the level
    • Lightning which displays the entire maze for a few seconds (but removes any dropped torches)
    • Maze flips which flip the maze horizontally or vertically to disorient you.

    I worked on this for a few months (off and on) and found it to be particularly entertaining with background sound effects of dripping water, shuffling feet with every step, distant thunder rumbling. It can be very atmospheric and archaeological at times.

    Half-way through a level, two torches dropped
    Torch, the game

    Slightly technical bit

    The game loop and draw controls are lifted almost line-for-line from this Opera Dev article on building a simple ray-casting engine. I discarded the main focus of the article - building a 3D first-person view - and used the top-down mini map bit on its own. The rays of light emanating from the torch are actually the rays cast by the engine to determine visible surfaces. It's the same trick as used in Wolfenstein 3D but with fewer uniforms. It's all rendered on a canvas using basic drawing functionality.

    The audio is an interesting, complicated and confusing thing. If I were starting again, I'd look at integrating an existing sound manager. In fact, I'd probably use an entire game engine (something like impact.js, most likely) but it was handy to remember how I used to do stuff back in the days when I actually made games for a living. Most of all, I'd recommend not looking too closely at the code and instead focusing on the concept.

    Go, make.

    As with Knot from my previous blog post, I'm not going to do anything with this concept as I'm about to start a big, new job in a big, new country and I wanted to empty out my ‘To do’ folder. The code's so scrappy, I'm not going to put it up on GitHub along with my other stuff, I seriously do recommend taking the concept on its own. If you are really keen on seeing the original code, it's all unminified on the site so you can just grab it from there.

    The usual rules apply, if you make something from it that makes you a huge heap of neverending cash, a credit would be nice and, if you felt generous, you could always buy me a larger TV.

    Torch v0.1

    Ideas, Geek, Development, Toys

  • newer posts
  • older posts

Categories

Toys, Guides, Opinion, Geek, Non-geek, Development, Design, CSS, JS, Open-source Ideas, Cartoons, Photos

Shop

Colourful clothes for colourful kids

I'm currently reading

Projects

  • Awsm Street – Kid's clothing
  • Stickture
  • Explanating
  • Open Source Snacks
  • My life in sans-serif
  • My life in monospace
Simon Madine (thingsinjars)

@thingsinjars.com

Hi, I’m Simon Madine and I make music, write books and code.

I’m the Engineering Lead for komment.

© 2025 Simon Madine