Live data from Hacker News

Temporal: The 9-year journey to fix time in JavaScript

bloomberg.github.io

21–30 of 284 posts

Re: Temporal: The 9-year journey to fix time in JavaScript

#21

[flagged]

The worst are methods that both mutate and return values. I know this gets into a complex land of computer science that I don’t understand well, but I wish I could define in TypeScript “any object passed into this function is now typed _never_. You’ve destroyed it and can’t use it after this.” Because I sometimes want to mutate something in a function and return it for convenience and performance reasons, but I want…

ruby has the convention of ! for dangerous destructive or mutating methods. This is something that I wish would spread around a bit.

For example:

# Original array

array = [1, 2, 3]

# Using map (non-destructive)

new_array = array.map { |x| x * 2 }

# new_array is [2, 4, 6]

# array is still [1, 2, 3] (unchanged)

# Using map! (destructive)

array.map! { |x| x * 2 }

# array is now [2, 4, 6] (modified in-place)

Re: Temporal: The 9-year journey to fix time in JavaScript

#24

Earlier quoted context omitted.

The worst are methods that both mutate and return values. I know this gets into a complex land of computer science that I don’t understand well, but I wish I could define in TypeScript “any object passed into this function is now typed _never_. You’ve destroyed it and can’t use it after this.” Because I sometimes want to mutate something in a function and return it for convenience and performance reasons, but I want…

ruby has the convention of ! for dangerous destructive or mutating methods. This is something that I wish would spread around a bit. For example: # Original array array = [1, 2, 3] # Using map (non-destructive) new_array = array.map { |x| x * 2 } # new_array is [2, 4, 6] # array is still [1, 2, 3] (unchanged) # Using map! (destructive) array.map! { |x| x * 2 } # array is now [2, 4, 6] (modified in-place)

> convention

Is the keyword. Anything that should never be broken isn’t a convention. There’s no better convention than compiler error.

Re: Temporal: The 9-year journey to fix time in JavaScript

#26

[flagged]

The worst are methods that both mutate and return values. I know this gets into a complex land of computer science that I don’t understand well, but I wish I could define in TypeScript “any object passed into this function is now typed _never_. You’ve destroyed it and can’t use it after this.” Because I sometimes want to mutate something in a function and return it for convenience and performance reasons, but I want…

What you are describing is linear (or affine) types in academic parlance, where a value must be used exactly (or at most) once, e.g., being passed to a function or having a method invoked, after which the old value is destroyed and not accessible. Most common examples are prolly move semantics in C++ and Rust.

Re: Temporal: The 9-year journey to fix time in JavaScript

#27

[flagged]

The worst are methods that both mutate and return values. I know this gets into a complex land of computer science that I don’t understand well, but I wish I could define in TypeScript “any object passed into this function is now typed _never_. You’ve destroyed it and can’t use it after this.” Because I sometimes want to mutate something in a function and return it for convenience and performance reasons, but I want…

Rust ownership model ("stacked borrows" I believe it's called) is basically this

Re: Temporal: The 9-year journey to fix time in JavaScript

#28

Aside: Bloomberg JS blog? ok.

Bloomberg has a pretty large software engineering department, including a lot of offshore contractors. Similar to Walmart Labs that does cool stuff as well, despite being part of a retail chain (retail industry typically sees SWEs a cost, not asset).

Re: Temporal: The 9-year journey to fix time in JavaScript

#29

Aside: Bloomberg JS blog? ok.

What surprises you? Terminal UI is written in JS using Chromium. It’s not just plain Chromium, but it’s still funny that it’s pretty much same approach as universally (according to HN and Reddit) hated Electron.

https://youtu.be/uqehwCWKVVw?is=wBijGwdD2k2jIOu7

Post reply on HN