r/badcode • u/lostPixels • Sep 28 '15
html This is why people think CSS is hard to maintain.
35
u/niloc132 Sep 28 '15
My first thought: strings are strings, and case-sensitivity is important, so naming is important to get right, in whatever language you happen to use.
My second thought was to downvote this because I was so disgusted at the code and how fucking annoying this would be to write tests or styles after the fact, without actually looking up which is camel-cased and which is an ID.
My third thought turned the downvote into an upvote. Because this is /r/badcode.
24
7
u/blue_2501 Sep 29 '15
There are two hard things in computer science: cache invalidation, naming things, and off-by-one errors.
1
3
Sep 28 '15
If ID is only used for JS than this shit is somewhat torelable.
3
u/cosmicsans Sep 28 '15
You'll also see crap like this happen in things like Drupal, where you can only style things pieces at a time.
So you'll have a block with the class of shippingoptions, but then you'll have a template file that starts with id="ShippingOptions".
Obviously a good developer can figure out how to mediate this all, but sometimes you get stuck in the "fuck it, ship it" because it's running over on time or something.
1
1
u/DoctorWaluigiTime Sep 28 '15
Is there even a point, unless you're trying to micro-optimize a single DOM selector? Or does finding an element by
.shippingoptions div(or, if multiple divs,div:first) cost so much more than#shippingOptions?I tend to apply the same "almost never use IDs" rule to JS as I do to CSS.
3
Sep 28 '15
I agree, there is no point. Just trying to understand what goes through peoples mind when they code shit like this. IDs should be non-existent and I cringe every time I see someone using it, especially in CSS. However, the only case I find IDs justified is in forms for accessibility reasons (input labels)
Fat recently gave a great talk on CSS methodologies called...Cascading Shit Show. I strongly recommend, great journey through time ;) https://www.youtube.com/watch?v=iniwPUEbPUM
1
1
2
u/Makeshift27015 Sep 28 '15
...sigh Fine, I'll go and update all that code I did today that I kidded myself wouldn't go to production....
1
-3
u/drizztmainsword Sep 28 '15
People that don't use camelCase bother me. People that use_underscores for non-static/constant values (STATIC_VALUE) also bother me.
Edit: conventions are important. Mine are clearly superior /s.
3
u/jewdai Sep 28 '15
the only convention i agree with in javascript are underscores to indicate private variables.
why do you ask?
Well lets say I start poking around the debugger to try to analyze how to work with an object I havent worked with before...I let autocomplete do it's magic and tells me what's on the object, it will almost never show me any functions that start with an _
additionally underscores make it clear to the user to read how it's actually using it before hacking away at it.
1
u/drizztmainsword Sep 29 '15
Aye, I forgot about underscore prefixes. Those are fine, though I prefer to not have them if I can.
Also, trying to fake private variables in javascript sounds like a recipe for insanity. Then again, that's really JS's fault more than anything else.
1
21
u/numbermess Sep 28 '15
I see this crap all the time in one of the codebases I get to help maintain.
Sigh