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

Show parent comments

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.