PSA: JavaScript is retarded
-
-
@sh_code It's not JavaScript that's kidding you:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html:
The <time.h> header shall declare the tm structure, which shall include at least the following members:
int tm_sec Seconds [0,60].
int tm_min Minutes [0,59].
int tm_hour Hour [0,23].
int tm_mday Day of month [1,31].
int tm_mon Month of year [0,11].
int tm_year Years since 1900.
int tm_wday Day of week [0,6] (Sunday =0).
int tm_yday Day of year [0,365].
int tm_isdst Daylight Savings flag.Javascript just passes those values on.
I would, however, grant you that the
getDate
for day andgetDay
for day-of-week is somewhat silly.
-
The point of high-level languages is to hide dumb low-level mistakes, not expose them.
-
Surely that's what
Date.SUNDAY
throughDate.SATURDAY
andDate.JANUARY
throughDate.DECEMBER
are for? Along with parse/format functions?Numeric values for those are a low-level convenience.
-
@createdtodislikethis Except this is not really a mistake. The values of the items that have names are zero-based, so you can easily index array of corresponding names with the value.
-
@bulb 0-based month numbers is retarded. This is an abolute non-negotiable fact.
-
Enumerations start at 0, things people use numbers for in real life start at 1. Not really that hard to comprehend. That's how it works in pretty much every language, it's just that the ones with actual strongly-typed enumerations don't have to expose the zeroes to their API.
-
@ben_lubar said in PSA: JavaScript is retarded:
Enumerations start at 0, things people use numbers for in real life start at 1. Not really that hard to comprehend. That's how it works in pretty much every language, it's just that the ones with actual strongly-typed enumerations don't have to expose the zeroes to their API.
@ben_lubar said in PSA: JavaScript is retarded:
Enumerations start at 0, things people use numbers for in real life start at 1. Not really that hard to comprehend. That's how it works in pretty much every language, it's just that the ones with actual strongly-typed enumerations don't have to expose the zeroes to their API.
I've gotten burned with the 0 based month years ago. We do regularly represent months with numbers, so I don't think it is an unreasonable mistake.
-
@ben_lubar said in PSA: JavaScript is retarded:
things people use numbers for in real life start at 1.
Except in Javascript, where January is month 0.
-
@ben_lubar said in PSA: JavaScript is retarded:
Enumerations start at 0,
Only in shitty languages.
In C# they can start at any integer.
-
@ben_lubar said in PSA: JavaScript is retarded:
Enumerations start at 0
They don't, because you can assign the numbers. But it is completely irrelevant. What is relevant is where indices start and since C, they always start at 0 in most languages.
@blakeyrat said in PSA: JavaScript is retarded:
In C# they can start at any integer.
As far as I can tell, indices start always at 0 though. And that is what matters.
-
News Flash: Bears shit in the woods.
-
-
@pleegwat said in PSA: JavaScript is retarded:
Along with parse/format functions?
Numeric values for those are a low-level convenience.show me JS' date.format function.
-
@cheong said in PSA: JavaScript is retarded:
@sh_code said in PSA: JavaScript is retarded:
Datetime is difficult. That's why we have Moment.js .
and JS is shit but people are too dumb to make some actually sane replacement for it, and they rather try to cover it up by piling layers of bandages made from shit on top of it, because that's the webstack mentality. that's why we have jQuery, typescript, whateverelsescript and who knows what else.
also processors are dificult, yet i don't see DYI wooden addons which would be basically required for them to work in at least remotely sane way.
-
@sh_code said in PSA: JavaScript is retarded:
and JS is shit but people are too dumb to make some actually sane replacement for it
WebAssembly is a thing.
@sh_code said in PSA: JavaScript is retarded:
also processors are dificult, yet i don't see DYI wooden addons which would be basically required for them to work in at least remotely sane way.
Uh, what?
-
@dreikin said in PSA: JavaScript is retarded:
@sh_code said in PSA: JavaScript is retarded:
and JS is shit but people are too dumb to make some actually sane replacement for it
WebAssembly is a thing.
finally! i've been saying we need this for the past 7 years!
@dreikin said in PSA: JavaScript is retarded:
@sh_code said in PSA: JavaScript is retarded:
also processors are dificult, yet i don't see DYI wooden addons which would be basically required for them to work in at least remotely sane way.
Uh, what?
metaphor meant to express what that sentence about moment.js sounds like. "my processor can't do basic stuff it should be able to do! “ - “that's normal because processors are hard, glue this hobbyist-made addon to it which will make it work fine, or, rather, which will hide and circumvent all its original by-design shittery"
-
@sh_code said in PSA: JavaScript is retarded:
@pleegwat said in PSA: JavaScript is retarded:
Along with parse/format functions?
Numeric values for those are a low-level convenience.show me JS' date.format function.
I'd expected something like that to be posted faster...
I was intending to describe how sane languages work. I was not intending to implicate javascript is sane.
-
@sh_code said in PSA: JavaScript is retarded:
metaphor meant to express what that sentence about moment.js sounds like. "my processor can't do basic stuff it should be able to do! “ - “that's normal because processors are hard, glue this hobbyist-made addon to it which will make it work fine, or, rather, which will hide and circumvent all its original by-design shittery"
I think this is the new winner for "worst metaphor ever".
-
@sh_code said in PSA: JavaScript is retarded:
show me JS' date.format function.
Date.prototype.toLocaleString
,Date.prototype.toLocaleDateString
andDate.prototype.toLocaleTimeString
. The arguments are, unfortunately, retarded though. If you want to pass options—you do want to pass options—you also have to pass the locale—for which you almost certainly want to use the default.But at least, it actually knows the localized timezone name:
$ node > new Date().toLocaleString('cs-CZ', {'timeZoneName': 'short'}) '6. 10. 2017 23:37:01 SELČ'
(same result in Chrome) which is better than GNU LibC.
-
@bulb said in PSA: JavaScript is retarded:
@sh_code said in PSA: JavaScript is retarded:
show me JS' date.format function.
Date.prototype.toLocaleString
,Date.prototype.toLocaleDateString
andDate.prototype.toLocaleTimeString
. The arguments are, unfortunately, retarded though. If you want to pass options—you do want to pass options—you also have to pass the locale—for which you almost certainly want to use the default.But at least, it actually knows the localized timezone name:
$ node > new Date().toLocaleString('cs-CZ', {'timeZoneName': 'short'}) '6. 10. 2017 23:37:01 SELČ'
(same result in Chrome) which is better than GNU LibC.
huh.
at first I was trying to come up with some snide remark, but actually you kinda caught me having a stupid moment (in not having discovered those functions/not having realized they might be useful. I was thinking in line of ".format(param, 'dd.mm.yyyy hh:ii:ss')", didn't realize going for our official locale format (or, in the worse but still functional case, some other locale with the format I'm looking for) can work too.i admit that makes me feel a bit of a fool and makes the OP a bit of a less of WTF.
-
@blakeyrat said in PSA: JavaScript is retarded:
@sh_code said in PSA: JavaScript is retarded:
metaphor meant to express what that sentence about moment.js sounds like. "my processor can't do basic stuff it should be able to do! “ - “that's normal because processors are hard, glue this hobbyist-made addon to it which will make it work fine, or, rather, which will hide and circumvent all its original by-design shittery"
I think this is the new winner for "worst metaphor ever".
thank you, I tried really hard. good to know my effort was not in vein :-D
-
@bulb said in PSA: JavaScript is retarded:
@createdtodislikethis Except this is not really a mistake. The values of the items that have names are zero-based, so you can easily index array of corresponding names with the value.
Just make a 13-element array and put January in 1st slot, and make 0th null or something.
-
@gąska said in PSA: JavaScript is retarded:
@bulb said in PSA: JavaScript is retarded:
@createdtodislikethis Except this is not really a mistake. The values of the items that have names are zero-based, so you can easily index array of corresponding names with the value.
Just make a 13-element array and put January in 1st slot, and make 0th null or something.
Then wait for the inevitable iteration over said array to build a dropdown of months in the UI somewhere.
-
@arantor said in PSA: JavaScript is retarded:
@gąska said in PSA: JavaScript is retarded:
@bulb said in PSA: JavaScript is retarded:
@createdtodislikethis Except this is not really a mistake. The values of the items that have names are zero-based, so you can easily index array of corresponding names with the value.
Just make a 13-element array and put January in 1st slot, and make 0th null or something.
Then wait for the inevitable iteration over said array to build a dropdown of months in the UI somewhere.
Are you directly indexing array with integer, or are you making GUI?
-
@gąska In JavaScript land, probably both in the same codebase.
Me, this is why I use PHP where we don't have such confusing shit. [citation given] (True, the syntax of date() is shite, but we don't start our months at zero.)
-
Why not just start arrays at 1 and save everyone the bother?
-
@sh_code said in PSA: JavaScript is retarded:
I was thinking in line of ".format(param, 'dd.mm.yyyy hh:ii:ss')", didn't realize going for our official locale format (or, in the worse but still functional case, some other locale with the format I'm looking for) can work too.
The trouble with that kind of pattern is that you have to localize it yourself. Though the options are rather unwieldy. I would prefer something with support for skeletons.
By the way, simply coercing the
Date
object to string gives the ISO-8601 format for serialization. And I don't see much use for anything else besides that and locale preferred format.@arantor said in PSA: JavaScript is retarded:
Me, this is why I use PHP where we don't have such confusing shit. [citation given]
And do you have support for skeletons? Or at least for he base locale-aware formats
full
,long
,medium
andshort
? I don't see it in that documentation. JavaScript at least does, although with rather verbose syntax.@arantor said in PSA: JavaScript is retarded:
but we don't start our months at zero
Because you don't have a split date in the first place, do you? Well, that's not much to brag about.
-
@arantor said in PSA: JavaScript is retarded:
Then wait for the inevitable iteration over said array to build a dropdown of months in the UI somewhere.
months[0] = "Please select a month":
As usual, JavaScript:
> arr = [0, 1, 2, 3] < Array [ 0, 1, 2, 3 ] >> Object.defineProperty(arr, '0', { enumerable: false }) < Array [ 0, 1, 2, 3 ] >> arr < Array [ 0, 1, 2, 3 ] >> Object.keys(arr) < Array [ "1", "2", "3" ] >> arr.forEach((i) => console.log(i)) 0 1 2 3 < undefined
Edit: okay, I can't really blame Array#forEach for knowing how to correctly iterate over itself despite my efforts to pervert it. At least the results of Object.keys() and Object.values() are consistent. This bit is fun too, the zeroth element is enumerated out of place:
>> console.dir(arr) ▽ Array(4) 1: 1 2: 2 3: 3 0: 0 length: 4 ▷__proto__: Array(0) < undefined
-
This post is deleted!
-
@zecc said in PSA: JavaScript is retarded:
> arr = [0, 1, 2, 3] < Array [ 0, 1, 2, 3 ] >> Object.defineProperty(arr, '0', { enumerable: false }) < Array [ 0, 1, 2, 3 ] >> arr < Array [ 0, 1, 2, 3 ]
That is not a . The array is indexed from 0 to length - 1. However:
> arr = [0, 1, 2, 3] [ 0, 1, 2, 3 ] > delete arr[0] true > arr.forEach((i) => console.log('-> ' + i)) -> 1 -> 2 -> 3
this might be.
-
I think I posted it earlier in this thread, but this still happens and I don't know why:
https://i.imgur.com/UlR4uTd.pngNodeBB is painful, but I can't imagine that it needs Flash for literally anything.
-
@pie_flavor something from iframely maybe.
-
@bulb it's not a thing any of the PHP devs have seen fit to add yet. But seeing how that function predates your link by a number of years, it's not going to add it retrospectively and break backwards compatibility.
The later library that overhauled it with better time zone support... also predates your link.
PHP moves a lot slower than JavaScript because the deployers of it are slow, and there isn't an arms race between implementers to keep up development.
But sure, feel free to tell me how wrong I am about something most people in the web dev world don't know about or ever deal with.
-
@bulb said in PSA: JavaScript is retarded:
As far as I can tell, indices start always at 0 though.
Pascal allowed for declarations of arrays with indices from M::N range
-
Why not just normalize array indices so that you can do anything from arr[0..0.1...0.5...1.0]
-
-
@pie_flavor said in PSA: JavaScript is retarded:
Why not just start arrays at 1 and save everyone the bother?
Because we don't want to be literally Hitler. Duh.
-
@dkf said in PSA: JavaScript is retarded:
@pie_flavor said in PSA: JavaScript is retarded:
Why not just start arrays at 1 and save everyone the bother?
Because we don't want to be literally Hitler. Duh.
Naw, for that we'd have to start the index at 9.
-
@arantor said in PSA: JavaScript is retarded:
But sure, feel free to tell me how wrong I am about something most people in the web dev world don't know about or ever deal with.
Well, the skeletons may be relatively new, but the
full
/long
/medium
/short
formats are in Java from early versions andstrftime
had the%c
,%x
and%X
and their%O
and%E
variants since about the time our ancestors climbed down from the trees.Yes, many programmers don't know how to ever deal with it; that does not mean programming language designers shouldn't.
-
@thecpuwizard said in PSA: JavaScript is retarded:
@bulb said in PSA: JavaScript is retarded:
As far as I can tell, indices start always at 0 though.
Pascal allowed for declarations of arrays with indices from M::N range
Yes, I know. But you snipped the bit of context where it said
@blakeyrat said in PSA: JavaScript is retarded:
In C# they […]
It is also the reason I said
@bulb said in PSA: JavaScript is retarded:
[…] since C, they […]
fully aware that in Pascal they started from whatever you declared.
-
@bulb it's a good thing we have strftime as well then even if it is handicapped by the locale database provided by the operating system and thus might not have all of the variants you mention.
-
@arantor Ok, at least something.
(And yes, the system locale database is crappy; I am fully aware)
-
@pie_flavor said in PSA: JavaScript is retarded:
Why not just start arrays at 1 and save everyone the bother?
-
@hardwaregeek what about people who think
Option Base 1
is a really neat idea?
-
@pie_flavor said in PSA: JavaScript is retarded:
Why not just start arrays at 1 and save everyone the bother?
Let's compromise and start at 0.5.
-
@mzh said in PSA: JavaScript is retarded:
@pie_flavor said in PSA: JavaScript is retarded:
Why not just start arrays at 1 and save everyone the bother?
Let's compromise and start at 0.5.
Crazy person: "Eat this bar of soap"
Sane person: "Do not eat soap"
You, an intellectual: "I will eat half of this bar of soap"
-
@rhywden said in PSA: JavaScript is retarded:
Naw, for that we'd have to start the index at 9.
Ugh, that reminds me of porting code from a language that did that and where the author of the code had used it extensively. :(
-
@dkf said in PSA: JavaScript is retarded:
@rhywden said in PSA: JavaScript is retarded:
Naw, for that we'd have to start the index at 9.
Ugh, that reminds me of porting code from a language that did that and where the author of the code had used it extensively. :(
Seriously?
The author was obviously Hitler, then.
-
@dkf said in PSA: JavaScript is retarded:
@rhywden said in PSA: JavaScript is retarded:
Naw, for that we'd have to start the index at 9.
Ugh, that reminds me of porting code from a language that did that and where the author of the code had used it extensively. :(
Well, if it was C++, you could have simply overriden operator[] and said 'meh, it works.' Oh, I guess that needs the additional statement 'fuck the maintainers'