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

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 }}
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!

Top comments (4)

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.

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

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!

alexandermirzoyan profile image

Pushed the solution to GitHub.

Feel free for any kind of comments.

skamansam profile image

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.