News for hackers. Stuff that matters.
Re:A small guide for naming stuff in front-end code by graup on Thursday January 13, 2022 @12:42AM (#29917261)
The general ideas are fine, but the examples are pretty outdated. For modern SPA, CSS naming has become largely obsolete. A lot of the JS code shows the principles it is supposed to well but sadly includes other cruft.

Here's a guide I would recommend instead: https://github.com/labs42io/clean-code-typescript

Re:A small guide for naming stuff in front-end code by froddd on Thursday January 13, 2022 @02:26AM (#29917819)
There is a huge amount of content besides SPAs on the internet.

May this continue.

Re:A small guide for naming stuff in front-end code by paceaux on Thursday January 13, 2022 @05:16AM (#29919032)
I'm the original author

All of the examples are within the last 2 years. My area of specialization is enterprise content management; I build the CMS AND the front-end for very large companies that use decoupled CMSs and web sites. And very often, the web app is a typical server-side .net app where a front-end team has written static HTML and handed it off to back-end developers to be sliced into views. So all of this stuff kinda comes from over a decade of doing THAT; it's fair to say that maybe this doesn't all apply if you're an app dev.

But even when I DO build SPAs (like I am for one client), I still use CSS in traditional stylesheets as much as possible because any inline styling that doesn't invoke the CSSOM directly like it should seems like a massive waste of DOM resources ... and also I feel like I lose out on reusability that way.

That "clean code for typescript" is really good. I may drop a link to it in mine. I wasn't trying to be exhaustive. I was just trying to set a good baseline for where to go ;)

Re:A small guide for naming stuff in front-end code by joppy on Thursday January 13, 2022 @08:04AM (#29920316)
Great post!

Your code example for isHot() seems round the wrong way; also doing something like “return temperature > 100” is probably more idiomatic than using if/else just to return true/false.

Re:A small guide for naming stuff in front-end code by paceaux on Thursday January 13, 2022 @08:24AM (#29920464)
Thanks. That's one of those where I have probably 100 cases in code I've written over the years and I can't find a single one when I actually needed it. I'm open to better examples.
Re:A small guide for naming stuff in front-end code by the_other on Thursday January 13, 2022 @09:11AM (#29920893)
> CSS naming has become largely obsolete.

This is enabled by tooling. The tooling is largely still using classes under the hood. If you know how to use the underlying tech well you can solve problems your framework of choice doesn’t solve for you.

Not every web page is an SPA. . Mant projects are small enough that frameworks are overkill, but good practice is still useful. Sites that are mostly content probably shouldn’t be built as if they were SPAs anyway (although many are now).

Re:A small guide for naming stuff in front-end code by runarberg on Thursday January 13, 2022 @11:43AM (#29922906)
Not necessarily. I often use native Web Components when I need to write a quick website SPA or not. Native web components also gives you component scoped styles without having to use any tools which alters the class names.
Re:A small guide for naming stuff in front-end code by kavaruka on Thursday January 13, 2022 @05:59AM (#29919321)
I think that it is really limiting to approach typescript as recommended by this repository :| typescript has a really nice and powerful type system which is not fully used in these examples
Re:A small guide for naming stuff in front-end code by motoxpro on Thursday January 13, 2022 @03:05AM (#29918030)
No opinion about the SPA thing but that guide is awesome. Thank you