Jiaaro

…on life, the universe, and everything

Maintainable CSS (or CSS the good parts)

CSS is kind of terrible. Everything affects everything. It’s impossible to refactor. Code is spaghetti from day one. And selectors are used to identify elements in scripts as well as applying styles, not to mention the semantic meaning of html tags themselves.

So. Some proposals…

Element ID

Don’t use ID. Don’t use getElementByID(). Don’t use element IDs in your CSS selectors. Just don’t. ID has no benefit over classes for use in CSS or JavaScript.

There is virtually no case where you can be 100% certain that a style will only ever need to be used on one element in the whole page. Even if you were certain, a class would work just as well!

There is only one acceptable use for id: to enable deep-links to specific elements (with the scroll behavior that entails).

Tag selectors

Don’t use tag selectors in javascript. In CSS only use them to provide the most basic reset and baseline styles. Never mix tag selectors with class selectors.

One class selectors

No nesting. If you need more behaviors on an element, add another class. If you need only some of the behaviors of a parent class and you want to override others, your parent class is probably doing too much. Try giving it less responsibility, or if you really can’t – no way, no how – just define a new class.

Really consider giving the parent class less responsibilities though. If you have to think about the order of the rules in a style block, there are probably too many.

Good:

.my-class {  }

Not great (but sometimes necessary):

.my-container .my-class {  }

Bad (just create a third class):

.my-class.other-class {  }

Very Bad (fully engaged in the precedence war):

.container .sub-element a.special-link.active {  }

Use Naming conventions

You should be able to tell roughly what a class is for (and you’re only using classes right?) by the name. Establish – at a minimum – a convention for classes that control layout, text styles, and javascript hooks.

JavaScript should not use the same classes as css.

That would be mixing presentation with logic.

Use rem (root em) units

em units are kind of crap because if they are nested they compound. Still, it’s great to set the font-size on the body and have everything work from there. And, rems are well supported (IE 9+).

Use lots of CSS files

You should have one main css file which uses @import to bring in everything else it needs. Break up your css so that each logical unit is in it’s own file. Got a custom dropdown widget? super-dropdown.css. What about persistent navigation at the top of each page? header-navbar.css. Login form? login-form.css.

If you have less than 5 CSS files you’re probably doing it wrong. If you have exactly one CSS file you almost definitely are.

ok, ok, ok. I know what you’re thinking: “James, I’ve been doing lots of these ‘wrong’ things and it’s been working fine for me.”

You see, it seems that way at first. IDs, specific selectors, using a class for styles and javascript. These things seem useful and “clean”. Why use two classes when one will do? Because you will not be able to refactor your code. That’s why. And if you let it go on long enough you won’t even be able to change your code without a full round of manual testing.

Most CSS code being written today is technical debt from the moment it’s created. And it’s the worst kind of technical debt: the kind you don’t know you have.

A Path to Fluency

Learning a language is a Good Idea. It makes you smarter, more creative, and empathetic, and more likely to recover from a stroke. Thinking it’s good idea doesn’t make it easy. The payoff is too far off, too abstract.

Recently though, I’ve been making some headway after giving up lots of times in the past. Some observations:

Learning a language because it’ll be “useful” probably won’t work out.
If you haven’t encountered any Chinese in the last 20 years, odds are you won’t in the next 20 years either. Any language is worth knowing, but, like exercise, most people run out of motivation before reaching their goals.

My advice? Pick one you have a personal reason for. I have Spanish-speaking family (including my wife), Mexico is right next door, and there’s Spanish language TV here in New York.

Duolingo is amazing.
If you’re not using Duolingo, you’re missing out.

Entertainment: You can trick yourself into learning.
Spanish tech news on twitter and RSS make it easier to practice every day without it feeling like work. I also picked up some translated graphic novels. Comics, graphic novels, and manga make it much easier to get the gist of the story without struggling too much. There are also “side-by-side” readers which have the same text in two langauges – English on the left, Spanish on the right.

Be careful of things that are too difficult for you. Feeling like you’re in over your head makes it hard to stay focused and it’s demoralizing.

TV and Movies are a siren song.
At least early on; I’m still not able to keep up. They seem like a great way to practice, but the pace is too fast and there are a lot of idioms.

Traditional methods don’t work (for me).
Stuff like Rosetta Stone, “Learn Spanish” books, podcasts, etc bore me to death. Motivation is as important as the information and exercises. You definitely won’t learn the language if you quit. And “I’ll know Spanish if I do this hard-ass work,” is not enough on it’s own.

Honestly, I don’t know how anyone learns language that way. ¯_(ツ)_/¯

Visiting Mexico was a huge motivator.
Really. Nothing makes me want grind through Spanish lessons like being surrounded by native speakers.

You can fly to Cancun for just over $150 each way on Jet Blue:

JFK to CUN for $315

…and rent a lovely place in Puerto Morelos for $220/mo (4000 pesos):

Puerto Morelos Apartment for $220/mo

note: I haven’t done that, I just took that photo of the apartment listing when I was in Cancun a few years ago.

That’s all I’ve got for now. Wish me luck!

Blocking Content Blocking

I can’t help but chuckle about all the hand-wringing over content blockers in iOS 9. Ad blockers have existed for some time. Not many people use them (as a percentage of overall web users). Plus, native advertising is mostly immune to content blocking anyway, and that’s where a lot (most?) of the money was going to end up anyway.

That’s old news. My favorite part is: it’s really not that hard to make nearly unblockable ads. If the publishers and ad networks worked together they could mostly nullify the effects of ad blockers in lots of ways.

  1. They could insert the ads server-side in a way indistinguishable from content. Then load the ad network’s javascript purely to mark the ads as “sponsored content” and handle tracking. This would make it so that people using ad-blockers would have more trouble telling where the ads are, but everyone would see the ads.

  2. Ad networks could build CDN-like infrastructure and insert their ads in pre-specified parts of the page (like how Vagrant builds pages). This approach lets everything come down from one domain but takes care of publisher accountability (publishers can’t screw the ad network).

    Alternatively, an actual CDN (like CloudFront) could provide hooks for publishers and Ad networks (again, like Vagrant) to insert ads into pages within the same domain, and do impression/click tracking on the same domain as well. This variant solves some of the incentive issues (publishers don’t have to trust the ad networks either) by moving trust on a third-party (the CDN). I prefer this variant in terms of incentives, but it requires more coordination, so it might be harder for a CDN to succeed in the marketplace with this approach.

  3. Ads can be sold on an average-traffic or pay-per-click basis (i.e. the Deck), but without any 3rd party javascript. The markup inserted by publishers is just a clickable hot linked image, and the ad is rotated by just changing the image served at that url, and changing the destination of the link’s redirect. Publishers would just have to insert a unix timestamp in the querystring of the image and link to invalidate caches, deal with fast ad rotations, and all sorts of other issues. This method is relatively blockable, but easily pairs with a CDN-like approach.

    What I like about this is the simplicity, and the fact that it represents a line in the sand. You can easily say, ads served as third-party images are OK, but not ads served as 3rd party javascript or 3rd party iframes.

Anyway, there are lots of details around all these approaches that would have to be worked out. And plenty of pros and cons of each one as well (for all parties involved, consumers, advertisers, publishers, and ad networks. And CDNs should they choose to get in the middle of all this.)

The Shortest Apple Watch Review

If you’re into two or more of these (or really into one), you should check out the Apple Watch:

  1. Personal fitness
  2. Watches
  3. Apple products

That’s it. Review complete.

It’s an interesting product - I still need time to form a more nuanced opinion.

One thing I will say though: the Sport is nice. It’s as nice and well built as the iPhone 6.

Don’t feel like you need to buy the Steel version unless the look and feel of the steel itself is what you’re interested in. Especially if fitness tracking is an attractor for you; the Ion-X glass on the Sport is more resilient to impact than the Sapphire screen of the Steel and Gold versions (the glass scratches more easily, but who cares about scratches if you shatter the sapphire screen playing sports).

Social Skills Education

In my post, “Why we got 140 characters instead of flying cars,” I made a throwaway comment about how enterprising individuals should focus on communication skills instead of delivery. My podcast cohost Mik, was disappointed that I was writing about economics and not communication. So today I’ll talk about the economics of education instead =P

I’ll cut to the chase. Teaching communication skills is not a very good idea for a startup.

This isn’t news. I said it in the last post too. Communication skills are valuable, but capturing that value is difficult. Education startups aren’t debuting to multi-billion dollar IPOs. Not Learn-to-code startups. Not Learn-to-write startups. Not learn-a-new-language startups. Not even learn-to-make-friends or learn-to-influence-people startups.

People just don’t value education in that way. Universities have managed to jack up the price, but even they focus on prestige, job prospects, facilities, and connections.

Conspicuously absent: the stuff you will know when you graduate.

In fact, those parts seem to be losing prominence as a larger trend in education. The focus is on opportunity, not knowledge.

And selling knowledge is getting harder. The Internet is socializing us to believe information should be free.

So… where does that leave you, the social entrepreneur?

Delivering communications – no matter how inane the content – at least has a business model: insert extra communications (ads) into your pipe in exchange for cash.

I hate that business model, but c’est la vie.

Some education startups have innovated in the business model department. Duolingo teaches you a language, and when their students become advanced they translate documents for practice. They sell translation services.

At first blush, you’d expect a high-value skill like computer programming to be something where you can sell education for a high price. If a professional programmer can earn $100k/year for the next 10 years – that’s a million bucks! – surely you can charge $5k to teach someone that skill. After all, that’s only half a percent of the earnings.

But that math only works if you assume that you’ll only want/need to learn one career skill. That you’ll like the first one you learn. That the skills will remain valuable for a long time. That’s not how people work.

If you’ve never tried computer programming, you really have no idea what it’s like to be a programmer (take it from me). Would you simultaneously choose a career you know nothing about AND hand over $5k to someone whose expertise you are completely unable to evaluate? I wouldn’t. Even without the risk of some asshole running off with my five grand.

Could a learn-to-communicate startup work (be profitable)? Maybe. First they’d have to settle on an approach. Will they teach people to write? to speak? to unravel the mind of their audience?

So far these sound like classical academic topics – literature, theater, psychology – and not exactly a bunch that are associated with high-paying careers either.

Much like technology, these things can be tremendously valuable when used in conjunction with another skill. It almost doesn’t matter what that other skill is. But that makes the value proposition even harder than the computer programmer one. “Want to learn a skill which will make you marginally more successful in whatever other career path you choose? I’ll teach you, that’ll be five grand.”

Now add the fact that people generally don’t think of themselves as poor communicators, and generally underestimate the benefits of good communication skills. How are you going to sell that?

Back to the drawing board. Each education startup will have to find a purpose-made way to capture value (a la duolingo).

And if they can’t? Screw it. Slap an ad on top and IPO.