News for hackers. Stuff that matters.
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by ekke on Wednesday May 09, 2018 @06:40AM (#17028805)
This is HN after all - some version of ES/JS:

  class Eel {
      valueOf () { 
          return 'https://imgflip.com/meme/Bad-Joke-Eel';
      }
  }

  const craftCapacity = 331,
        hovercraft = Array.from(Array(craftCapacity), () => new Eel);
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by Klathmon on Wednesday May 09, 2018 @08:15AM (#17029201)
It's "My hovercraft is full of eels", not "My hovercraft has an arbitrary amount of eels in it"!

Now looking at the ES5 spec [0], the max length of an array is an unsigned 32-bit integer due to the `ToUint32` operation that the spec defines. So that means our `craftCapacity` here needs to be 2^32-1

Sadly we can't use `Number.MAX_SAFE_INTEGER` here because that assumes double-precision floating points as the underlying storage method, so we just have to hardcode our value:

  const hovercraft = Array(4294967295).map(() => 'https://imgflip.com/meme/Bad-Joke-Eel')
[0] While the spec says this in a roundabout way, i'm not sure if any implementations actually adhere to this limit, and i'd guess most convert the array to a hashtable internally long before it gets to that size.
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by bebe3000 on Wednesday May 09, 2018 @09:03AM (#17029429)
ekke assumed the hovercraft can hold at most 331 eels. You assumed it holds 4 billion eels. Who's right? I don't know but a billion eels sounds far off.
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by Klathmon on Wednesday May 09, 2018 @09:21AM (#17029548)
If an array is the hovercraft, it can hold 4 billion "things" regardless of what those things are! So you need to fill that up to meet the requirements of the saying.
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by simsla on Wednesday May 09, 2018 @09:43AM (#17029707)
And if a hovercraft is an array of size 331, then it should hold 331 eels.
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by peeters on Wednesday May 09, 2018 @10:58AM (#17030318)
Ah but now we're at the crux of the issue; in Javascript, hovercrafts grow in size to accommodate as many eels as you put in, but to a maximum of ~4 billion. So "full" is not a question you can ask of your hovercraft, though it will tell you once it's overflowing.
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by Klathmon on Wednesday May 09, 2018 @11:51AM (#17030779)
Now there's a thought!

What if we used a storage method that didn't grow?

In JavaScript we have typed arrays, we could use a `Uint16Array` to store UTF-16 code points as integers in each element, then we could define the amount of eels that our "hovercraft" could store ahead of time in a way that it won't expand.

  const hovercraftEelCapacity = 331 // We can define our hovercraft to have room for 331 eels
  const eel = 'eel'
  const hovercraft = new Uint16Array(new ArrayBuffer(2 * eel.length * hovercraftEelCapacity)) // Each "eel" takes up 3 16-bit integers

  for (let i = 0; i < hovercraftEelCapacity * eel.length; i += eel.length) {
    hovercraft[i] = eel.codePointAt(0)
    hovercraft[i+1] = eel.codePointAt(1)
    hovercraft[i+2] = eel.codePointAt(2)
  }

  console.log('Your hovercraft full of eels: ', hovercraft)
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by JasonFruit on Wednesday May 09, 2018 @11:13AM (#17030437)
While we're nitpicking, unless you have partial eels, it's arbitrary number, not amount. That calls to mind measuring blended eel, of which I don't want to make a career.
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by Klathmon on Wednesday May 09, 2018 @11:32AM (#17030588)
Well to be fair the saying doesn't specify the state of the eels.

It could be liquefied remains of eels! Although I'm guessing we would need to study a few of the translations in languages that explicitly differentiate between "a collection of whole somethings" and "an amount of something". Although now that I'm thinking about it in english saying "my hovercraft is full of eel" would imply that it's an amount of eel, not a distinct number of eels.

Still, if it were the "amount", a simpler JS expression would convey the message:

  const amountOfEelsInHovercraft = Number.MAX_VALUE
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by Angostura on Wednesday May 09, 2018 @12:47PM (#17031368)
If they were blended, the phrase would be “my hovercraft is full of eel”
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by JasonFruit on Wednesday May 09, 2018 @03:48PM (#17033296)
My phrase would be, "This is your hovercraft."
Re:‘My Hovercraft Is Full of Eels’ in Many Languages by flyingcircus3 on Wednesday May 09, 2018 @12:30PM (#17031207)
Whoa, whoa. Did you just assume the transitive property of sound pressure fluctuating languages with voltage fluctuating languages? You should check your access privilege.

Let me guess, I bet you think people can transmit information via the fluctuation of electromagnetic waves too. Brilliant!