2102: "Internet Archive"

This forum is for the individual discussion thread that goes with each new comic.

Moderators: Moderators General, Prelates, Magistrates

User avatar
SDK
Posts: 703
Joined: Thu May 22, 2014 7:40 pm UTC
Location: Canada

2102: "Internet Archive"

Postby SDK » Wed Jan 23, 2019 8:53 pm UTC

Image
Title text: The fact that things like the npm left-pad incident are so rare is oddly reassuring.


At least my body takes care of itself. Don't have to rely on finicky humans to continue caring about those tasks.

User avatar
rhomboidal
Posts: 796
Joined: Wed Jun 15, 2011 5:25 pm UTC
Contact:

Re: 2102: "Internet Archive"

Postby rhomboidal » Wed Jan 23, 2019 9:04 pm UTC

I'm still trying to figure out what my brain does.

User avatar
Soupspoon
You have done something you shouldn't. Or are about to.
Posts: 4060
Joined: Thu Jan 28, 2016 7:00 pm UTC
Location: 53-1

Re: 2102: "Internet Archive"

Postby Soupspoon » Wed Jan 23, 2019 9:07 pm UTC

It tries (and fails) to figure out what your brain does.

User avatar
Jorpho
Posts: 6276
Joined: Wed Dec 12, 2007 5:31 am UTC
Location: Canada

Re: 2102: "Internet Archive"

Postby Jorpho » Wed Jan 23, 2019 9:12 pm UTC

I was completely oblivious to this NPM left-pad thing. Sounds exciting!
https://www.theregister.co.uk/2016/03/2 ... pad_chaos/

Koçulu yanked his source code because, we're told, one of the modules was called Kik and that apparently attracted the attention of lawyers representing the instant-messaging app of the same name. [...] Unfortunately, one of those dependencies was left-pad. The code is below. It pads out the lefthand-side of strings with zeroes or spaces. And thousands of projects including Node and Babel relied on it.


Strange, that such a simple piece of code wouldn't be a component of the base libraries or something.

User avatar
Pfhorrest
Posts: 5380
Joined: Fri Oct 30, 2009 6:11 am UTC
Contact:

Re: 2102: "Internet Archive"

Postby Pfhorrest » Wed Jan 23, 2019 9:46 pm UTC

Having a body has been freaking me out lately, though the prospects of not having a body (like, being an uploaded mind in a virtual computer world or something) is if anything even more disconcerting. Since a serious illness last month I've been full of awful existential dread about how fragile existence is and how it can't really help but be that way. Like, I've known about all these frailties my whole life, but they never really sank in on an emotional level before, how so much of what I consider normalcy really just rests on fragile systems that could easily go away and there's basically shit I can do about any of it. It used to feel like, you know, my body is self-healing and time will fix any damage to it, and the rest of the world outside of me is so huge and full of inertia that I really don't have to worry about things I depend on going away, but now it's just like... I happen to be here for now, and that might change at any second, and thinking about that only makes this brief chance existence less enjoyable, so I wish I could go back to just kinda knowing that shit abstractly in the back of my head, like it's a fact about some far away world I've studied, and not feeling like I'm actually a part of that awful world that couldn't possibly be much better in this kind of existential way.
Forrest Cameranesi, Geek of All Trades
"I am Sam. Sam I am. I do not like trolls, flames, or spam."
The Codex Quaerendae (my philosophy) - The Chronicles of Quelouva (my fiction)

kdb
Posts: 14
Joined: Thu Aug 16, 2018 8:40 am UTC

Re: 2102: "Internet Archive"

Postby kdb » Wed Jan 23, 2019 11:42 pm UTC

I told a younger colleague about leftward just today XD

Incidentally, Kik also also the name of a cheap clothing chain.
“Computers: a way to take three hours to do a three minute job in three seconds.” – ucim, 2019

sotanaht
Posts: 235
Joined: Sat Nov 27, 2010 2:14 am UTC

Re: 2102: "Internet Archive"

Postby sotanaht » Thu Jan 24, 2019 12:10 am UTC

Jorpho wrote:I was completely oblivious to this NPM left-pad thing. Sounds exciting!
https://www.theregister.co.uk/2016/03/2 ... pad_chaos/

Koçulu yanked his source code because, we're told, one of the modules was called Kik and that apparently attracted the attention of lawyers representing the instant-messaging app of the same name. [...] Unfortunately, one of those dependencies was left-pad. The code is below. It pads out the lefthand-side of strings with zeroes or spaces. And thousands of projects including Node and Babel relied on it.


Strange, that such a simple piece of code wouldn't be a component of the base libraries or something.

I was just reading the same thing. Short version is author gets copywrite trolled, has one of his projects removed because corporate at NPM doesn't give a fuck, decides to leave NPM and take everything with him, and then NPM steals one of his projects because their users need it. Why NPM didn't then get sued out of existence I don't understand.

User avatar
jc
Posts: 352
Joined: Fri May 04, 2007 5:48 pm UTC
Location: Waltham, Massachusetts, USA, Earth, Solar System, Milky Way Galaxy
Contact:

Re: 2102: "Internet Archive"

Postby jc » Thu Jan 24, 2019 12:21 am UTC

Jorpho wrote:I was completely oblivious to this NPM left-pad thing. Sounds exciting!
https://www.theregister.co.uk/2016/03/2 ... pad_chaos/
...
Strange, that such a simple piece of code wouldn't be a component of the base libraries or something.


And it's disappointing that they just restored it, without fixing the its inefficiency. To pad the string with n spaces means building n new strings, each containing a copy of the previous string. Even a minimally competent coder should be able to do better than that.

Of course, I could be wrong. I haven't written any javascript in years, so for all I know, that might be the best it can do. But I'd be really embarrassed if something that dumb looking were found in any of my code. ;-)

(I wonder if the JS interpreter knows how to optimize such things.)

User avatar
Archgeek
Posts: 260
Joined: Wed May 02, 2007 6:00 am UTC
Location: Central US
Contact:

Re: 2102: "Internet Archive"

Postby Archgeek » Thu Jan 24, 2019 1:35 am UTC

jc wrote:
Jorpho wrote:I was completely oblivious to this NPM left-pad thing. Sounds exciting!
https://www.theregister.co.uk/2016/03/2 ... pad_chaos/
...
Strange, that such a simple piece of code wouldn't be a component of the base libraries or something.


And it's disappointing that they just restored it, without fixing the its inefficiency. To pad the string with n spaces means building n new strings, each containing a copy of the previous string. Even a minimally competent coder should be able to do better than that.

Of course, I could be wrong. I haven't written any javascript in years, so for all I know, that might be the best it can do. But I'd be really embarrassed if something that dumb looking were found in any of my code. ;-)

(I wonder if the JS interpreter knows how to optimize such things.)

That does look a mite silly. I'd probably just do

Code: Select all

var pad = '';
while (++i < len) {
  pad += ch;
}
str = pad + str;


Though I too wonder if JS does something dippy enough under the hood that that only looks better.
"That big tube down the side was officially called a "systems tunnel", which is aerospace contractor speak for "big tube down the side."

User avatar
Uristqwerty
Posts: 27
Joined: Mon Nov 14, 2011 5:11 am UTC
Location: Canada

Re: 2102: "Internet Archive"

Postby Uristqwerty » Thu Jan 24, 2019 2:14 am UTC

If performance really mattered, for large enough N, you'd want something like

Code: Select all

let acc = ' ';
let pad = '';
while(n > 0) {
    if(n & 1)
      pad += acc;
    n >>= 1;
    acc += acc;
}


But that's still an inefficient high-level workaround, and what you'd really want to do is tell the underlying platform to allocate a large enough string, and fill it with spaces using a single highly-optimized memset.

Cruxador
Posts: 1
Joined: Thu Jan 24, 2019 7:45 am UTC

Re: 2102: "Internet Archive"

Postby Cruxador » Thu Jan 24, 2019 7:48 am UTC

sotanaht wrote:
Jorpho wrote:I was completely oblivious to this NPM left-pad thing. Sounds exciting!
https://www.theregister.co.uk/2016/03/2 ... pad_chaos/

Koçulu yanked his source code because, we're told, one of the modules was called Kik and that apparently attracted the attention of lawyers representing the instant-messaging app of the same name. [...] Unfortunately, one of those dependencies was left-pad. The code is below. It pads out the lefthand-side of strings with zeroes or spaces. And thousands of projects including Node and Babel relied on it.


Strange, that such a simple piece of code wouldn't be a component of the base libraries or something.

I was just reading the same thing. Short version is author gets copywrite trolled, has one of his projects removed because corporate at NPM doesn't give a fuck, decides to leave NPM and take everything with him, and then NPM steals one of his projects because their users need it. Why NPM didn't then get sued out of existence I don't understand.

Because the owner of left-pad chose not to sue. There may have been a usage agreement that meant he was unlikely to win, or he may have just not felt it worth his trouble.

cheweytoo
Posts: 13
Joined: Wed Jan 22, 2014 9:38 am UTC

Re: 2102: "Internet Archive"

Postby cheweytoo » Thu Jan 24, 2019 9:17 am UTC

Holy cow.

Identical functionality, taking (minimal!) advantage of language features:

Code: Select all

function leftpad (str, len, ch) {
  if (!ch && ch !== 0) ch = ' ';
  return ch.repeat(len - String(str).length) + str
}

Admittedly, String.prototype.repeat is new-ish.

(The cast to string at the end is implicit: string + int = string)

User avatar
orthogon
Posts: 3059
Joined: Thu May 17, 2012 7:52 am UTC
Location: The Airy 1830 ellipsoid

Re: 2102: "Internet Archive"

Postby orthogon » Thu Jan 24, 2019 11:50 am UTC

When I first learned about the "+" string operator in Sinclair BASIC, I thought that the other operators ought to exist, too. In particular you should be able to say

Code: Select all

LET x$= "foo"*4
to get "foofoofoofoo".

Pseudo-edit: Ruby has exactly this, but I thought of it a couple of decades earlier!
xtifr wrote:... and orthogon merely sounds undecided.

User avatar
cellocgw
Posts: 2044
Joined: Sat Jun 21, 2008 7:40 pm UTC

Re: 2102: "Internet Archive"

Postby cellocgw » Thu Jan 24, 2019 12:10 pm UTC

SDK wrote:At least my body takes care of itself. Don't have to rely on finicky humans to continue caring about those tasks.


With humor:
The whole intent of cloud servers and distributed error-checking and so on is to have the whole series of tubes repair itself.

Without humor:
Your body is at great risk of failing to succeed at taking care of itself. Consider:
1) Measles
2) toxic substances in non-FDA-approved "supplements"
3) Cancer
4) tigers
https://app.box.com/witthoftresume
Former OTTer
Vote cellocgw for President 2020. #ScienceintheWhiteHouse http://cellocgw.wordpress.com
"The Planck length is 3.81779e-33 picas." -- keithl
" Earth weighs almost exactly π milliJupiters" -- what-if #146, note 7

User avatar
ucim
Posts: 6819
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: 2102: "Internet Archive"

Postby ucim » Thu Jan 24, 2019 2:22 pm UTC

I notice velociraptors are not on the list. That is comforting. Maybe the Great Lord Randall is wrong after all. :)
Spoiler:
Forgive my heresy!
Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Heartfelt thanks from addams and from me - you really made a difference.

User avatar
Soupspoon
You have done something you shouldn't. Or are about to.
Posts: 4060
Joined: Thu Jan 28, 2016 7:00 pm UTC
Location: 53-1

Re: 2102: "Internet Archive"

Postby Soupspoon » Thu Jan 24, 2019 3:05 pm UTC

orthogon wrote:When I first learned about the "+" string operator in Sinclair BASIC, I thought that the other operators ought to exist, too. In particular you should be able to say

Code: Select all

LET x$= "foo"*4
to get "foofoofoofoo".

Pseudo-edit: Ruby has exactly this, but I thought of it a couple of decades earlier!

https://perldoc.perl.org/perlop.html#Multiplicative-Operators (the "x" operator)

(Pre-existing Ruby, I presume, unless Ruby is older than I assume. Not pre-existing the Sinclair in that form. Inspiration may still have already been around, but you're getting into the era before such 'shortcuts'.)

So, perlwise you could do something like:

Code: Select all

length($_)<$reqLen&&$_=($reqLen-length($_))x$padCh.$_;

Perhaps, with suitable context - this version doesn't bother with non-undersized versions due to short-circuiting straight past and ignores oversized as part of that. And I'd have to test it to make sure I've remembered the precedences enough to get away with just the one set of non-parameter parens. Though I'd probably consider a substr-based operation upon the $string as an internal lvalue by using the suitable replacement feature over position 0, length 0. Which could also be done singly within a while-length-less-than-required-length loop or equivalent repeating block. TIMTOWTDI, some more readable, some more efficient, many very much neither. I'd have to benchmark a few options to find the most efficient method.


The thing that trips me up most when switching code-bases is string concatenation.
Is it String=String1+String2 or String=String1&String2 or String=String1.String2 or String=String1;String2 or are you forced to use the inbuilt String=StrCat(String1,String2) - assuming I have the = right and it's not := or needs a LET or is superfluous to context? The number of times I've introduced an error by forgetting which peculiarity the current language family or dialect I'm working with uses when inserting something as simple as a debug-line.

User avatar
YellowYeti
Posts: 59
Joined: Fri Jul 27, 2012 6:05 am UTC

Re: 2102: "Internet Archive"

Postby YellowYeti » Thu Jan 24, 2019 3:26 pm UTC

The thing that trips me up most when switching code-bases is string concatenation.
Is it String=String1+String2 or String=String1&String2 or String=String1.String2 or String=String1;String2 or are you forced to use the inbuilt String=StrCat(String1,String2) - assuming I have the = right and it's not := or needs a LET or is superfluous to context? The number of times I've introduced an error by forgetting which peculiarity the current language family or dialect I'm working with uses when inserting something as simple as a debug-line.


This always gets me as well - then you realise half your program is written using one form, and half in another form. Neither of which are actually for the language you intended to write.

Why can't they just have a standard way to do it?

https://xkcd.com/927/

jpers36
Posts: 231
Joined: Wed Apr 14, 2010 2:47 pm UTC
Location: The 3-manifold described by Red and Blue

Re: 2102: "Internet Archive"

Postby jpers36 » Thu Jan 24, 2019 8:56 pm UTC

Plagiarizing myself from the arXiv thread:

I still have no idea how archive.org works legally, but I use it for films and books pretty regularly. I'm in the middle of Village of the Damned, the one from 1960 I just watched The Truman Show yesterday. I usually watch in 30 minute increments on the stationary bike.


Return to “Individual XKCD Comic Threads”

Who is online

Users browsing this forum: No registered users and 47 guests