r/programmingcirclejerk • u/dreampwnzor Software Craftsman • Dec 30 '17
Retiring Python as a Teaching Language because Javascript
http://prog21.dadgum.com/203.html41
u/Earhacker Code Artisan Dec 30 '17
Python has too many libraries. Let's teach JavaScript instead!
19
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
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
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
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
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.shufflemethod right out of the box either, btw. You'd have to:from random import shuffleNeither 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
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.
8
6
u/enchufadoo not Turing complete Dec 31 '17
def lol_no_gui_libraries(unjerk):
isn't webassambly supposed to solve this? we can all program multiplatform electron games in 2018 using other languages.
9
Dec 31 '17
WebAssembly, like every similar technology before it, is indeed supposed to solve this problem, and doesn't.
This is the Zen of Web Development.
2
u/Tysonzero Jan 02 '18
Can you elaborate on exactly how it doesn't? From what I heard once proper DOM manipulation and GC hooks are implemented it will solve that problem.
2
Jan 02 '18
It doesn't offer DOM manipulation or GC hooks, which are pretty much essentials for doing anything on the web other than mining bitcoins in the background. The graveyard of web technologies from Java to Flash to Silverlight is filled with platforms that could have been game-changing but for one thing, whether it was security and stability or portability or performance, that was officially on the road map but never delivered. Without DOM at the very least WebAssembly is just a toy.
2
u/Tysonzero Jan 02 '18
But WASM is getting both of those things... I think it's extremely premature to write it off as "not solving those problems" considering it's still under development and will absolutely end up win those features.
2
Jan 02 '18
"Getting" implies currently not having. Ergo, not solving the problem it needs to solve. Someday, maybe it will - but that day is not today, and given the pace of development for web standards, I'm not holding my breath.
2
u/Tysonzero Jan 02 '18
I mean sure, at the moment it does not solve that problem. But I took the original comment to be along the lines of "Isn't Frank supposed to solve this", so in other words future tense, treating WASM appropriately as the changing thing that it is. Not to be along the lines of "Isn't dimethylmercury supposed to solve this", in which case your response would make more sense.
4
u/haskell_leghumper in open defiance of the Gopher Values Dec 31 '17
Yes, but it's still in its infancy. I don't think web assembly code can access the DOM without going through JS yet.
2
0
Dec 31 '17
[deleted]
10
3
u/haskell_leghumper in open defiance of the Gopher Values Dec 31 '17
brb doing this from a script tag right now
2
5
0
Dec 30 '17
[deleted]
13
Dec 31 '17 edited Dec 31 '17
Writing games is immediately what every student wants to do, and when the games don't work on mobile it really kills their development libido.
i dunno if this is true necessarily... ive helped instruct coding summer camps and mostly the kids just seemed like they cared about having some kind of graphical result in general.
whether it was on a phone or a PC didn't seem to matter too much at all to them in the first place, and also PC with the obviously higher screen size/resolution let them see their custom-made art better a lot of the time and so was more exciting for them sometimes.
10
Dec 31 '17
Every student wants to write games until they realize what programming games actually entails.
7
u/likes-beans lisp does it better Jan 01 '18
Games and gui apps are the work of the devil. We should have never left shell & ncurses everything.
4
Jan 01 '18
It's more just that writing games is 70% event scripting, 30% linear algebra, and 0% (approximately within experimental error) actually cool stuff. Using ncurses changes that slightly, to 99% event scripting and 1% linear algebra, but it doesn't change the fact that programming games is mostly either boring or frustratingly difficult.
4
6
u/pythonesqueviper Do you do Deep Learning? Dec 31 '17
Well, there is Kivy, but to quote a Belgian friend of mine "Kivy is such a complete kanker Ionic looks like chemotherapy in comparison".
1
Dec 30 '17
when the games don't work on mobile it really kills their development libido.
Yeah, I wonder how people managed to learn programming before smartphones came to be.
0
Dec 30 '17
[deleted]
8
u/thephotoman Dec 31 '17
I mean, you're not wrong. I think about "In 1992, I'd have shit my pants if I'd seen a Nintendo Switch", yet here I am now, owning one and playing Zelda."
5
u/username223 line-oriented programmer Dec 31 '17
Link, has come to town / Come to save / The Princess Zelda. We even had remixes of that shit back in the day.
1
6
u/[deleted] Dec 30 '17
The future is looking bright!