r/programmingcirclejerk • Software Craftsman • Dec 30 '17

Retiring Python as a Teaching Language because Javascript

http://prog21.dadgum.com/203.html
39 Upvotes

46 comments sorted by

View all comments

41

u/Earhacker Code Artisan Dec 30 '17

Python has too many libraries. Let's teach JavaScript instead!

19

u/[deleted] Dec 30 '17 edited Dec 31 '17

lol I wonder how many fewer "libraries" JS would have if there was some kind of minimum length they needed to be in order to get accepted by the package repository, instead of the situation that apparently exists now where there's no distinction at all between large multi-file frameworks and things that are really just a couple of functions, or not even a couple.

24

u/Earhacker Code Artisan Dec 30 '17
const unjerk = require("unjerk");

That makes sense in JavaScript, though. I don't want my users to have to download the entire Lodash library just so I can shuffle an array painlessly. I should only have to require the minimum code necessary for that functionality.

In Python, who cares how big a library is? My users are probably only going to download and install my app once, and not every time they open it. I can import basically whatever I like.

12

u/[deleted] Dec 30 '17 edited Dec 31 '17

I guess that kind of makes sense. I suppose I'm just used to languages where smartlinking exists (and more broadly linking of any kind, obviously), haha.

Although I'd still say people should try to avoid unnecessary imports/includes/usings/e.t.c in any language where possible. I'm never going to buy that the sort of entirely trivial nature yet insanely overestimated importance and status of something like "leftPad" is a perfectly reasonable phenomenon.

That said, if I were actually a JS programmer/someone who regularly had to import a single-function not-library for something as simple as what leftPad does, I'd definitely be asking more and more questions as time went on about why JavaScript doesn't have at least a nominal standardized collection of string handling methods.

Also more specifically/less seriously, in my experience padding the left side of a string with anything is not even something most developers would ever need to do that much at all (although it's normally no big deal... in Pascal at least I can just call either PadLeft or PadRight directly through the strings themselves by default) so it seems strange/funny that leftPad is even that regularly useful for JS devs?

Is there some specific reason you need to pad stuff especially often while making web-things?

12

u/Earhacker Code Artisan Dec 31 '17

You don't need to pad strings especially often on the web. No more often than you do in your Pascal apps.

But it's not that exciting a problem to solve. You might write it out once and get a little kick out of passing some tests in under 10 minutes, but then the fun's over.

Then months later, you're on another project and need to left pad a string. Do you just go back to your old project and copy-paste? No you don't, because you're a shit hot programmer who remembers OO principles like abstraction and encapsulation, so you wrap up your old left-pad function and its tests and put it in an Node package, so that you can share functionality across two unrelated projects. And that's totally valid, that's even a good use case for packages.

Then later some rock star Front-end ninja who can't code for shit has to Google "how to add spaces to the start of a string" and finds your package on NPM. He installs it, calls your function, and orders himself a latte on his Starbucks app to celebrate another card moved from 'Doing' to 'Done' on the Trello board. Such agile. Much 10x. Wow.

Later the product the 10x'er is working on also gets uploaded to NPM. And later still it gets used by the guys at Babel, who really do know what they're doing, and need to use this product because it solves some problem they're having. They don't even care about the string padding thing, that's only used on the product's CLI output, which they aren't going to use anyway. But they npm install the product and that installs your old left-pad package as a dependency because that's how NPM works. And Babel do write a really awesome product that nearly everyone uses. So now your little left-pad package is getting millions of downloads a day.

That's how it snowballs. But your solution is absolutely right, there should be some string library made up of dozens of functions like pad-left, and JS devs should be smart enough to only require in the functions they need from that library. But that's putting a lot of faith in JavaScript developers, and there so many shit JavaScript developers out there.

7

u/[deleted] Jan 01 '18 edited Jan 01 '18

No you don't, because you're a shit hot programmer who remembers OO principles like abstraction and encapsulation, so you wrap up your old left-pad function and its tests and put it in an Node package, so that you can share functionality across two unrelated projects. And that's totally valid, that's even a good use case for packages.

This is where I would tend to disagree in general, though. IMO the attitude/mindset that a single function is ever worthy of its own entire listing in any purpose-built online package repo for any language should be strongly discouraged in all cases. That you'd ever end up with people who don't/didn't see uploading things like that in that particular context as ridiculous in the first place is indicative of a larger issue, I'd say.

To be clear, I'm not suggesting people should be discouraged from uploading code in general. There's absolutely nothing wrong with uploading anything you want to your personal GitHub/BitBucket/whatever page at any time, no matter how small.

5

u/[deleted] Dec 31 '17 edited Dec 31 '17

You seem reluctant to write a one liner but you're sure willing to write a wall of text. Of course left padding isn't an exciting problem to solve, it's not even a problem to solve in the first place. TL;DR:

String.prototype.leftPad = function(pad_char, len) { return pad_char.repeat(Math.max(len - this.length, 0)) + this; };

11

u/[deleted] Dec 31 '17

JS needs a significantly more fleshed-out standard lib.

3

u/Earhacker Code Artisan Dec 31 '17

Most devs who use Lodash would describe it as JavaScript's missing standard library.

Python doesn't have a list.shuffle method right out of the box either, btw. You'd have to:

from random import shuffle

Neither does Java:

import static java.util.Collections.shuffle;

Only language I personally know of with a built-in, always available method for this is Ruby's Array#shuffle. And thank fuck not every language has a stdlib like Ruby.

17

u/Scriptorius lisp does it better Dec 31 '17

You're confusing standard libs with builtin/core functions. A standard library includes any functions/classes/libraries that comes bundled with the language. Just because you have to explicitly import it into the current namespace doesn't mean it's not part of the standard lib.

Python's random and Java's Collections aren't random 3rd party modules, they're worked on by the language's own maintainers. Lodash, on the other hand, is maintained by completely different people from the ones who work on the various Javascript runtimes. That's why you have to download it as a separate dependency (using npm or webpack or whatever) before you can require it in.

12

u/tehtris Dec 31 '17

Random comes with python though... so if a uaer has python they have random.

1

u/spaghettiCodeArtisan blub programmer Jan 03 '18

That makes sense in JavaScript, though. I don't want my users to have to download the entire Lodash library just so I can shuffle an array painlessly. I should only have to require the minimum code necessary for that functionality.

IMO this problem should not be solved on a module system level though. Basically this is a consequence of the crappy way JS is "built", ie. there is no proper compilation and linking process, just a bunch of more or less crappy workarounds that emulate such process.