Explore My Notes

Sass and clamp | adactio

Jeremy has been updating The Session to use variable font sizes with the new CSS clamp() property. He offers some interesting ideas on how best to do that:

:root {
    font-size: clamp(1rem, 0.5rem + 0.666vw, 1.5rem);
}

He also notes that in order to do this, he needed to remove Sass from the site. I find that interesting. Sass still appears to be a common prerequisite for frontend jobs, but I've never really understood why new projects would use it. When I returned to the frontend world a couple of years ago, I'd missed the Sass train. By the time I got around to thinking about learning it, I wanted to know what problem it solved. I came to the same conclusion then as Jeremy has done now, which is that all the solutions Sass provides are pretty much native to CSS these days.

Between CSS variables, customer properties, and calc() a lot of the benefit of Sass is now a burden. There are still two big bonuses: multiple files and nesting. I do wish CSS had a native nesting capability, but for the most part when I review Sass code it gives me a headache. DRY is great, but not at the expense of readability, which I fear it often ends up becoming with deep nesting.

As for multiple files, I guess I moved straight into the framework world on return. It's one of the things I love about CSS modules in React, that it lets me colocate my styles with my components from a dev perspective. In many ways, I prefer this to the .scss model.

I still have to work with Sass and imagine that isn't going to change; it's integral to a lot of tech stacks. But it's nice to see that I've potentially skipped needing to embrace it fully.

It feels like something similar has happened with tools like Sass. Sass was the hare. CSS is the tortoise. Sass blazed the trail, but now native CSS can achieve much the same result.

Figure it out | A List Apart

Colour is tricky, as discussed in this chapter of Figure it Out: Getting from Information to Understanding.

  • Western cultures have seven colours in the rainbow (ROYGBIV) because that's what Isaac Newton decided, based (of all things) on the Western musical scale. Seven notes, seven colours. That could explain why I (and many others) have no idea which part is "indigo".
  • Languages may have thousands of words or phrases for specific colours, but in general cultures tend to settle on < 20 for common use (normally around 10). That means different cultures perceive – linguistically at least – different colours with different words.
  • Russia, for example, has specific words for light blue and dark blue; they are two distinct colours. Early-modern Japanese (prior to extensive Western influence) grouped greens and blues together as one colour. The Berinmo people of Papua New Guinea see "yellow" as two distinct colours, nol and wor.
  • However, it does seem that colours follow a pattern of recognition within languages. First come words for dark and light (sometimes evolving in black and white over time); then red, followed (often quite a bit later) by either yellow or green. The last colour seems to always be blue. Again, there are exceptions, but in general this trend is observable around the world in linguistic archaeology.
While we’re keen to seek out human universals, color has proven to be something that does not have consistent meaning across cultures, or even within a culture group... The meanings we point to—blue as a safe, corporate color, for example—are highly generalized assumptions, highly contextual, and mostly learned associations.

The article continues by reviewing some of the impacts colour choices can have, though interestingly one of them didn't work for me. This graph is used to show that saturation can cause information bias; the chart on the left uses colours of uneven saturation levels, the one on the right has been "balanced" for saturation:

Two pie charts with identical segments, but one has been balanced for saturation by using different colours.
I wonder how many other people find the results of this experiment topsy-turvy...

The article claims that this causes the one on the left to become misleading, drawing your attention specifically to the orange segment and making it "pop". Weirdly, the opposite is the case for me. The left chart is very evenly balanced to my eyes and lets me take in the whole pattern very easily. The chart on the right I find very distracting, immediately being drawn to the red and purple and actively perceiving those segments as larger than they clearly are on the left-hand chart. The article argues that you should avoid the left chart as it is "unevenly perceived". Unfortunately, it seems like the right chart hits those same issues for me, so perhaps the lesson is that you're damned if you do, damned if you don't?

On a lighter note, they also reference this excellent breakdown of colour language in English by XKCD:

Colour map with English names drawn over the regions most likely to use that term, showing very uneven distribution and highly wavy boundaries.
I'd love to know who actually refers to a colour as "dark teal"? And where is "violet"?

Leaky roofs | Seth Godin

Expectations can be all the difference. Getting wet whilst outside? Understandable. Getting wet whilst inside, though?

Promising us a roof and then breaking that promise might be worse than no roof at all.

The miracle sudoku | Cracking the Cryptic

Attempting to solve a sudoku with only two clues and some abnormal rules turns into a joyous, strangely tense thrill ride.

Marxian alienation and web development | Heydon Works

Some interesting thoughts from Heydon on burnout, why it's a positive thing that we're talking about it more, and what a major root cause is for many people:

Burnout is what Marx called alienation. It's when a worker becomes estranged from their work. It sounds like a big, grand thing, but it happens every day, in small ways. As a web designer or developer burnout comes calling when you try to do good work, but you're not allowed.

Thinking in React hooks | Amelia Wattenberger

I'm not going to lie, some of Amelia's breakdown of why hooks > class components went over my head, but the reasoning is solid (plus, preaching to the converted 😉). Even better, though, is that she shares a number of open-source hooks you can use, including ones for synchronising URL hashes and setting/updating cookies. Useful.

📆 03 Jun 2020  | 🔗

  • JavaScript
  • React hook
  • React
  • component
  • class
  • function
  • example
  • guide
  • URL
  • hash
  • cookies 

It's plant, it's animal, it's bitroph | Planet Furaha

The idea of an animal that can derive all or some of its energy needs from the sun is one that sci-fi authors have often touched on. Gert has proposed the nomenclature "bitroph" for such a creature, which I like. He also points out that certain sea slugs are known that "steal" chloroplasts from ingested algae and continue to use them as a sort of battery; they aren't necessary for survival, but help during lean times. Personally, I've always considered the way cold-blooded animals bask in the sun a form of photosynthesis and saw the skeletal adaptations of creates like Dimetrodon (such as sails and large fins) as potentially analogous to bitrophic behaviour.

Gert has also modelled a rough estimate "leaf" size for a mammalian-type metabolic rate. For an animal the size of a bandicoot, it would need to be a circle with a 40cm diameter. Obviously that would look a little ridiculous (and be extremely vulnerable to attack) but honestly it's well within the bounds of reality, which is a pleasant surprise. As he points out, the surface area would be reduced for less energy-intensive body plans, such as crustaceans, as well; plus, having large foldable flaps of photosynthetic skin isn't exactly a stretch (pun intended) when you consider bat and pterosaur wings. Interesting indeed.

Update 15/06/20: Gert's published a follow up. The short of it is that there are a lot more issues with the idea: available sunlight, metabolic need fluctuations (like movement), the fact leaves have mass. On the plus side, photosynthesis on Earth is pretty rubbish, so it could be made a lot more efficient.

Round to the nearest 0.5 | Yang Yang

I'm still chipping away at getting a review section working. Part of that has been finding a way to automate the calculation of series ratings from individual ratings. Not the hardest equation in the world: take the sum of the ratings and divide by the total number of reviews. However, I want to display this using a star (⭐) system, which means I can't have any decimal other than .5 or .0.  Like a lot of languages, PHP will only round to a whole decimal, so you can do .0, .1, .01 etc. using round(), but nothing in between. Luckily, Yang has a solution:

$rating = round((sum rating / ratings count) * 2) / 2;

It's a bit fiddly, but it means that every rating it outputs is either .5 or .0, exactly what I'm after.

The panopticon | Seth Godin

Seth reckons there are three ways to track whether people are working hard:

  1. The boss can watch people in meetings;
  2. The boss can watch people at their desks;
  3. An honour system, where people promise to do something and then do it.

Working from home makes #1 easy and #2 pointless, but #3 is where the magic happens, and I agree.

It seems as though only the third one is a useful, long-term way to allow us to do our best work together.

📆 02 Jun 2020  | 🔗

A static future | Josh W Comeau

A static website is a website where the initial HTML is prepared ahead of time, not dynamically generated by a server on request.

I like this definition. I think it does a good job of encapsulating why static sites are beneficial whilst also being clear that there are very few things a static site can't be. As Josh demonstrates through several examples, he has static sites that interact with databases; static sites that allow users to create generative art (via a load of client-side JavaScript); and normal websites that would only ever want static pages anyway.

Better yet, static sites let you shift computation (where possible) from the user to the server. Sites like this one where all pages are rendered on build. Plus, it gives you additional resilience to mistakes; a production error that crashes a build doesn't impact a live site, and even live errors can simply be rolled back one deploy if you're using a service like Netlify.

Static sites are more performant, more resilient, have better SEO, better user experience, better accessibility, they can be more easily cached. Yes, there will always be some web uses which don't fit the model (a static Slack would be a nightmare) but for a lot of websites, it could be a better choice, particularly as we get features like Incremental Builds.

Gardened | Ethan Marcotte

We’re dealing with the results of bad defaults, deployed at a terrible scale.

The way we make websites is built on a false assumption: that the tools we use are the right ones for the job. Now – more than ever – we should be questioning why common frameworks, dependencies, libraries, and other packages are often poorly optimised. Engineers can put in the work (and many do) to fix those issues, but if the default state is broken then most won't.

In other words, they have to give a damn. But giving a damn doesn’t scale.

It's the users that pay in the short-term, but in the long-term Ethan makes a valid point that it may ultimately mean the tech industry will require greater oversight and regulation. Some of what makes the web great might be lost in that process but, as he puts it:

If other industries follow building codes and regulations, why shouldn’t we?

📆 02 Jun 2020  | 🔗

Hamonshu | Eric Meyer

A really like Eric's latest redesign. I'm a huge fan of ink drawings in general, so it figures I'd like this, but more than the graphic elements I feel like the layout manages to strike a great balance of feeling refreshingly different and yet immediately obvious, particularly on desktop. Snooping the source code shows that there's some clever CSS grid wizardry going on here with negative column/row indices that I'll definitely want to remember 🕵️‍♂️

Made By Me, But Made Possible By:

CMS:

Build: Gatsby

Deployment: GitHub

Hosting: Netlify

Connect With Me:

Twitter Twitter

Instagram Instragram

500px 500px

GitHub GitHub

Keep Up To Date:

All Posts RSS feed.

Articles RSS feed.

Journal RSS feed.

Notes RSS feed.