Hacker News new | ask | show | jobs
by iainmerrick 2267 days ago
Or, “Object-oriented”

Remember when we were building our apps as a set of screens and pages instead of thinking in components?

Sure, but I also remember building web apps in GWT, using a toolkit of reusable widgets, with an OO interface.

Edit to add: I guess I’m more agreeing with the author than arguing with them; I just find it amusing how what goes around comes around.

2 comments

How does it become any more object-oriented?

I saw it more as "purely functional", where components are the functions and styling outside of the component is a side-effect. Avoiding side-effects like margin or align-self makes components more like pure functions than objects IMO.

Margins and align-self aren’t side-effects. Their semantics are consistent and reproducible and depend only on the context a component is placed in, just as a property like width does.

They’re awkward because they have bigger knock-on effects on the overall layout of components within the parent.

In an OO mindset, I see this as being all about what interfaces your object exposes. For something like a button or slider control, it obviously exposes an action callback of some kind. But it also exposes a generic “child component” interface, which is the only thing a generic parent component cares about.

What are useful things and what are obnoxious things for a child component to do? Flexibly adapting itself to a range of sizes is useful. Demanding that it should be centered is obnoxious. In fact it would be hard to express at all in most OO widget toolkits. So I think this problem is very closely related to good OO design.

Their semantics might be consistent, but they sort of leak into the parent. Height and width are local to what the component renders, and they don't depend on the parent (as long as they aren't relative sizes). But things like margin and align-self change how the parent renders all of its children.

In other words, the view rendered by the component is a function of properties like height and width. But when you throw in margin or align-self, the component now depends on its siblings.

The OO perspective is interesting — I agree that it effectively makes these things hard to express. I now think that it's more of a problem relating to encapsulation and isolation. OO would isolate it through a child component interface while FP would have a function that can't affect siblings.

Yeah, I think we’re mostly agreeing! Encapsulation and isolation are the key bits, and both FP and OO suggest ways to achieve them.
I would love it if the new component revolution worked for sites not using Javascript frameworks.