My love-hate relationship with JS/TS and CSS

András Tóth - Apr 11 - - Dev Community

INSERT AI GENERATED HEADER IMAGE

I frequently encounter comments that love Javascript and CSS dearly. That is fine, but they reply in quite harsh manner when I point out several unmitigated mistakes of these languages.

So this is how I see the stack as a professional JS/TS developer who worked with them for around 8/12 years (I used CSS for longer than JS).

In the browser we have a lack of choice: you have Javascript, CSS and WASM. You can't get a more performant language, you can't get a higher level language: whatever you code must boil down to these options.

I contrast it with any other operating system, where you have a huge array of languages.

Many years ago, a lot of companies moved their legacy platform-based solutions to the web. I was working once on a project that recreated (with better UX) a chat application running on Windows only. By moving to the web we instantly gained MacOS and Linux users.

We could do this, because essentially the browser became a mini operating system. If this is the case then we should treat it as such and expect the variety we have when we work with an OS.

My next point is that...

languages (however beloved) in the browser were designed during a much different stage of the internet.

People who hate CSS usually hate it, because it has so many features and optimizations about how to create pleasing documentation (see also: margin collapse feature). On the other hand many of us have to deliver large scale applications that have very interactive UI; a thing for which CSS was not built (even though it is getting better at).

People who hate JavaScript hate it for its quirks and gimmicks (see also: [] + {} === 0 vs {} + [] === [object Object]) which came from a person tasked to write a language in a week and he chose these and also because of backward compatibility of the language. Yet another reason is that fully dynamic languages suck at scaling: you end up with MDD: memory driven development (in other words: you are cool if you remember everything you wrote, 'cause the IDE can't help you), which is only not a problem when you code alone.

Now all these limitations were and are somewhat mitigated by an awesome community, who adds new elements to languages, like flex to CSS.

But these are mitigations instead of purpose-building. Imagine you want to fix throughput of trucks by chaining together many trucks; but it would be better to transport cargo on rails.

JavaScript, TypeScript, CSS are not bad languages, and I can be very productive working with them. But, and that's a big but, it's quirks and problems are causing constant troubles, especially for junior and mid-level engineers. The former are utterly confused at the quirks, the latter rage-quits problems and brute force patterns, like TailwindCSS or OOP or FP onto languages that will never have the guarantees and optimizations for those approaches.

As I said, I don't hate the languages of the Internet, but I wish for a bigger dose of healthy criticism and thinking out of the box. After all, we have now a huge amount of real world use cases which we didn't have when CSS and JS were designed; it is normal to time-to-time to rewrite basics to better align with usages.

It is foolish to think we can predict how tech will be used; it is even more foolish not to react how tech is actually used.

I don't even dare to suggest things like "Can we have a separate engine for the case when I don't have a document, but I do have rich UI inputs?", I just want to state the problems here.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .