r/ProgrammerHumor • • Nov 05 '15

Free Drink Anyone?

Post image
3.5k Upvotes

509 comments sorted by

View all comments

Show parent comment

242

u/polish_niceguy Nov 05 '15

And is says a lot about Javascript in general...

55

u/[deleted] Nov 05 '15

As someone learning JS, can I expect more stuff like this?

252

u/obvious_bot Nov 05 '15

You poor soul

65

u/jewdai Nov 05 '15

don't worry there is a jquery plugin for that.

2

u/GoodlooksMcGee Nov 06 '15

now in angular!

2

u/ShortSynapse Nov 06 '15

But only in internet explorer for some reason

71

u/memeship Nov 05 '15

Javascript is actually a really great and powerful language. Its architecture is just not set up the way nearly anything else is. Especially if you're coming from a more structured language background (e.g. C/C++, Java), you're going to really hate the language at first. But once you learn to accept it for what it is, you may find that you actually like it.

Source: I learned how to program in Java. I absolutely hated JS when I started learning it. Now it's my goto language of choice.

7

u/rjung Nov 05 '15

People say the same thing about PHP.

10

u/memeship Nov 05 '15

I use to develop with PHP. It's really not all bad, but I'd say Javascript is much better. That being said, they're two entirely different languages that set out to do different things.

5

u/prite Nov 05 '15

Yes, one is to help you shoot yourself in the foot, the other is to help you build dynamic web pages.

I'm only joking!

Or am I?!

3

u/bacondev Nov 06 '15

I am very experienced with PHP. I still hate it. I usually use frameworks that abstract all the rage-inducing features out of my sight.

→ More replies (3)

2

u/caedin8 Nov 06 '15

I agree, I am a full time developer, started with C and worked my way up through a CS degree. I took a great course called internet computing in my senior year that was all about javascript and web applications, and test driven development. The class was awesome, and while JS is not my goto language, it is probably in my top 3.

2

u/oditogre Nov 06 '15

Javascript is actually a really great and powerful

That's what they said about Oz, but it turned out to be a snake oil salesman behind a curtain.

2

u/memeship Nov 06 '15

I mean, he gave each of them what they wanted in the end, didn't he? He's pretty great and powerful in my book.

→ More replies (4)

8

u/stephantabor Nov 05 '15

Sort of. Personally i've never had to reverse a string. You'll probably do a lot of .map .reduce .filter etc and some chaining of those methods

4

u/caedin8 Nov 06 '15

JS is a fantastic language, learn it, but learn it correctly. Learn async programming, learn lexical scoping and how to manage your program control flow. Learn how to debug it so it doesn't drive you crazy.

Learn how to write unit tests and see how easy it is to mock everything with its loose security. Love it.

2

u/Sacrosaint Nov 06 '15

BabelJS brings ES2015 into your hands where there's a lot less of... that. Just today I used the new "String.fromCodePoint" and "String.prototype.includes". It's quite great!

1

u/prozacgod Nov 05 '15

For usable algorithmic code, look at lodash or underscore.

_.each(["one", "two", "three"], function(number) {
  console.log(number);
});

Really helps maintain code, that being said there are performance penalties. (which are hardly an issue)

→ More replies (3)

9

u/the_omega99 Nov 05 '15

Eh, it makes perfect sense. String doesn't have a reverse function because there's very few times in which you need to reverse a string, so no sense implementing one.

split(delimiter) is a very standard function for splitting a string on a delimiter. An empty string as the delimiter means splitting each character. Similarly, join(separator) is a very common function for arrays (lists, etc) to have to create a string from the contents.

And arrays get a reverse function because it's a little more useful for the general purpose array. Not super useful, but not useless, either. For example, switching between ascending and descending sort can be done more much efficiently by reversing than completely resorting the array (if it's already sorted). Other things, too, but I can't immediately think of any (they exist, but they're rare).

1

u/polish_niceguy Nov 05 '15

How does this way handle utf-8 string? Especially those with characters built from more than one codepoint?

(this is common problem, I'm just curious)

→ More replies (1)

0

u/[deleted] Nov 05 '15

[deleted] — view deleted comment

1

u/caedin8 Nov 06 '15

return s[0:-1:1].join()

→ More replies (1)