Live data from Hacker News

New Features in ES2019

javascript.christmas

21–30 of 123 posts

Re: New Features in ES2019

#21

Not ES directly, but you know what I need on an almost daily basis? A JSON date type. It’s obnoxious to have to pass a string back and forth and parse it on either end between server and browser.

You can use an unix epoch (seconds or milliseconds from 1/1/1970) to make parsing very fast. This is naturally supported by Javascripts new Date() too.

Re: New Features in ES2019

#22
post #11

Really liking these new developments! JavaScript is not the horrible language it used to be anymore (in my very subjective opinion). When I started writing JavaScript in 2016 after a Python background I was frustrated every day... Then after some time and learning about which dark corners to avoid, which tools to use, etc. it became quite an enjoyable experience. Nowadays I mostly use a mix of JavaScript and TypeScri…

> One thing that I am a bit afraid about though is that the language might become more complex and complicated over time because of backward compatibility (C++-like?).

New methods with simple behaviour don't really make the language more complex through.

> And that's great, but that's a new function, and maybe 'replace(...)' should have had this behavior from the start.

As you note it kinda does, just in a weird roundabout manner.

One issue with javascript is also that it makes extending existing functions difficult, because extra arguments are just ignored by default, so you can't just add a `count=1` parameter to String.replace to override the regex flag as there could be code out there which already passes a third (currently ignored) parameter and would break.

Re: New Features in ES2019

#23
post #20

Not ES directly, but you know what I need on an almost daily basis? A JSON date type. It’s obnoxious to have to pass a string back and forth and parse it on either end between server and browser.

I was going to ask a variant of that question: what is the status of BigInt and when might it clear TC39 approval? In most languages a Date object is just a BigInt with Unix time() making this somewhat obvious. BigInt will allow not only proper Date implementation but Currency and Real types, and many more things.

BigInt is already in several modern browsers: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re: New Features in ES2019

#24
post #5
post #3

I don’t mean to hate on ECMAScript, but is anyone else slightly surprised these features weren’t in earlier? Like I wonder how many bugs were introduced because the developer didn’t realize Array.sort() was unstable.

Another sort() quirk that catches people out is not realising it uses string comparison by default [1,2,10].sort() = [1,10,2]

Wow, who came up with that idea? And people say Haskell is hard to learn...

Re: New Features in ES2019

#25
post #20

Not ES directly, but you know what I need on an almost daily basis? A JSON date type. It’s obnoxious to have to pass a string back and forth and parse it on either end between server and browser.

I was going to ask a variant of that question: what is the status of BigInt and when might it clear TC39 approval? In most languages a Date object is just a BigInt with Unix time() making this somewhat obvious. BigInt will allow not only proper Date implementation but Currency and Real types, and many more things.

If by BigInt you mean an arbitrary-precision integer type, then AFAIK no major language uses it to represent dates.

If you mean a 64-bit integer type (which, to be fair, is 11 bits larger than what JavaScript supports), then that's still not enough. As long as you want nanosecond-level granularity, and range beyond the current decade for your timestamps, you'll need more than 8 bytes to represent them in code.

Re: New Features in ES2019

#26

Not ES directly, but you know what I need on an almost daily basis? A JSON date type. It’s obnoxious to have to pass a string back and forth and parse it on either end between server and browser.

There's plenty of good reasons one doesn't exist. JSON is not JS-specific. It is a standard interchange format used by thousands of languages, many of which have very different date implementations. If you did have a JSON date, how would you decide what it was? Would it be a timestamp, or a civil date-time? Would it have timezones? Offsets? Locations? Would there be a database along with it required to understand it…

A 'date' type could be as simple as syntax indicating that a particular ISO8601 string IS a date. Right now, there's no reasonable way to infer that unless you're already aware of the schema of the JSON object you're receiving.

You could make the same argument with numbers - there's no reason you couldn't just pass strings containing the number - but there's advantages to being able to distinguish between a string and a number when the schema is unknown.

Re: New Features in ES2019

#27
post #24
post #5

Earlier quoted context omitted.

Another sort() quirk that catches people out is not realising it uses string comparison by default [1,2,10].sort() = [1,10,2]

Wow, who came up with that idea? And people say Haskell is hard to learn...

Weak types.

When neither the function nor the parameters have hard types, you have to create heuristics. There could be a test for numbers there, but it would also be surprising because at the older days people expected "10" and 10 to behave the same.

Re: New Features in ES2019

#28
post #11

Really liking these new developments! JavaScript is not the horrible language it used to be anymore (in my very subjective opinion). When I started writing JavaScript in 2016 after a Python background I was frustrated every day... Then after some time and learning about which dark corners to avoid, which tools to use, etc. it became quite an enjoyable experience. Nowadays I mostly use a mix of JavaScript and TypeScri…

The difference between JS and C++ is that C++ is addressing a complex problem domain whereas JS is addressing a simple one. So JS can put its complexity budget towards features that improve productivity whereas such features in C++ require huge amounts of complexity. Take for instance anonymous functions in JS compared with lambdas since C++11, the C++ version needs a complicated capture syntax, capability for capture by value and reference, type inference, templating, and more. All that complexity is useful and needs to be there (I have used most of it in my own code) - in JS anonymous functions are immensely simpler. That's why JS will never become even 1/2 as complex as C++.

Re: New Features in ES2019

#29
post #5

Earlier quoted context omitted.

Another sort() quirk that catches people out is not realising it uses string comparison by default [1,2,10].sort() = [1,10,2]

It’s the curse of the optional arguments. Same thing with parsing numbers where the second argument magically specifies the base. If the comparison function argument was mandatory in sort() this wouldn’t be a problem.

A different comparison function would not make efficient QuickSort stable.

Re: New Features in ES2019

#30

I wonder what kind of shenanigans you could do with Function.toString(). It'd be even better if they had Function.toAST().

If I remember correctly, AngularJS 1.x would use it for dependency injection.

How so? Were these eval()ed by Angular?

I don't follow what it would use function strings for determining missing - presumably - polyfills that you couldn't do in better ways.

Post reply on HN