News for hackers. Stuff that matters.
Re:Ask HN: Is web programming a series of hacks on hacks? by roblabla on Monday September 12, 2016 @01:50AM (#12477470)
Errm...

- "test".indexOf("st") == "test".length - "st".length

- "test".enddWith("st")

Am I the only one who thinks the second one is WAAAY more readable? And that's a COMMON function. Using the former is bringing complexity UP.

Not to mention, endsWith is part of es2016 I believe. So this package is just a simple polyfill.

Re:Ask HN: Is web programming a series of hacks on hacks? by EnigmaticLion on Monday September 12, 2016 @02:15AM (#12477575)
> "test".indexOf("st") == "test".length - "st".length

I don't think this is a correct implementation of "endsWith".

"testtest".indexOf("st") =/= "testtest".length - "st".length

Re:Ask HN: Is web programming a series of hacks on hacks? by roblabla on Monday September 12, 2016 @02:52AM (#12477706)
Good point. Should have been

"test".substr("test".length - "st".length) === "st"

Or is it substring? Might there be an off by one in there? Anyway, this kind of reflexion only proves my point. There's no reason to question what endsWith does, because it's obvious. It's the correct abstraction in many cases.

Re:Ask HN: Is web programming a series of hacks on hacks? by pablovidal85 on Monday September 12, 2016 @04:30AM (#12478046)
Negative substr() already does the trick, I don't see the need for endsWith() at all.

  'test'.substr(-'st'.length) === 'st'
Re:Ask HN: Is web programming a series of hacks on hacks? by roblabla on Monday September 12, 2016 @04:43AM (#12478095)
The thing is :

1. You need to know and understand obscure behavior of substr

2. This hides the programmer's true intent. What you want is to know if the string ends with 'st', not that "the 'st'.length last characters of the string is 'st'". Why make it harder on your fellow coworkers to understand what you mean ?

If you only do this once, sure, maybe importing a whole module is overkill. But as you write it over and over again, in separate projects, having the code safely tucked away in a reusable module brings complexity down.

Re:Ask HN: Is web programming a series of hacks on hacks? by bartl on Monday September 12, 2016 @04:46AM (#12478106)
You can even do

    'test'.match(/st$/)
I don't see why people insist on doing all the low level shit themselves, and then still complain about "scalability" and "fitness for programming on the enterprise level".
Re:Ask HN: Is web programming a series of hacks on hacks? by dbkaplun on Monday September 12, 2016 @01:55PM (#12481992)
- "test".match(/st$/)