I do believe I’ve shared my feelings about Javascript in the past. At least partially. And if I remember right, it wasn’t exactly favorable.
And while time makes fools of us all, my feelings for the percolated language remain unaffected by Chronos’ hand.
Why?
Well, let me tell you a little story about a woman named String:
String has had quite a journey over the last 50 years of her life.
In her younger days, she never knew how tall she was. Often, she was written off as nothing more than a small span of memory. This was unfortunate, for she knew that she was destined for greater things. But at that time, the world was just not ready for her.
Determined to make it on her own, String set out to prove she was the best: that she could do anything. She tried many odd jobs, from writing cryptic acronyms and abbreviations for banks and scientists, to keeping track of to-do lists. But depending on the task, she could take a little while to learn and perfect the task, particularly if she hadn’t done anything like it before.
This, of course, wasn’t good enough for the new, fast-moving world. They wanted ultra-high speed, ultra-high efficiency. Not flexibility. Flexibility was slow. Flexibility was wasteful.
String had no choice but to jump from job to job, and eventually her reputation as a “job jumper” got to the point that no one would hire her anymore. She tried moving to a new area, only to find out that previous contacts already had her on a veritable “do not hire” list. She was shut out from everywhere.
Then, she met a man named Parse. Parse knew just how to put String’s flexibility to good use. Parse knew that String was a dirty girl.
Parse offered himself as an “agent” to String. He said that he knew how to make her famous. He could make her the best at everything. With one catch. String would have to do whatever Parse wanted. With whomever he wanted. Anytime he wanted.
Soon, String was everywhere. She knew her craft inside and out. Literally. She could do anything, in any position. A list of four-hundred items? String would delimit them and keep track of it. Need to make “July eleventh, nineteen hundred eighty eight” act like “7/11/1988”? String hid the secret in her undergarments.
And so, String did get her wish: she became indispensable. Yet she did so at the cost of her dignity. Sure, she was needed, wanted, and coveted the world around. Just, not how she wanted to be. Now, String was nothing but a whore to be used by anyone who was too lazy to do it the right way.
For those of you uninitiated in the programming world, a “string” is a way of representing data as a chunk of letters, numbers, punctuation, or other characters in your computer’s memory. Think of it like the Post-It note you stick on the fridge: a piece of information in phrase form that you want to remember for later. The act of “parsing” a string, attempts to look at that phrase and extrapolate another piece of data from it. For example, a string parser might be able to interpret the phrase “five dollars and seventy five cents” and convert it within the computer directly to the numeric value of “5.75”.
とても (super) useful, ね?
As programmers, we all know we misuse the string type from time to time, mainly due to the power of what string parsing has become. Sure, it’s super convenient, super versatile, and in a few cases, the only way some things will work.
Does it suck? Yes. It’s our own fault though — we’ve made so many data types do so many things, we can no longer convert between them without String’s help.
Now, I’m first to admit that I’ve visited String from time to time. And she is brilliant. She makes you feel incredible. She will do anything, and everything. You just have to be able to ask her. But as a programmer, I’m always very conscious in making sure I wear my coding condom when I visit String.
Reason being, you can never be sure exactly what rules Parse has her working under. Sometimes, he’ll only accept “7-11-2008” as a valid representation of a calendar date; when that’s true, forget trying “7/11/2008” as it just won’t happen. Sometimes, Parse won’t let String realize that she’s smarter than him.
And yes, you guessed it, when Parse dabbles in Javascript, he makes String act dumb as hell.
I found out today that, when you attempt to parse a date with only two digits for the year, like “7/11/08” (which, we would all interpret as July 11, 2008) with Javascript’s built in string parser, it thinks it’s July 11, 1908.
In the words of Lil’ John, “WHAT?!”
Sure, I understand that Javascript’s first implementation was before the Y2K switch. Fine. Maybe that’s one explanation. However, this was in 1995. Solidly within the time that someone, somewhere had to have been thinking about the possibility of the Y2K bug.
Secondly, there have been new implementations of Javascript that have their roots in this century. Why, then, does Javascript still use 1900 as it’s base year? (Yes, that’s right. Every web browser you use has it’s own, “special” way of understanding Javascript, which a lot of times is different from other web browsers. That’s why most developers hate Javascript.)
Thirdly, Javascript, like many UNIX-based systems, utilizes the UNIX epoch, or, POSIX time (the number of seconds since midnight, January 1, 1970, UTC) when it parses a date. Thus, any date that it would parse, one would think, would be interpreted as post-1970, right?
In fact, Javascript seems to utilize a flux capacitor to create negative time, and generate a negative number of seconds since the UNIX epoch, solely to parse a date into the early 1900s.
This, quite honestly, is stupid.
Yeah, I get it, time did exist before the 1970s. Duh. Hell, it existed before the 1900s. So why not assume the 1800s? Or the 1200s?
We’re talking computers here. The computer we detest but tolerate today started around the 1970s. The 50’s if you count when they took up an entire room. Why, exactly, would a programming language invented in 1995 even begin to think that it was a good idea to assume all dates start at 1900?
This means that, yes. I literally had to add an extra hundred years, manually, just to get the date to parse right. And that’s super great for maintainability in the future. Though, I do hope the software I’m working on now is replaced by something better in that stretch of time…
String, honey, I love ya. But after this long with Parse, it’s time you showed him what a real education can do.
And you might want to consider an antibiotic.