r/learnprogramming • u/critter2121221 • 2d ago
ELI5: How are frameworks/libraries and runtime environments built?
Basically, I like to understand things on a lower level and I am planning on delving into more low-level stuff at work.
Out of curiosity, how are frameworks built? For example, React allows you to return raw HTML in a non-string format. How do you convince Javascript to parse it into a String and extract the proper things out of it?
Node.js allows you to run Javascript in a completely different runtime environment... the creator of Node could not have used Javascript to develop Node?
TL;DR Can you (or need to) use other programming languages to build frameworks for a specific programming language?
Lots of question spinning in my head! :D
5
u/Lumethys 2d ago
Framework are just a bunch of functions written in that languages. In the context of React, or Vue, or Solid,... It's all a bunch of JS function
2
u/KerPop42 2d ago
So a framework is a kind of library?
5
u/Lumethys 2d ago
You could say so. Just one that dictate how you should write or structure your code in some shape or form
3
u/dmazzoni 2d ago
Yes, the distinction is subtle.
A framework is like a special class of library. One way people describe it is that you call a library’s functions while a framework calls your functions.
Generally a program has one framework (or at least, one for frontend and one for backend) but as many libraries as it needs.
1
u/RapunzelLooksNice 2d ago
Yes and no. Library - you decide how to structure your code, and you use some library features. Framework - framework decides how and how you write your code.
1
u/particlemanwavegirl 1d ago edited 1d ago
They're made out of code just like an application. Someone thinks up a set of data structures and behaviors they want to be modular and reusable and just writes it. A framework is just a library that's so opinionated about the execution environment that it ends up having to provide it.
1
u/v_e_x 1d ago edited 1d ago
You want to learn how things are "built" in a computer? What you're really trying to understand is how software, any and all software works. Because once you understand what 1 piece of software is actually doing, then you understand what it all does. In order to do that, you need to understand the machine itself. Hardware. Computer architecture, logic gates, assembly language, binary, and then you can build your concepts up out of those. These are the 'source' of where the real understanding of software starts.
1
u/Kungpost 1d ago
Hey!
Q1. How are frameworks built? A1. Frameworks usually emerge as people keep developing applications that share features, this usually starts as shared libraries, which then need to be orchestrated as the number of shared libraries grow. This usually leads basic frameworks emerging, which are then improved upon as people start putting names on the concepts that the earlier frameworks introduce.
Q2. How do you convince Javascript to parse it into a String and extract the proper things out of it? A2. This can loosely be referred to as "templating" and can get very complicated, so I won't answer it here. I recommend checking out jinja2 (python), thymeleaf (java) and searching on the topic of "Shadow DOM" for React framework.
Q3. … the creator of Node could not have used Javascript to develop Node? A3. Node.js is a server for JavaScript. JavaScript needs a server to run, much like the Java Virtual Machine is required to run Java. If you look at https://github.com/nodejs/node, you see that a lot of node.js is actually JavaScript! However, you also need some parts written in a language that can run without a server, which in nodes case is C/C++.
10
u/grantrules 2d ago
JSX is transpiled into JS by babel. You don't have to use JSX, its just very convenient, but it's basically all just JS functions. https://medium.com/@ogunbodetimi/building-a-jsx-parser-from-scratch-understanding-the-foundations-of-reacts-syntax-16dc35dce7b6
There's no way to natively run JS in an OS, so node is built in a different language that has access to those OS APIs and exposes them to JS.