Better solution? Use smaller libraries. If you don't need full fledged framework with MVC, ajax, canvas support and whatever else - just go to NPM or Github amd find some small specialized library.
Better solution? Use smaller libraries. If you don't need full fledged framework with MVC, ajax, canvas support and whatever else - just go to NPM or Github amd find some small specialized library.
I also think that choosing small libraries wouldn't help us here, because there will always be some stuff that's not being used. And that's exactly what I'm trying to avoid as best as possible here.
Also, what's wrong with copy-and-pasting code? This changes neither the formatting of the code nor makes it less readable, if you ask me (and I'm of course not talking about indenting with spaces, of course - that's terrible).
1. not readable by other programmers (compare 1 line of code to call library function versus e.g. 15 lines of code snippet).
2. not clear (libraries have usually some API, some clear input and output, some boundaries). So bugs would be introduces easily. And you would lose more time debugging than you would save disk space... and because it would be not clear, that also would be hard to maintain, to modify such code. You would be unable to make quick changes (what if you needed to change something?)
3. When you use libraries you can always compose them, treat one library as filter for another one (for example you can use Physics Engine and connect it to Renderer). If you used only snippets you will practically not be able to make anything more complex than program that outputs Hello World 100 times using 100 different snippets...
4. libraries are usually tested by creators and if you use libraries you don't have to test library code.
But if you used snippets and mix with your own code, you would have to test these snippets also because they would be part of your codebase.
5. not properly encapsulated (unless you convert every single snippet into IIFE and inject variables to it as arguments)
All above would be obvious... And I don't believe that I have to write this down. One can argue if libraries are better than frameworks or vice versa. Or if OOP is better than FP or vice versa. Or if MVC is good or harmful. etc. But arguing that copy pasted code is better than properly separated reusable sets of functions and objects...? What year is this? 1950? ;)
Firstly, I was mostly talking about languages like JavaScript that are running directly within the browser. When it comes to Back-end-techniques I don't see the necessity for this type of improvement, especially since most languages there are compiling before a request even comes in (or include some neat ways to cache the output).
To be clear: I haven't thought about using this "Snippet"-technique for software running on your mac/pc, it's thought for the web. I don't care about disc space or anything like that, in this post, I was just thinking of a new way to limit the size of the data packages that are downloaded from the server, each first time someone visits a site. And this "first hit" is really important to me and to many other developers out there. It's the first time a website or -app is actually downloading to a visitors client. Therefore I'm pretty focused on making it a good experience for the user.
I'm also thankful for that "compare 1 line of code to call library function versus e.g. 15 lines of code snippet" argument, I completely agree with you there. But when I say "snippets", I'm actually talking mainly about JS-functions (for example) that can be called on a specific DOM-Element, Object, String or whatever.
You can also take a look at the comments on my site, I posted a comment about "dynamic frameworks", maybe that will be a proper solution for the future. But as I already said, as long as this is not real yet, the "Snippet"-technique is probably the best way to achieve fast web-applications, in my opinion.
Sorry for not stating everything clear enough, again. I will make sure to do better in the future. :)
"The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming. " Donald Knuth