Tag Info

Hot answers tagged

41

I did this, and I recommend that you don't. What I did was write all the business logic in Lua, and stored that Lua script in a database. When my application started up it would load and execute the script. That way I could update the business logic of my application without distributing a new binary. I invariably found that I always needed to update the ...


32

Piping dynamic data into an interpreter of your implementation language is usually a bad idea, since it escalates the potential for data corruption into a potential for malicious application takeover. In other words, you are going out of your way to create a code injection vulnerability. Your problem can be better solved by a rules engine or maybe a ...


20

Modern JavaScript engines all do just-in-time compilation. You can't make any presumptions about what it "must create over and over again." That sort of calculation is relatively easy to optimize out, in either case. On the other hand, closing over constant variables is not a typical case you would target JIT compilation for. You typically create a ...


12

Variables are cheap. Execution contexts and scope chains are expensive. There are various answers that essentially boil down to "because closures", and those are essentially true, but the problem isn't specifically with the closure, it's the fact that you have a function referencing variables in a different scope. You'd have the same problem if these were ...


12

In the early days of Netscape, there was a new technology that was all the rage. Java. This wasn't the Java that we know and love (for some definition of 'love') today, but rather Java Applets. Java applets had a serious flaw though - they couldn't interact with the page that enclosed them. This severly limited their utility. And so, the makers of the ...


8

For starters, v8 predates (public knowledge of) TypeScript by several years, TypeScript isn't from Google, Google isn't invested in it, TypeScript is far from an industry standard, and Google has its own language trying to fill a similar niche (Dart). And then there's the problem that nobody deploys TypeScript to websites, it's designed to be compiled to ...


6

In ECMAScript 5, yield is a strict-mode "Future Reserved Word": 7.6.1.2 Future Reserved Words The following words are used as keywords in proposed extensions and are therefore reserved to allow for the possibility of future adoption of those extensions. ... class enum extends super const export import The following tokens are also ...


5

Javascript ressembles a Scheme like language, with a different syntax, a weird prototype semantics, and ugly rules (like for evaluation of {} + [] etc...). It was probably (for economical and social reasons) under-specified and under-designed. Later, the common implementation (inside browsers) became a de facto standard and inspired the more official ...


4

webSocket is implemented in browsers (not in the underlying OS). It is built on top of TCP/IP which comes from the OS. You can see which versions of which browsers support webSockets here:http://caniuse.com/#feat=websockets


4

The question is actually two questions rolled into one: Why a scripting language? Of all scripting languages, why javascript? Why a scripting language? The major idea behind the use of scripting languages is this: Applications often need customization, and some times the level of customization offered by options and styles is not enough. By including ...


4

For a few reasons: It often forces you to choose longer names, where a shorter one would be more clear and concise within a limited scope. For example, filter versus MyModuleNameFilter. The process of "taking the responsibility to make sure you have very good names and they will never overlap" gets increasingly difficult the larger your code base gets ...


4

You cannot write only one function. You will still need to have a separate function for each event handler, so the best you can do is to have 3 functions whose total amount of code will be less than what you currently have because it will not contain duplicated code. It will not perform faster, but it will be smaller. So, what you need to do is to extract ...


3

I would say it depends of the language. In a strongly typed language like Java, pasing a Map<String, Object> means that you risk using the wrong type for a parameter. That said, I have seen this been used in frameworks like ExtJS and, for some tasks that require lots of parameters (like initialization, configuration) it is worth it. It actually helps, ...


3

Because global variables have global scope, they are visible, and mutable, by anything that runs on the page. That introduces implicit coupling between all code running on the page; everything could interact with everything. That runs contrary to the concept of encapsulation. If your code, and variables are local in scope, it's easier to reason about thing; ...


2

I disagree, the main goal of ES6 is not to introduced new ways "to accomplish the same thing" but actually cover some areas that were not covered at all. Generators are extremely helpful for the class of tasks where you should iterate through a big list of items but you don't need to keep all this items in memory at one time. This is something that just was ...


2

Absolutely! For several reasons: Promises provide an excellent error checking system. You can return a promise and let the caller deal with the promise however he or she wishes (or not at all). Many would argue that promises make your code cleaner and easier to read, which is no small thing. I would argue that promises are worth using if for no other ...


2

I would think of it as a graph: Creating a topological sorting would give you a valid order to process the nodes in. Note there can be multiple topological sorts. Whether you need to worry about that depends on if you need one solution or all the solutions. In this case, there is only one topological sort: c, b, a. You start with c, add it to the ...


2

You're almost certainly overthinking this. Your quest for an ideal data structure is a solution in search of a problem. Look carefully at the example you gave. All three of those dropdowns have a different data source, and they imply a relational structure. Just by looking at the names of your dropdowns, I know that you have three tables: Groups, Events ...


2

Why reinvent the wheel? Try ELO rating system - it was developed for exactly this purpose, and is best known for being used to rate chess players, although not exclusively. And it stood the test of time, to be sure. As for calculating the probability that player (or team) A defeats B, look under ...


2

This is JavaScript. Your server's not involved that much. If the embedding is done in pure JavaScript without calls you your server, then the video should go straight to the User's browser.


2

One example involves a closure, the other does not. Implementing closures is kinda tricky, since closed over variables do not work like normal variables. This is more obvious in a low-level language like C, but I'll use JavaScript to illustrate this. A closure does not only consist of a function, but also of all variables it closed over. When we want to ...


2

V8 and other language implementations using similar techniques are just-in-time compilers. They generate code, and that generated code is speculatively optimized (with checks to fall back to slower, more general code if the specialization turns out to be invalid). So when generating code, the JIT compiler often has a good guess at what the hidden class of an ...


2

I would not have the database contain code. But you can do something similar by having the database contain function names and then using reflection to call them. When you add a new condition, you have to add it to your code and your database, but you can combine conditions and parameters that get passed to them to create quite complex evaluations. In ...


2

This question mainly stems from worrying about maintenance so I will make an assumption that you are going to have many of these state-dependent functions. I would recommend having a layer in between your client and the function that it is calling which is state dependent. Then let this layer handle the state management. This will do two things for you: ...


1

"I will take the responsibility to make sure...". Many unexpected babies arrive that way. But seriously: keeping names unique with a growing code base that may include other libraries is a difficult and risky process that is ultimately doomed to failure. your very own code will start to get really hard to read and follow when you set and read these ...


1

"Never put variables in global scope" is a best practice because it makes those variables brittle. A typical web page or especially a typical web application is likely to contain many different scripts from multiple sources, and as careful as you may be to track your own global variables, everyone else whose scripts you're referencing may not be playing ...


1

The key is that this is being used in a JIT which produces specialized code. Let's say that have a function something like this: function add_points(a, b) { return new Point(a.x + b.x, a.y + b.y); } V8 will actually generate different versions of this function, for different possible arguments that you pass in. For example, it would generate a version ...


1

I agree, it's just too complicated. I think the root of this problem is that async programming is inherently difficult. In the past, async code was mostly found in specialist, high-performance areas (kernels, servers, etc.) while typical code was multi-threaded. This has changed somewhat in recent years. The ideal solution would be for browser JavaScript to ...


1

ECMAScript ist the single most compatibility-constrained language that ever existed. In general, developers can't choose the version of the implementation (or even which implementation) that is going to be used to run their code, because it is installed on the users' machine. Users can't choose the version of the app they run, because the code gets ...



Only top voted, non community-wiki answers of a minimum length are eligible