Recently I read JS Coding Patterns that give you away as a Junior Developer
by Alexey Chang. Which is an interesting read! I encourage you to read...
For further actions, you may consider blocking this person and/or reporting abuse
I don't agree with multiple paddings / margins. Using the shorthand only when appropriate is a sign of a more experienced developer. You shouldn't be setting properties you don't actually want to set just so that you can use shorthand syntax. What if you want to change just one of the sides? You have to overwrite the whole declaration again, repeating 3 of the values just to change the 4th one.
Verbose can be better than concise where verbose is easier for humans to understand. There is sometimes too much of a drive towards concise over anything else.
Thanks for your input! Ye in some cases it can be best to only do 1 value. It will be very dependable on the scenario. In general tho, I see a lot of juniors just staying from it all together.
Also a problem could arise with doing a specific value. Let's say on dekstop it's padding-top: 20px; but on mobile it's: padding-bottom: 20px; This means you would need to write a media query to make padding-top: 0, and padding-bottom: 20px; So cases like this would be better to have a 1 liner.
But I do agree that you should not blindly go into 1 liners for every scenario. In most cases it is the better option, but for sure, as you said, not in all cases.
You'll need the media query anyway, and there's different ways to reach it.
From the example I'll reply it using different approaches:
1
2
3
4
From this 4 options the most correct one is the second one and depending on the context I can say the fourth.
Why?
On the 1 and 3 there are unnecessary overrides. Also shorthands are less specific in CSS, so
padding: 10px 5px 8px 16px;
will be easily overwritten by any padding-[direction] property declaration such aspadding-top: 15px;
.If you know these properties must keep like this (otherwise edit this same declarations) keep the option 2, if you are building a component and you are aware that this properties will be (or could be) context-dependant get the option 4 to avoid using !important statements and fall to padding-[direction] instead.
Knowing a language and its details is what makes a developer a Senior developer, using one think or another because it seems more trendy or fashion to you it's not.
Amazing examples, ye that is what I ment with based on the context. Great input man! Thanks :D
"Now, this CSS will work, but is it well written? No! You should aim to have all the margins or paddings grouped up." - says who?
A lot of this seems like subjective preferences. A developer could have patterns of habit established by previous coding environments that favor one method over another. Don't be so quick to judge someone's level of experience just because they do something different from what you think is right
That is true, never judge a book by its cover! However I felt the need to write about it because it both makes the CSS cleaner and faster to change in media queries. Of course there are still cases where you don't need them in one line.
More often than not, I see the juniors use padding/margin-top, -right, -bottom, -left over 1 liners. So I figured this is something they struggle with, that is why I tried to explain as best I can about how the 1 liner is structured and how they could use it to their advantage.
It's not faster to change in media queries, nothing to do with that.
is much more cleaner (and precise in computational terms -> take a look at how CSS is evaluated and rendered - painted by the browsers) than like it or not.For the "cleaner" statement I've to disagree, the most clean code is that one that is wrote in the manner that makes just what it needs to make.
If you are used to use the shorthand it's ok as long as it does not put you in trouble when needing to override something but that's all, there are 0 extra-advantages of using that.
In his original example, the person is using margin-top and margin-bottom. In that case, I think the shorthand looks cleaner.
There's a bit of misconception about what cleaner means and depends on the context, but keeping with the example, using the shorthand you will be setting 4 properties when only 1 is needed which is bad from any point of view, specially when the project grows up and you need to override property values instead of declaring them, like it or not it's true computationally, and will be opinionated for human reading (unless you are a heavy user of shorthands and are used to them the padding-[direction] will be understood by any developer regardless of their knowledge level) but this second point is less important than the computational point of view one
That li-thing i've always done as
li+li { margin-top: 1em }
.May be useful when different tags are mixed and we want spacing just between same things.
I prefer using lobotomized owls *+*
this makes your code less optimized, so in performance terms it's an issue and must be avoided
How so? What's less performant about
*+*
compared to the other ways you could express it?Was unaware of the :not() selector! Wow!
I wrote an article for it, hope it helps you out! :)
Haha ye it can be a real game changer! Soon I will write a complete post about the :not() selector. You can achieve a lot of things with it
nice, i would be glad if you share more css snippets from time to time. not() was new to me.
Take a look at the guide , you'll find nice tips for sure 😄
I just wrote a dedicated article about! Hope it can help you out
Also possibly using pixels I much prefer rems :)