Programming thread

I hate that Javascript is so obviously horrendously broken... yet it's near enough the only option for coding in the browser. If only you could do DOM stuff in wasm.
 
  • Feels
Reactions: 306h4Ge5eJUJ
Whats your guys opinion on using javascript libraries? Im in between beginner and intermediate with html css and javascript so should i just make everything for my site by myself to learn and understand javascript more or should I use libraries to help save myself time?
 
Whats your guys opinion on using javascript libraries? Im in between beginner and intermediate with html css and javascript so should i just make everything for my site by myself to learn and understand javascript more or should I use libraries to help save myself time?
Almost no meaningfully complex apps are developed without using libraries or frameworks these days. It will save you a great deal of time by eliminating repetitive code and working around browser inconsistencies. I propose you learn at least one major javascript framework such as React or Angular (I say at least one as the concepts do transfer reasonably well as you become stronger).

You can also take this opportunity to transition to Typescript. People, even famous developers have negative opinions about Typescript but type-safe languages provably reduce the number of bugs in your code; honestly this is obvious for anyone moving from something like Python to C#.

If you don't already have an idea, I would start with the Create React App tutorial, transitioning to the adding Typescript part as soon as possible.

Of course, you can ignore this advice. If your goal is simply to learn for the enjoyment of learning then I encourage you to do that, but the above advice assumes you have a practical goal in mind, such as developing something complex or getting a job. To achieve this goal, you need a framework.
 
Almost no meaningfully complex apps are developed without using libraries or frameworks these days. It will save you a great deal of time by eliminating repetitive code and working around browser inconsistencies. I propose you learn at least one major javascript framework such as React or Angular (I say at least one as the concepts do transfer reasonably well as you become stronger).

You can also take this opportunity to transition to Typescript. People, even famous developers have negative opinions about Typescript but type-safe languages provably reduce the number of bugs in your code; honestly this is obvious for anyone moving from something like Python to C#.

If you don't already have an idea, I would start with the Create React App tutorial, transitioning to the adding Typescript part as soon as possible.

Of course, you can ignore this advice. If your goal is simply to learn for the enjoyment of learning then I encourage you to do that, but the above advice assumes you have a practical goal in mind, such as developing something complex or getting a job. To achieve this goal, you need a framework.
Thanks for the help man
 
Whats your guys opinion on using javascript libraries? Im in between beginner and intermediate with html css and javascript so should i just make everything for my site by myself to learn and understand javascript more or should I use libraries to help save myself time?
The DOM is all you need. We should have stopped at jQuery, but it's too late now.
 
The DOM is all you need. We should have stopped at jQuery, but it's too late now.
I respectfully disagree but still love you.

Frameworks provide a method of manipulating the DOM which allow you to think of your application in terms of higher order components. They also provide build systems that validate your types, code style, and write repetitive unpleasant code for you, as well as an ecosystem of add-ons, libraries, tutorials and developers you can hire.

"The DOM is all you need" framework does not have any of that; you are on your own. Also, if you intend to do this professionally, it is unlikely any team will take you seriously.
 
Binary is fun! All sorts of innocent little numbers turn out to be infinitely repeating decimals.

View attachment 5354134
Fractions in base-n are infinitely repeating if the denominator has prime factors other than those of n. For binary, octal and hex, your denominator must be a power of 2 or it's infinitely repeating, so that excludes 1/10, 1/5 and 3/10. Decimal allows multiples of powers of 2 and 5. There's an argument that the Babylonians liked base-60 because it meant they got finite decimals for multiples of powers of 2, 3 and 5, though in that case, you wonder why they didn't pick base-30.
 
Whats your guys opinion on using javascript libraries? Im in between beginner and intermediate with html css and javascript so should i just make everything for my site by myself to learn and understand javascript more or should I use libraries to help save myself time?

So every time you ask about js frontend libraries you're going to get a bunch of hot takes from hobbyists who don't code for a living, or jaded backend developers who simultaneously hate js because the most fancy is they used was coffeesscript on their rails monolith app years ago but also think js should stay the same collection of small scripts on each page that they hate using.

The DOM is all you need. We should have stopped at jQuery, but it's too late now.

This is one such example.

The thing is that as your app gets more and more complicated and you start growing a user base, the limiting factor in improving your app is going to be scalability. This applies both in making an app that can support millions of users, and having a codebase that can support multiple teams touching the same files and building new features concurrently. The complexity of your app also increases, which you use js libraries to help handle. This is why just using DOM isn't good enough. Without js libraries, the website we have at my job would not be possible to make. It would have to be hacked together with a bunch of random js scripts and no one would want to work on such a piece of shit. If you were looking for jobs and didn't know react, you could probably only work on maintaining legacy systems.

The js ecosystem is a lot more stable than people make it out to be. React is king and has been for almost a decade. React won't be dethroned for the foreseeable future. Learn modern react.
 
This is one such example.

The thing is that as your app gets more and more complicated and you start growing a user base, the limiting factor in improving your app is going to be scalability. This applies both in making an app that can support millions of users, and having a codebase that can support multiple teams touching the same files and building new features concurrently. The complexity of your app also increases, which you use js libraries to help handle. This is why just using DOM isn't good enough. Without js libraries, the website we have at my job would not be possible to make. It would have to be hacked together with a bunch of random js scripts and no one would want to work on such a piece of shit. If you were looking for jobs and didn't know react, you could probably only work on maintaining legacy systems.

The js ecosystem is a lot more stable than people make it out to be. React is king and has been for almost a decade. React won't be dethroned for the foreseeable future. Learn modern react.
yeah how about I shove my fist up your ass faggot
Without js libraries, the website we have at my job would not be possible to make. It would have to be hacked together with a bunch of random js scripts and no one would want to work on such a piece of shit.
you should be shot
 
sadrefrigerator glow
Can you guys explain to me what react is, what its used for, and why its so widespread within webdev? I see it being discussed a lot and I'm definitely going to learn it I just want to know how will its going to help me with webdev.
 
sadrefrigerator glow
Can you guys explain to me what react is, what its used for, and why its so widespread within webdev? I see it being discussed a lot and I'm definitely going to learn it I just want to know how will its going to help me with webdev.
React is a JavaScript library used by bugmen and Indians because they don't know how to code and we've forgotten how to actually make software that runs on the desktop. React (and most other JavaScript libraries) allow you to build components which are pieces of the UI (or, the DOM) which you can reuse. So the end result for the user is a clusterfuck of webshit glued together which comprises most of the modern Web today.
 
Last edited:
sadrefrigerator glow
Can you guys explain to me what react is, what its used for, and why its so widespread within webdev? I see it being discussed a lot and I'm definitely going to learn it I just want to know how will its going to help me with webdev.
React specifically is a library, not a framework. (Angular and Vue are frameworks). You use React sometimes along with other libraries such as Redux or GraphQL to build your frontend framework (though with the new context api, I haven't needed to use any separate state management). Whereas Angular will include most of the things you need to build out your frontend, such as state management, api fetching, etc, and have an opinionated way of doing things, React is much more barebones and you end up building that stuff, or plugging in the necessary parts yourself. Angular kind of fell off a long time ago because Google is retarded and decided to release breaking versions every half year or such, and it never really largely recovered from that. Vue followed in Angular's footsteps by making Vue 3 a breaking change where almost nothing is compatible. This is why you'll see a lot of modules that have different versions for different versions of Angular and Vue.
I guess a more useful answer for you is that React, and other frameworks allow you to build the frontend as an actual separate project, rather than an extension of the backend. HTML, CSS, JS will always determine what the browser renders, but React is going to create the HTML, CSS, and JS from your app. Before frontend apps, the backend would usually render each page from a template, inserting data as needed into the template to make the final page. JS was limited to making the page do stupid stuff you couldn't do with CSS or HTML, and for doing AJAX stuff that you didn't want to reload the page for. This is why a lot of backend developers who never worked with modern JS hate JS. Everytime you did JS for something like that, it was a buggy unmaintainable mess that always broke.
React allows you to define your frontend as its own project, rather than an extension of the backend. It makes interactivity straight forward and easy to implement. For example, if you wanted to create a list, you could add items to without refreshing, you would need to manually add and remove items from the DOM in addition to all the AJAX queries, keeping track of state, and other stuff to keep your data intact. With react, you would keep your dataset in the state, and render components from your state. React would handle modifying the DOM as needed. All your would need to do is add items to the state, and the browser would represent the state of your list.
Theres too many benefits to list out. Theres a lot of things I wouldn't even think about since its all taken for granted with modern frontend development. Most of the websites today wouldn't be able to be created without frontend frameworks.
 
Fractions in base-n are infinitely repeating if the denominator has prime factors other than those of n. For binary, octal and hex, your denominator must be a power of 2 or it's infinitely repeating, so that excludes 1/10, 1/5 and 3/10. Decimal allows multiples of powers of 2 and 5. There's an argument that the Babylonians liked base-60 because it meant they got finite decimals for multiples of powers of 2, 3 and 5, though in that case, you wonder why they didn't pick base-30.
I don't know about the ancients, but anymore it seems that when people talk about bases other than 10 they don't even consider fractions. (Is there even a proper term for this? "Decimals" implies "deci-" which is base 10. Fractions can have any base, as it's just the denominator. What do we call numbers that engage negative powers of their base system?)

That was more of a thing where they just fixed it with units. Throwing random factors like "3 teaspoons in a tablespoon" or "12 inches in a foot"... wait, where are these factors of 3 coming from? Who cares, if it makes subdividing them easier...

I'm not really going to weigh in on the JS library flamewars, but what I'd say is: learn JavaScript first, and learn to learn libraries. Every library is fundamentally just an extension of JavaScript, but if you know JavaScript and know how to pick up the basics of a library, you're probably better than someone who knows the wrong library and doesn't know the fundamentals. Get a fairly solid grasp of vanilla JS, and then pick one or two libraries to gain a passable competency. But the library itself is just more JS, so even if you're just calling a library function that says it does X, it's nice to at least have a basic understanding of how it can do what it says it does.
 
  • Like
Reactions: Atlictoal
Can you guys explain to me what react is, what its used for, and why its so widespread within webdev? I see it being discussed a lot and I'm definitely going to learn it I just want to know how will its going to help me with webdev.
@sadrefrigerator has already explained this nicely but I'll expand a little and explain why it's different to what I imagine you already know.

You are already familiar with imperative programming: for example, you know how to change the CSS class or style of a button when it is clicked, and you can change the text. However, keeping track of all these state changes can be very hard. For example, consider the number of state changes required in your email client when a new email arrives, when you archive a message, and so on. For example, you might want to change the favicon or some other area of the email client when a new message appears.

React is developed in an imperative programming language, but the design allows you to be declarative about your intention. You simply declare what the user interface should look like given the data you wish to display, and if that has changed, react will issue the imperative commands on your behalf to change only the elements that require changing.

This is why React and libraries like it are popular, because it takes away this state management concern. React specifically is widespread because it was one of the first in this class, and at the time was a refreshing alternative to Angular, which is a bit heavier weight. Libraries like this tend to have a center of gravity in which a developer brings the library to their team, and then that team wants more experts in that library which in turn creates demand for workers, who notice this and skill themselves up, and so on. It's economics, basically.

I underlined imperative and declarative above because they are very important concepts for you to research to build your mental model of programming. In reality, everything you tell a computer to do will be executed in an order as if it were a series of imperative instructions (the CPU doesn't have a clue about anything declarative whatsoever), but higher level libraries allow you to declare your desired result and order those instructions for you which saves time for the developer.
 
Theres a lot of things I wouldn't even think about since its all taken for granted with modern frontend development. Most of the websites today wouldn't be able to be created without frontend frameworks.
You mean to tell me we would have to go back to writing software that runs on a DESKTOP? Save me Durgasoft I'm going insane.
 
How do you guys make changes and try new things with your code without completely breaking it? Basically I want to make multiple versions of the same code so I can experiment on the copies while also having access to previous versions. Sorry if this is vague I dont know how to describe it.
 
How do you guys make changes and try new things with your code without completely breaking it? Basically I want to make multiple versions of the same code so I can experiment on the copies while also having access to previous versions. Sorry if this is vague I dont know how to describe it.
Learn a few commands in Git with this handy free book, learn to check out and merge branches for your experiments, ignore the rest of the book, start putting all your code in repos on Gitlab or a VPS, never cry over spilled code again (probably.) If you already know all this then I may not understand the question
 
Can someone help me with std::function? I have encounter a usage that doesn't match any examples online
Code:
class QUAZIP_EXPORT JlCompress {
public:
    using FilterFunction = std::function<bool(const QString &)>;
FilterFuction gets used as a parameter in a different function:
Code:
    bool mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained,
                                            const JlCompress::FilterFunction filter = nullptr);
mergeZip declaration
Code:
bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained, const JlCompress::FilterFunction filter)
{
...
What does this std::function actually mean?
 
using FilterFunction = std::function<bool(const QString &)>;
This is just the newer syntax for typedefs, i.e. it declares `FilterFunction` to be an alternative name for the type `std::function<bool(const QString &)>`.
Code:
    bool mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained,
                                            const JlCompress::FilterFunction filter = nullptr);
...
What does this std::function actually mean?
It represents a callback that you can pass to `mergeZipFiles`.

The `std::function` template is basically a type-erasing wrapper for an arbitrary function pointer, function object, or lambda that satisfies a specified signature.

For the specific type `std::function<bool(const QString &)>`, the required signature is `bool(const QString &)` - therefore it is a wrapper for any function pointer, function object, or lambda that can be called with a single `const QString &` argument and has the return type `bool`.

By accepting such a construct as its argument, the function `mergeZipFiles` basically tells you: "Give me something that I can call as often as I want with a `QString` argument, and that will return a `bool` value each time.

The fact that the example code names this a "filter function", suggests that it will call this callback once for each item it is processing, each time passing a `QString` to identify the item, and and each time using the callback's `bool` return value to decide whether the item should be filtered out. But you should read the documentation of whatever library that is from, to be sure.

Here's how you'd pass a function pointer or a lambda expression to this parameter, and in both cases the `std::function` wrapper would be implicitly created:
Code:
bool myFilterFunction(const QString& item)
{
    return !item.empty();
}

mergeZipFiles(into, from, contained, &myFilterFunction);
mergeZipFiles(into, from, contained, [](const QString& item){ return !item.empty(); });
 
Last edited:
Back