Apple Is Using Sass, And They’re Doing It Wrong (blog.kaelig.fr)

71 points by kaelig ↗ HN
Today Apple redesigned the homepage of the online Apple Store. I was having a look at their code and I found out some interesting code smells that apparently even the most skilled developers will commit.

54 comments

[ 4.7 ms ] story [ 124 ms ] thread
Today Apple redesigned the homepage of the online Apple Store. I was having a look at their code and I found out some interesting code smells that apparently even the most skilled developers will commit.

If one of their developers is reading this I am happy to help with Sass architecture and best practices.

>I was having a look at their code and I found out some interesting code smells that apparently even the most skilled developers will commit.

Your use case is not Apple's use case.

They're not designing Flickr, some blogging service or some news site.

The smells are there for a reason. The pages and styles are not to be reusable -- they are meant to be easily replaceable on a per page / section basis.

> The smells are there for a reason.

What reason is there for CSS that is commented out? Or for redundant prefixes? Or for debug to be left on and to have a bunch of comments and paths from the build structure?

>>> Or for debug to be left on and to have a bunch of comments and paths from the build structure?

So you can debug problems being seen only in the production version?

Let's hope Apple's not that lazy.
Then they may want to use Sourcemaps in Sass 3.3 alpha. But production assets should be minified for better performance.
>But production assets should be minified for better performance.

Only if you have measured both, and found that minifying makes a difference on the scale you care about. Which might very well NOT be the case with Apple's site.

They have tons of images, a lot of them very high quality and size (even retina). So a difference of a few K in the CSS would not even register in the assets transfer time. E.g you should now sweat 10K vs 20K CSS, when you have 2MB of images to serve in the same page.

Oh, and it would only matter if they are not transferring assets as gzip in the first place -- in which case minifying is mostly redundant.

What redundant prefixes? The article asks if they're really targeting users on iOS 3.2. And I would have to assume the answer is yes, of course they are. For a tiny amount of extra CSS they allow people using old devices and browsers to still give them money. It's a no brainer that they would leave the prefixes in!
Next time some person says that CSS is good enough and SASS/SCSS is unnecessary. Yeah this.
Each have their place, and if you can't write good good CSS then your SASS is going to be just as rubbish.
What's good CSS, apart from minimizing performance impact by keeping to some rules?
What's good code apart from minimizing performance impact by keeping to some rules?
I think a lot of this is more that apple doesn't give a damn about reuseability, they care about perfection. If the promo after father's day has an image that goes over the border by 3px, they'll write it from scratch.
They care about perfection on the surface as well as below the surface. This release doesn't meet both these criteria.
I don't think it's actually true that Apple cares about "perfection below the surface".
especially where the surface is invisible. its all about the shiny.
It might not be perfect, because what ever is? But the interior of the Macbook Pro, Mac Pro, and other hardware suggests otherwise:

http://www.ifixit.com/Teardown/MacBook+Pro+15-Inch+Retina+Di...

Similarly, the filesystem on OS X. As far at the Mac parts go, while the BSD folders have visibility toggled off.

Oh give me a break, Apple products are nowhere near perfection. They do plenty right, but plenty of their stuff is awful (just like every other company out there). Finder is awful. The calendar and notes app are awful. One of the ugliest things about Apple is the constant insistence by users that everything Apple does is perfection.
I didn't say they're perfect or anywhere near perfection. I could go on at length about the myriad things that annoy me: Finder, HFS, software update crammed in the App Store, iOS lockdown.

All I did say is that they absolutely do _care_ about what's below the surface. Parts that a fraction of a fraction of folks will ever see are given loving attention far beyond the norm. Do most or any other manufacturers color coordinate battery warning labels, PCBs, etc., down to the cm^2 headphone jack?

But … it took 5+ years not to freeze the UI if the network dropped a packet and lookupd ran out of threads. This was much worse if you used a network authentication service like LDAP – I submitted the same libldap client patches which I sent upstream to the OSS devs (http://chris.improbable.org/2008/03/15/borrowing-from-the-fu...) – but this and NFS client kernel deadlocks and other problems (they accidentally broke Unix permissions for a few releases in the 10.4 days) were generally either ignored or answered with something like “How many Macs does this problem prevent you from buying?” (NOT a joke).

iOS's WiFi still hasn't fixed the basic usability bugs I reported against 1.0 (simple things like “Don't capture the UI until the hotspot page has actually loaded” or “Don't nag me asking to reconnect to a marginal network I already requested you connect to”).

iOS autocomplete remains an embarrassment, frequently turning correct words into nonsense or failing to handle minor inconsistencies in input which didn't produce a valid word.

iOS backups don't backup the stuff you care about like passwords or settings but do backup things you can trivially re-download from the store like apps. This is not in any way documented and the backup status will simply claim the backup was successful without mentioning that it includes almost nothing important.

FileVault had data-loss bugs for multiple releases until v2 was released. Time Machine still doesn't check data integrity and the remaining users complain about weird UI bugs, performance impact, hangs & data loss, etc. Nobody at Apple appears to care.

iCloud sync is a disaster with uncontrollable delays and hangs (e.g. http://createlivelove.com/246). There's no sign of anyone at Apple caring since it hasn't impacted iPhone/iPad sales.

To reiterate: Apple doesn't obsess about quality unless it's needed to get people to buy the device.

>That’s 7 levels deep (sic.). On top of being quite inefficient and generating a large amount of code, these styles are completely un-reuseable.

That's kind of the whole idea.

It's supposed to help to not mess other parts of the page when they change something.

Their page design is not supposed to be overall consistent and re-usable. They are supposed to be able to do long or surgical changes to any individual section at whim, without affecting anything else -- having sections with a unique new look weeks before updating anything else, or creating special purpose looks for different sections.

For this purposes, reusability and less nesting would be a nightmare.

I know Apple has to deal with a lot of legacy code and wants to avoid conflicts. Their architecture is very good but I believe it could still be better (at least they stopped using IDs in their CSS).

Nesting (especially this deep) is usually a bad idea. Have you heard of BEM? This methodology helps building reusable modules without polluting the global scope.

It’s not only about legacy code. Apple’s website layout (especially on all the important product pages, certainly also some overview pages in the store) is all highly custom, much more like a magazine than a website. That’s on purpose. That stuff is supposed to look different. Making the stuff reusable wouldn’t even make sense. (Though I do not want to claim that what Apple is doing here is a good way to go about things.)
Even if you don't care about reuse, wouldn't it make more sense to just do a selector like ".my-completely-and-totally-unique-class-name" instead of nesting so many levels deep?
Not always. That could just add clutter to the html. Or they might not have permission to edit the html (because it's mostly generated by other tools, and they might be in a weird setup where design doesn't touch the html, look, I don't know, it's Apple...)
If you want to see how that turns out, check out ExtJs thousand line sass files. Nesting or namespacing is DRY 101 in my book and I prefer my projects with this as well.
Agreed. I'd love to actually hear about how people go about architecting styles that aren't meant to be re-usable in their projects. Landing page are always a good example of this, which Apple's site is full of.

Of course the simple explanation can be: write everything, everywhere. But I'd love to hear some expert insights from people who have to think about not breaking these things all day.

(comment deleted)
Forgetting about reuse, if you change any of the 6 levels before it, then the inner-most element breaks. This is brittle because of the extreme specificity. Thus, you can't make surgical changes easily for fear of breaking child elements.
We've started experimenting with Sass for Wikipedia as well, and it's now in MediaWiki core. Check out mediawiki.ui in the core resources (git.wikimedia.org).

Right now we're only using it for our upcoming signup/login redesign, but it's available for use elsewhere and will probably start popping up on other interaces. We debated whether to even include the Sass files and associated errata at all though, to be honest.

Thank you for sharing, I am glad that more and more organizations are using such powerful tools.

Also: it's Sass, not SASS.

Everyone is doing something wrong.

I'm starting to wonder about using checklists for deployment (yes, your deployment should be automated. You still have to go through the checklist at least once). There are lots of them out there, but they seem pretty pretty general, mostly. There are also a lot that are internal to a given company, used for a specific application.

It seems like there should be an intermediate level, though. Just like any OSS project is expected to have a readme and a changelog, it should also have a CHECKLIST.txt. Drop it into your checklists directory (or have a script that collects them for you) when you add a library to your project, and go through them all before releasing.

What is wrong is that I can't zoom on your website. Typos won't scale.

It's really a big accessibility problem. I can't read this article without using the Chrome inspector to change styles.

And I'm far from being visually Impaired.

Sorry, but it must be said.

Zooms just fine in Firefox. Seems like a Chrome issue to me, afaik no site should be able to override zoom.
Thanks very much for this feedback. I removed this limitation and you can now zoom in. I am very sorry, as this is something I've been willing to fix for a long time.
> this is something I've been willing to fix for a long time

I'm guessing English isn't your native language, so this is a diction note:

You should say "I've been wanting to fix". "willing" is strictly correct, but it conveys that you've been waiting for someone to ask you to fix it. "wanting" conveys that you knew about the problem but hadn't found the time to deal with it.

Hope that helps.

Nitpick: your explanation works for the far more common term "willing", an adjective. But, through it may sound awkward and very few people would use it this way, could it not also be the participle of "to will"? In this interpretation the use of "willing" is totally correct.

(Also, before saying that I've written this out of some foreign notion of English and that I just wouldn't understand, my own native language is English.)

It's technically correct, but it sounds weird and non-native to me. It requires me to jump through mental hoops to explain how it makes sense. For easy communication, I'd recommend sticking with "wanting" in this situation.

(though I'm not averse to using awkward phrasings or the like in casual situations where clear communication isn't the number one priority. At the moment I'm on a crusade to bring back "thrice" and {h,th,wh}{ence,ither}. )

Thanks! I actually moved to the UK exactly one year ago to improve my speaking/writing English skills, and every suggestion helps. I hesitated when writing this comment and went for "willing" because it sounded good (not a very good way to choose what word to use…).
I don't think Apple is doing anything right on their website. I've recently come across parts of it built in 2006 on perl scripts, running hand in hand with the AppleID code running today. The backend must be horrifying.
(comment deleted)
This article would be improved tremendously if you told me what Sass was.
You're right, since the audience reading the blog is usually a crowd of developers I did not think I should mention it. Sass is a CSS preprocessor, used for better stylesheet authoring. You may find more information here: http://sass-lang.com/

I also added a link to the Sass website in the first part of the post.

This is off topic, but in the recent months there has been an influx of these informative blog posts with animated gifs that are not really relevant to the information. Is this just a side effect of being a Tumblr user/community member? The more snarky pictures, the higher your view count/loyalty?

I ask, because they are distracting and shred any seriousness laid out in the article. Some of these articles are rich in content, but reading them at work with flashing/animated nonsense feels like I am viewing Reddit to people passing by.

I hate to say it, but I agree completely. Forgive me for wanting engineering articles to look like... engineering. I wonder if this is just a generational thing. I don't have a bucket full of GIFs to drop on an article.

It seems to be tapering off lately, but it used to irk me greatly when a technical blog article would have a bunch of random photos stitched in that had absolutely nothing to do with the content.

Is this any surprise from the team that takes the store offline to add products?
That's more marketing and hype than technical limitation.
There actually used to be a technical reason for it. Updating the servers all over the World required a propagation delay. Nowadays I don't know.
> Your code is so much better than most Fortune 500 companies, which is why hundreds of developers (perhaps more) are viewing the source of Apple.com ...

Let's hope these hundreds of devs don't look too closely. Referencing 11+ seperate JS files in <head>, among them unminified libraries, isn't exactly best practice. They violated all the rules:

1) Combine! 1 CSS + 1 JS are usually enough.

2) Move JS to the bottom if possible!

3) Minify!

(I'm talking about www.apple.com, not the store.)

Things that Apple's customers care about include: Whether the website reliably displays on their device. Whether or not they can successfully browse and buy Apple's latest products. How fast the site loads.

Things that Apple's customers don't care about at all include: The code. Or whether or not that code "smells".

This would be an interesting story if it spoke in terms of something important. "Here is how Apple could probably boost sales by 0.1% by optimizing their SaSS" would be a good story. "Here is how to make the Apple Store load 25% faster by optimizing its SaSS" would be a good story.

But "here is how Apple could make their SaSS more aesthetically satisfying to the 0% of visitors who will pay more to read higher-quality code in the Web Inspector" is, at best, an academic exercise.

Production code exists to solve problems, and its quality is not merely a function of the code itself, but of the time constraints, the budgetary constraints, and the magnitude and urgency of the business opportunities. How many millions of dollars of product did Apple's "bad" SaSS sell in the time it took to critique it?

I agree that code should not be a goal in itself, but you miss the point.

Apple is preaching engineering excellence through their campaigns and products. In the Apple World, the quality of a product is not something you assess only depending on the money it makes.

Seems like everyone wants to make a name for themselves by knocking on others on HN instead of showing their own awesome work.