DEV Community

Cover image for What structure, operator or other thing do you use most in your daily development?
Renan Ferro
Renan Ferro

Posted on

3 1 1

What structure, operator or other thing do you use most in your daily development?

Hey guys, how are you?!

Today I was developing some things and I realized that I was using something very frequently, this is wonderful because as I develop using Angular, when we have more repetition of components, for example, the better, as it becomes easier to create components and reuse structures!

In my case, I noticed that I use the Conditional (ternary) operator quite often (My heart aches to know that Clean Code indicates not to use If too often and at too high levels
🤣🥲).

Image description

Here are a simple example of the structure:



<h1 [ngClass]="titleForHomepage ? 'title-homepage' : 'title-internpage'">
  {{ title }}
</h1>


Enter fullscreen mode Exit fullscreen mode

Therefore, I'd like to talk to you and find out what you frequently use when developing?! It could be some validation structure, JavaScript operator or something else!

Share with us and let's talk!

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (4)

Collapse
 
alexandermirzoyan profile image
Alex Mirzoyan

In React there are a lot of packages for managing ternary operators for conditionally rendering some UI parts. It's really easy to even create such components by yourself.

I am sure that Angular also can have such approaches. Even if it is hard to find such kind of components I think it's better to move the conditional statement to Component file for making the code cleaner and more readable.

Attaching some packages for React.

npmjs.com/package/react-if
npmjs.com/package/react-conditiona...

P.S. If you wish I can share my own written solution for such kind of problem.

Collapse
 
renancferro profile image
Renan Ferro

Wow, really cool and interesting. I also like to keep everything well componentized to avoid duplication and make maintenance easier. Thanks for sharing!

Please, I'd love to see your solution!

Collapse
 
alexandermirzoyan profile image

Pushed the solution to GitHub.

Feel free for any kind of comments.

github.com/alexandermirzoyan/rc-co...

Collapse
 
skamansam profile image
Samuel

I use list comprension (in python) a whole lot. I used suffix ops to achieve the same in ruby. But I also use the ternary op a lot, and I love it.

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay