I've been studying and thinking on this, still not getting past my current opinion. I can't see how libraries aren't bad as compared to writing a ton of modules.
Server-side, it doesn't matter so much, but client-side, it's a big deal to me.
noms suggested that if you want to use lodash for something, then using a cdn is the solution for the bulk that comes with it
So, if I write a useful client-side function, or just some function that's great for either server/client, and I use lodash, then I'm forcing myself and anyone else to get it from a cdn at best
and that still comes along with that whole script having to be executed
and at worst, also downloaded if it isn't available from a previous site
This issue makes me never want to touch client-side again.
The way I've started to think about code, due to James Halliday (substack) mainly, I have a lot of trouble considering using a library, rather than thinking in terms of how to solve a problem.
npm install thing-that-solves-this-problem
done
That thing should pull in whatever dependencies it needs and that should be the end of it. If they're already in the project, even better.
But, who wants to use a solution that forces them to include an entire library, and who would write a solution that includes an entire library for one function from it?
and if you then solve the problem by just writing that function right in the script with the solution, then you're setting yourself up to write that function over and over everytime you need it again.
And that throws DRY,modularity,reusability,abstraction right out the window.
There is no difference between a module and a library. A library is simply a set of functionality; so it is a modular component. Something being a library doesn’t mean that it’s a super complicated and huge thing with lots of features.
Just because there are some libraries that want to do everything in a slightly different less-vanilla way, that doesn’t mean that this defines the term “library”.
Just saying that you shouldn’t rage against “libraries”, and that there are indeed libraries that do exactly what you want, i.e. solve just a very specific problem.
Nobody forces you to use those huge bundled do-it-all things, so if you don’t like them, don’t use them, and instead choose those tools that actually help you get work done.
var wrap = require('lodash-wrap'); <-- solve my problem with no drawback
var _ = require('lodash'); <-- solve my problem by losing performance all around
@poke I still don't see how what you're saying applies to what I'm saying. What you're saying would mean I should fork lodash and modularize it ;D
If you can see some individual parts being useful without having to depend on the rest, then sure, just pick those what you need. And if it’s a good selection—or just very modular—then make it available to others.
Well, people are lazy and don’t care about performance. That’s why the average JavaScript question always contains an answer (or a comment) like “Why don’t use use jQuery?”
No, those huge libraries are a great thing—for sites that completely build on them. If you have a huge interactive site, yes, jQuery is probably very useful. But it’s not the right tool for everything you can do in JavaScript. So choose the right tool, the right big-ass library—or none—for the right situation.
Like, I don't get it, a lot of people write node only modules and do _.map(_.filter(_.map(arr, fn), fn2), fn3) and not arr.map(fn).filter(fn2).map(fn3)
@BenjaminGruenbaum to me, it's not about "most" things. It's about not having a lingering function in a script that doesn't really relate. It's something reusable and should be it's own thing.
In this case, I have my own wrap function that does the same thing as lodash.wrap
var oldFoo = foo;
foo = function(){
// code that runs before foo
var val = oldFoo.apply(this, arguments); // change arguments etc
// code that runs after
return val; // or some processing of
};
@BenjaminGruenbaum Probably varies from person to person; I find _.pluck and _.find to be pretty invaluable; _.invoke can be a nice time saver, _.mapValues has its usages; stuff like _.any, _.every, _.some help make conditionals more readable...
@poke they're not encouraged but I like them - I generally think that functional syntax when appropriate is better than query syntax - and you see that mostly in C# that has both syntaxes.
(Both python like comprehensions and JS like .map.reduce.etc
@BenjaminGruenbaum I definitely don't think it obfuscates the intent; you can pretty much read left to right as an english sentence: "filter collection by id 'foo'"
And it works without having to name another variable.
@Retsam That shorthand syntax is very limited though. What if you want to filter on even bar values? You will need a separate filter function; so you have a second, different syntax for another filter query.
Then I’d rather want a library to give me a equalityPredicate function which gives me a function that I can then use with the JS filter? E.g. collection.filter(equalityPredicate('id', 'foo'))
In some cases "scripting language" is meant as "interpreted language", but generally it's a perjorative term used by people arguing for "real" languages, I find.
@BenjaminGruenbaum Don't some languages require compilation at a language level due to their features? My view was that "interpreted languages" could be compiled, but not generally the other way around.
so.. dogescript would be a programming language because it compiles to js, but js is a scripting language because... it doesn't compile, it's just interpreted...
@Retsam what do you mean? Take a look at Java for example - it can run natively (on Java machines), it can run interpreted (like it did initially), it can be JIT compiled (like on the desktop) or it can be compiled ahead of time (like on Android 5) - none of that has much to do with Java.
@Retsam I think Benjamin’s point is that every compiler is also an interpreter, and what compiler produces is some other sort of code that’s then interpreted by something else. That doesn’t directly affect the language you are writing though.
@BenjaminGruenbaum How can we write the command: printf("%d->%d", X, Y); in ALGOL where X and Y are the arguments of the recursive function. Do we have to write something like: write "X -> Y"; ?
@CSᵠ Scripting languages and compiled languages don’t have an order; so one language being interpreted has no advantage nor disadvantage over a language being compiled. That’s why one can be compiled into another that is going to be interpreted. And that’s usually what happens with every language. At some point, the machine interprets and runs machine code.
And as Benjamin made clear, scripting or compiled is not necessarily a property of the language.
Well, those terms are just hard to define. Just like strong or weak typing. Everybody uses it to define their language, but rarely one can give a clear definition.
It probably makes sense to not keep calling twttr.ready for whatever single task you have to do. Depending on what twttr even is (xD), it might make sense to just wrap all twttr-related stuff into a single function that’s then passed to twttr.ready.
– twttr is really the name of the official Twitter library? Wow, that’s bad.
I mean, if all I'm doing is creating a single button or creating several things in the same code block, it would all be inside of one twttr.ready, but I haven't thought about all that.
The Twitter widget library exposes a global variable twttr. I'd like to modularize this library on the fly using webpack with exports-loader. The problem is that, while the twttr variable is immediately exposed, it's properties are still undefined when accessing it synchronously.
console.log(twt...
@Benjamin I was actually about to ask you about promises. I haven’t caught up with the ES6 development of it, and since you seem to know them very well, I would be interested to hear if there’s anything new. And I would like a recommendation for a lightwight polyfill (I still use es6-promise for node). I would appreciate if we could talk about it tomorrow :)
You've effectively done the OP's homework for them, and thus deprived them of the opportunity to learn something. Not only that, by answering, you've helped further encouraged horrible "gimme teh codez" and other "lack of effort"-type questions. Answering these questions is strongly discouraged, and it is far better to flag, and/or leave a comment asking the op to provide further information. — Paul Richter1 min ago
the page crashes Error: Failed to lookup view "error" in views directory "C:\nodejs\nodetest\views" at Function.app.render (C:\nodejs\nodetest\node_modules\express\lib\application.js:492:17) at ServerResponse.res.render (C:\nodejs\nodetest\node_modules\express\lib\response.js:802:7) at Layer.module.exports [as handle] (C:\nodejs\nodetest\app.js:63:9) at trim_prefix (C:\nodejs\nodetest\node_modules\express\lib\router\index.js:235:17) at C:\nodejs\nodetest\node_modules\express\lib\router\index.js:208:9 at Function.proto.process_params
In a browser, if I have setTimeout(a, 1000); setTimeout(b, 2000); is it guaranteed that a is called before b is called? I'm working with some crappy code that uses timeouts where it shouldn't and I want to know if I can depend on this.
I should probably write better sentences - I feel my English has deteriorated. Makes sense since I don't read as often and when I do it's usually technical.
@BenjaminGruenbaum I like reading too, but when I go on a book-binge, 16h of nonstop audiobook is much easier on my organism than 16h or reading black letters on stark white background
I read "And the Mountains Echoed" last week and I had a hard time following it (I was very sleepy in my defense) - if I get confused on such an easy book I definitely need to read more. I should probably pick up something by Dickens, I love that dude.
I have created an application in full-calendar, the application is working fine but the problem is that under the week view i have two events for today (Nov 9 - 15, 2014)- Meeting 1 and Meeting 2, both are within the boundary levels which you can see a light green event. The problem which i am fa...
@SecondRikudo it's just a language - whatever would take an hour or two in php or C# or Java would take about as much in Scala as much as this challenge is concerned.