lainchan / λ

Javascript: how does it work?

Pulse · 2020-05-04 05:43
What is the deal with javascript? Try as I might I just can't enjoy programming in it. I think my main stumbling block is all the various build tools and the library ecosystem in general. Any recommendations on how to hate javascript less?
queue · 2020-05-04 05:56
The task before us, fellow lains, is all but impossible. Nigh! It is impossible. Look, for this man says "look, this nightmare fuel is nightmarish what with its many arms, smoten with warts and sores, oozing disease and pestilence. Hark, for the libraries spell out certain means of escape, but it is for naught - their soykafty packaging, distribution, and inclusion maketh their allegiance weak and unreliable. There be no fellowship with fellow code, for all are impossible to read. Delighted by the ravages of this sickly sight, one must ask the other to turn back with them, and never go back. Some defy their friend and comrade, stepping back into the inky black shadows of the javascript realm. He who doesn't leave is doomed to eternal damnation upon the alter of the prototype, and have their soul wrenched from their mortal coil, torn apart over and over before reconstitution. Though he will call the well-defined interface, it shall except repeatedly and spill the contents of its belly upon the stack. Though he knowth the extent of his recursion, he shall not know its terminating condition. As though the light of the hdd access shall flicker, the data will flow uninterrupted. Heed these words, dear lainon, for there is light away from this darkness that you need only follow.
push · 2020-05-04 06:06
>>18251 I mean sure, program in a better language, but until I get a `<script type="text/python"></script>` tag I don't have a lot of options for anything running in the browser.
Ishikura "Tatsu" Tatsuhiko · 2020-05-04 06:07
>>18252 transpilers, if you must develop for such a disgusting piece of soykaf platform.
Donna Hawthorne · 2020-05-04 11:17
>>18249 After writing some amount of javascript, here's my take at it: - the language has some nice features, but many things are poorly designed, especially the standard library. - functional constructs (map, forEach) along with object construction/deconstruction (Object.entries/Object.fromEntries) give a nice programming experience, even though there a bit too much of boilerplate involved (especially compared with python comprehension) All in all, forget everything about objects, write mainly pure functional, and the language gets comfortable enough, even though some thinks are still cumbersome (what, are you trying to compare lists ? sorry, I don't know about that)
DEBUG-CONTENTS · 2020-05-04 18:17
>>18252 Python would have an application/python type, but I doubt that's ever gonna happen. Isn't python's startup time worse than javascript's startup time?
Netrunner · 2020-05-04 19:19
> I think my main stumbling block is all the various build tools and the library ecosystem in general. Well, I'd say it's what makes Javascript bearable. A Webpack setting that transpile from ES6, minimize you code automatically, and a ESLinter with strict setting are things I couldn't do without anymore to program in Javascript. It's a pain to set up but it's totally worth it. Typescript is a nice superset but from my late noob experience it's even more tedious to set up and I got fed up before making it work for Vue and understanding "ambient types" well enough to solve some type problems I had with the backend. Writing interface/types really helped me to debug and reason about the data the program manipulated, but at some point it felt more like a hindrance than something totally reliable. So if you go down this road, check if the framework you use (if any) goes well with Typescript. As lainon said, functional programming is doable with Javascript, although I don't know yet how far it goes beyond currying, recursion the common construct like map, etc., and there is transpilers around : https://kotlinlang.org/docs/reference/js-overview.html
Pulse · 2020-05-04 20:48
>>18265 I mean throw enough money at it and I'm sure it would be fine. The joke there is that you can get `text/python` scripts if you use brython, but no one does that because performance is extra bad and it adds a lot of overhead. Transcrypt actually seems pretty reasonable all things considered.
BloodCat · 2020-05-05 21:01
>>18267 >As lainon said, functional programming is doable with Javascript, although I don't know yet how far it goes beyond currying, recursion the common construct like map Other than that, a good part of efficient functional programming is about writing (mostly) pure functions, with well defined (and "simple") input/output type. This make it simpler to reason about the program and it's behaviour. A bit like using typescript, but without the syntax overhead.
Nguoi La · 2020-05-05 23:03
>Any recommendations on how to hate javascript less? I do not use it, and do not hate it. There is a corollary here
Erik Johansson · 2020-05-05 23:29
In order to program in javascript you have to give up completely on the idea of writing good correct code. That's the secret. Sure, keep writing code that looks good, but just ignore the fact that underneath that facade is a fundamentally fuarrrked up mess, and don't try to account for all the edge cases. Yes, use floating point numbers to index into arrays. Use unchecked, unparsed JSON dicts for everything. Give up. Channel your hate for JS into hate for your employer and users, and then spite your employer and users by writing JS for them. It's what they want. Worse is better. There's no other way.
Lukasiewicz · 2020-05-06 00:49
>>18288 this took me so long to wrap my head around because javascript's syntax makes it look like you're supposed to write C#/java style OO code. doing purely functional with long ugly chained method calls is definitely the way to go. the other thing that always fuarrrks me up is how the asynchronous soykaf works. i still don't get it at all, but at least now i know that there is an inverse relationship between how good a bit of js code looks and how good it actually is. >inb4 webassembly saves us from this hell while simultaneously knocking us back to 2010-era levels of browser-exploitability.
J.C. Denton · 2020-05-10 23:32
modern JS is based (even tho its better to not use newest features if you dont want to waste time with configuring transpiller. For example {...dict, k:v} is just Object.assign(dict, {k:v}) with much less hassle) Here is Redux in just 100 lines of code https://gist.github.com/gaearon/ffd88b0e4f00b22c3159
Lady 3Jane.. · 2020-05-20 20:24
>>18252 >what is cgi
cdr · 2020-05-21 06:05
>>18249 Use a language that emits JS, and do not write it directly.
sage · 2020-05-24 03:43
>>18682 Common Gateway Interface (CGI) is a protocol for running *on the server* arbitrary programs.
byte · 2020-05-25 22:57
>>18774 >>18682 In 1993 the National Center for Supercomputing Applications (NCSA) team wrote the specification for calling command line executables https://en.wikipedia.org/wiki/Common_Gateway_Interface
Jens Hansen · 2020-05-27 23:41
HTML and CSS were, for the most part, easy to grasp and remember. I am, however, perplexed by just how difficult it is for me to remember what all I'm reading regarding JavaScript. I have been using https://www.w3schools.com/ to learn all I know about web development. Aside from remembering what I'm reading regarding the subject matter, I struggle to just stay focused on this. I really struggle to just sit down and force myself to read up on this stuff. Eventually, after a while, I'll wander off to Lainchan, 8kun, or xchan, and after that I lose any progress I've made from researching JS. Really, I guess my problem is just a short attention span and impatience of learning. How do you guys force yourself to just sit down and focus on this stuff.
string · 2020-05-28 01:54
Sitting down and doing stuff is a skill, you have to learn to do things you don't want to do. That's literally the only benefit of capitalism, you have to do it or you end up homeless. So you either learn to suffer through it, until you suffer less, or you create a situation where you feel like failure is hugely negative, homelessness. Or wasting money, if you paid for a course.
Torvalds · 2020-05-28 02:07
That's just how it is. In my case sitting and reading through a technical document is really tedious for me. Having to read pages of how things are implememted, however informative in the long run, is simply no fun. That's why I usually don't and also why I don't do much programming anymore. But I do other things I enjoy and have to go through the same process. Of course what drives me is my motivation as to what I hope to do with the knowledge I acquire. In your case it might be much better to actually read a beginner's book that has projects and showcases usage, and also pushes some less-relevant details for later explanation. Put the language in perspective and whatnot. Good thing about js is there are many books out there for different goals. Game programming, enterprise webapps, whatever ypou're trying to achieve is probably covered by some book so you don't have to look for that stuff in the sea of frameworks and whatnot. Best of luck, drink water, have a bowl of raisins on your desk, and turn off the internet connection for an hour (be sure to have your resources cached/downloaded beforehand)
Vasya Pupkin · 2020-05-28 10:04
> just how difficult it is for me to remember Chop. Mix. Stew. > I'll wander off Close the world out a couple hours. Pack, shut the door and pull the plug.
Case · 2020-05-28 12:30
What helps for me is having lengthy music without lyrics playing. The typical "lofi hiphop beats for study/chill" or soundtracks of puzzle video games can work well. For learning programming languages specifically, I think it's important to have an interactive environment next to the documentation so that you can try out and experiment with the stuff you're reading about, really helps to keep it all tangible. For javascript you can just press ctrl+shift+k in Firefox to get an interactive js console.
not op · 2020-05-28 14:32
>>18852 I have tried that approach recently but with other subjects, I'm not sure it would work when you're absorbing a language's features and need to constantly try stuff on an IDE or even search something online.
Aiweiwei · 2020-05-29 02:29
>>18849 Are you trying to learn how to use javascript? If so, i'd suggest you just start using it, and look up whatever you need if you don't remember the details. You will naturally remember things after you've used them a few times.
Boris Grishenko · 2020-05-30 15:08
>>18849 Just go to javascriptbook(dot)com and go through everything. Get the book itself through Libgen and you'll be good to go. Try making a few simple games, like connect 4 or tic-tac-toe. That will be the foundation for understanding how the language works from a Vanilla point of view. Then start looking into things like the client-server model, n-tier architecture, server hosting (LAMP stack is old but good for beginners to get a feel for how everything should work), domain names, etc. After you've gone through all that and you've made something that you're proud of, visually and technically start using popular JS frameworks, like: Angular, React, D3JS, and just in general research everything you're interested in. All in all web development boils down to a number of things: getting/sending data, manipulating data, and displaying data. That's it! A good place to see what your roadmap as a developer should be is at roadmap(dot)sh. You can see what is expected of developers to know for their career, be it frontend, backend, devops, etc. It takes a bit to get the hang of it, but I'm sure you'll pull through. Good luck!
Just another Random Lainon · 2020-05-30 19:07
>>18911 not him but where i get stuck is the conceptual jump from writing basic tutorial-style javascript to actually writing javascript how it is used in production. Real javascript code looks totally alien to me: everything's wrapped in callback functions and asynchronous stuff and it's not at all clear to my why certain decisions are being made, unlike say C where if I see something weird I can usually think about it for a moment and go "yeah, I guess I can see why that would be faster/more maintainable/better coding style/etc." That's not even getting into how much production javascript depends on intimate knowledge of various frameworks that are constantly changing. Your advice re: learning how web applications work in total is good, but in my case I already know how a LAMP stack works. I've used DBs and CGI and even have a pretty deep knowledge of networking concepts in general. I just for some reason can't get my head around production javascript (I know a lot of it is actually compiled from typescript and whatnot, but that's not what I'm talking about.)
Tequila · 2020-07-13 13:46
>>18911 > (LAMP stack is old but good for beginners to get a feel for how everything should work) Is PHP tend to be replaced at the top of the stack or is the model still valid for a beginner point of vue ?
quote · 2020-10-28 09:56
>>18249 Is not as bad. I find PHP way worst and boring to code. Perhaps it would help to (at first) code as vanilla as posible, so you'll get to appreciate (and understand better) the tools when you need them.
H.R. Giger · 2020-10-28 10:00
>>18849 I had this problem too with my first languages. What helped a lot was to make a small text-based RPG battle, with HP points, attacks, skills and stuff when I started learning JS. Doing fun small projects really helps, and later when you read more about the language you'll go "oh, I could have used this and it would have made everything easier."
Meddler · 2020-10-28 12:36
>>21689 One of my favourite test projects when I'm learning a new language is a scientific calculator. Parsing user complex input in a new language is always a quick way to learn some intricacies.
Zuse · 2020-10-28 13:55
>>21691 Good idea. Plus some graphical user interface and it could get you started quickly. Thanks
Shogun · 2020-10-29 04:36
>>19557 >Is PHP tend to be replaced at the top of the stack or is the model still valid for a beginner point of vue ? I've often felt that after VPSs of various flavours became really cheap and easy to set up, PHP's one big advantage (server-side processing on shared web hosting) became unimportant.
McCarthy · 2020-10-29 17:52
>>19557 I personally recommend you use something else. PHP's only real strengths are that it's easy to set up and plays nice with HTML. Outside of that it's a pretty crap language.
Liet Kynes · 2020-10-31 13:55
Javascript and it's consequences have been a disaster for the human race >Any recommendations on how to hate javascript less? You can't
Demeere · 2020-10-31 21:29
>>21743 Javascript is an alright language. Most of the issues come from the environment it primarily works in, which is web browsers.
Marly Krushkhova · 2020-11-01 16:03
>>18267 setting up environments is the hardest thing about programming. is it even possible to do webdev without using vscode?
McCarthy · 2020-11-01 20:59
>>21751 yes. i done webdev in vim
Stallman · 2020-11-02 04:54
>Any recommendations on how to hate javascript less? Stay as far away from it as possible---soon, you'll forget all about it: a vague memory disdain.
Vasya Pupkin · 2020-11-02 09:01
>>21751 Why do you need a browser to write HTML?
progn · 2020-11-02 17:09
>>21751 I learned to do webdev in notepad back when I used windows. You most definitely don't need an IDE for it.
Hiro Protagonist · 2020-11-02 17:33
>>21777 back in the day you could just view source to see how everything was built. bit harder to do that these days since everything's more obfuscated and optimized.
Sabo Engle · 2020-11-02 17:38
>>21779 >bit harder to do that these days since everything's more obfuscated and optimized. The really sad thing is that often the obfuscation is just the result of the code being rushed into production with no time to tidy it, rather than a deliberate attempt at obfuscation.
Nobody special · 2020-11-04 00:06
>>18249 Well javascript has lambdas. Those are cool. So basically you can define a function like this: javascript foo = (arg) => arg And a consequence of this is that you can create functions on the fly, say for example, when you're calling a function: javascript // bar takes a function as an argument and passes that function the argument `3` bar = (foo) => foo(3) // passing the identity function to `bar` bar( (arg) => arg ) This actually comes in handy greatly when you're doing asynchronous UI stuff, because just like lisp you can use lambdas to "freeze" evaluation and delay until all your data is ready to process. Example: javascript // create file input button in DOM var input = document.createElement('input'); input.type = 'file'; // We give addEventListener an event and a function. // The function will be executed at a later time when the event happens instead of right now. Pretty cool. input.addEventListener('change', () => { // create an empty record object with properties we want to pull from the file input let record = {lastModified : null, path : null, name : null, size : null}; let file = input.files[0] for (let prop in record) { record[prop] = file[prop] } // imagine we've implemented store as some kind of database call that puts the record in a database store(record) }) // now whenever our file button is clicked on, the selected file will be input into the database by running the function we passed earlier // we can also trigger this programmatically for the same effect input.click() There's other stuff that javascript does too. It's pretty okay I think.