DEV Community

Cole Diffin
Cole Diffin

Posted on

Screaming Snakes in Javascript

SCREAMING_SNAKES case has no place in modern day javascript.

It's ugly, it's vulgar, and it makes any code less desirable to read. I feel like my eyes are being yelled at for doing something wrong when I read it.

The most common place I see SCREAMING_SNAKES, is when someone uses it to define a constant. At the top of a file. Let's think about that for a second. They took the effort to arrange their code in such a way they can put the constant at the top. (let's assume it had positive outcomes and wasn't a pointless re-factor) now, when I open their code, the first thing that hits me in the face is a stack of SCREAMING_SNAKES! They all kind of meld together - typically, I'll just ignore them and move on to where the real code begins. Then at periodic places throughout the code, I get a SCREAMING_SNAKE to the face, which I probably do want to decipher this time, and hopefully, it's named carefully so I can determine the content of the variable based on the name (entirely different rant.)

It's 2017. We have the good(?) fortune to have hundreds of build tools at our disposal to work around browser caveats and implement half baked specs that make embedding SCREAMING_SNAKES completely un-necessary, a.k.a imports!

In my opinion, take your dirt SCREAMING_SNAKES and move them to a separate file. You can even call that file constants.js if that fits in with your file structure. Export all your constants, then you can import them where ever you need to. (and, they will be proper constants i.e. immutable thanks to the transpiler tasks in your build pipeline.) And guess what, you don't need to make them SCREAMING_SNAKE case to make your point.

The history of SCREAMING_SNAKE case in javascript (based on my 1 person poll around the office) is due to the need to identify the constant as a constant, so people didn't accidentally change it. This is no longer an issue, due to the immutable nature mentioned above.

Top comments (10)

Collapse
 
caseyreeddev profile image
Casey Reed

"Eye-raped" has no place in modern day article writing. It's ugly, it's vulgar, and it makes any article less desirable to read.

Collapse
 
patricktingen profile image
Patrick Tingen

I like the term "eye-raped"; what has been seen cannot be unseen. Furthermore, I really appreciate that someone finally took the effort of doing a poll about the usage of screaming snakes :)

Collapse
 
caseyreeddev profile image
Casey Reed

"The use of sexualized language or imagery" is literally the first unacceptable behavior listed in this website's Code of Conduct.

Collapse
 
patricktingen profile image
Patrick Tingen

Yeah, actually, you're right! But since you started out with an opinion, I joined in. And to be honest, I still like it ....

Thread Thread
 
arcticshadow profile image
Cole Diffin

I'd like to thank you for reading my first article, and providing some constructive feedback.

My intention was never to use an overly sexualized term, to extend the reach of my work. I found it to be an exact representation of the feelings that I had on a regular basis when a constant in code was represented by SCREAMING_SNAKE case.

It would appear that my understanding of the term is not as common as I initially thought. I have even spent the morning researching other sites and blogs in a futile attempt to find supporting evidence, and have turned up empty handed. I am happy though, that there is at least one person that does appear to have interpreted the term in the same way I initially have.

I shall edit my article with hopefully another punchy description, that does not offend the masses.

Thread Thread
 
caseyreeddev profile image
Casey Reed

Hey, man. Just wanted to say that I really appreciate your level-headed response to my comments. I thought you wrote a really great, thought-provoking article and I'm glad that you could understand my criticism in your use of a term often reserved for describing sexual assault to describe how a variable typed in all-caps makes developers feel. I'm certain you didn't intend any harm in choosing that phrase, but I didn't believe its inclusion helped to further the mission statements or code of conduct of this site.

Once again, thanks for accepting my criticism and having an open dialogue about this.

Thread Thread
 
arcticshadow profile image
Cole Diffin

But of course! Without an open dialogue, one cannot learn and grow.

Collapse
 
arcticshadow profile image
Cole Diffin

You have raised a couple of good points here. It's been a long while since I wrote any PHP - back in the days of 4x transition to 5x. If I recall back then It was a similar story to what you describe.

So there will naturally be slight differences between meanings in different languages, however, this appears to be more of a developer habit than a language convention, so it does make sense that the patterns are common.

In the situation that config is presented as a SCREAMING_SNAKE I would suggest the need to carefully examine if it is in the correct place. Typically, config would be better located elsewhere. Especially if it is sensitive, or shared. There are instances of course, where in-file does make sense - but again if that's true, is it used multiple times in the file? If not, why not just inline it and save yourself time and overall code.

My comments regarding Developers using SCREAMING_SNAKE case to represent immutability, is more targeted towards Javascript, where IDE's are a luxury (that usually don't work well) Typical setups would involve a modified/customized editor like Atom or VSCode, but still, leaves the language nuances to you. In particular, in the past, immutability has been a distant thought, i.e. you can edit anything, at any time, so best to make it obvious things that you shouldn't edit accidentally.

Collapse
 
jbwebtech profile image
jbwebtech

It's a great day for JavaScript that we have immutables and don't have to rely on the developers to "not change the thing." Thanks for the perspective!

Collapse
 
ptkdev profile image
Patryk Rzucidło • Edited

I love 🐍 {snake_case}