Tag Info

New answers tagged

4

No reason why not... people embed Lua in C++ engines all the time, and sometimes JS engines. This enables them to run script-based code (eg for games, levels can be described in script). However, it does raise a large level of additional complexity that may not be needed if all you want to do is parse JSON. For that get a JSON library for C instead (Spirit ...


1

I'm not sure if many template syntaxes have a specific name. A lot of template syntaxes are unique, but there are frameworks out there that use similar templating syntaxes without actually calling them anything. Mostly, they are referred to by the name of the engine. For example, both Twig (a templating engine that can be used with the Symfony Framework for ...


1

You can have as many models as you need to meet the many goals that a successful application has to address. One concept that might help here is the Single Responsibility Principle. Basically, you ask the question, "what would cause this data structure to change?" In your case, changing the details of the quiz structure would be a prime source for change. ...


1

I think you are misunderstanding the MVC pattern a bit. One of the purposes of MVC pattern is to divide your application into "layers". The Model-layer which contains "data" The View-layer which represents the "data" (the Model) The Controller-layer which handles user input and modifies "data" (the Model) The Model does not tell the View how ...


1

You want to have a single class that knows about your FooName current display settings. Your Views should decide to show or not the FooName based on visibility settings provided by your class. When you build your pages, pass the current true/false visibility state of your FooName(produced by that class) into viewBag, Everywhere where you have your FooName ...


0

Those two functions are scheduled to be run at the same time, but will actually never run at the same time in a single-threaded environment. They will run in sequence. But while they are running the browser rendering is blocked and any effect that they do will happen at the same time when they both finish. It makes sense for the timestamp to be the same ...


5

If you don't use cookies at all then it would be a huge misinformation to warn your visitors about using cookies. It may even be useful to explicitly state that you don't use cookies. Remember that those warnings are for people who are afraid of cookies so they should know when they finally get to a rare website that don't use them. But you may still need to ...


1

There are some reasons why I prefer using Maps over plain objects ({}) for storing runtime data (caches, etc): The .size property let me know how much entries exist in this Map; The various utility methods - .clear(), .forEach(), etc; They provide me iterators by default! Every other case, like passing function arguments, storing configurations and etc, ...


1

Be careful, because const is not immutable. From here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const object attributes are not protected consider this example: const colors = {red: "#f00"}; console.log(colors); // { "red": "#f00" } colors.red = "#00f"; colors.green = "#0f0"; console.log(colors); // { "red": ...


3

If putting the functions chronologically improves the readability of the code, it means that you are using functions wrong. The primary purpose of dividing the code to function is to reduce the amount of context you need to hold in your mind at any given time. (functions have other usages when you use recursion or higher-order functions, but that's clearly ...


0

How to find this: Open the website in Chrome. Hit F12, select the Elements tab. Hover over the HTML until only the buttons were covered. This will take you to id="calloutLinks" Search for calloutLinks. In the Document ready function, you will locate a function called rotateSwitch


1

bind() doesn't actually do currying. What it does is partial application. lodash and rambda have a method called _.partial() that does partial application without setting the context object. A function f is curried if calling f with one or more arguments is equivalent to calling f with one argument, then calling the return value with the next argument, and ...


2

This is kind of an opinion question - but I would say yes, keep them separate. While keeping them together may be less complex in the short run, in the long run, separate repositories make scalability, updates, bug fixes, and extensibility much easier. In terms of scalability: if you decide to host the frontend in multiple places, you can simply build and ...


2

configuration object or config object are the terms often used to describe this construct. It allows to rearrange the parameters in any order, because the properties of the generic object have no ordering. And you don't need a long list of optional parameters.


2

I need for my app to consume a rest api service and since I will call it from javascript/jquery i need to expose it to the end user That's your first mistake. As Pinoniq pointed out in his answer, it's not possible to secure client side code. However, you can add your own server to the mix. Have your client side code use JavaScript / jQuery to make a ...


0

I think you should not directly access the Third Party API from your JavaScript application. Instead, you should implement your own basic web services which is like a wrapper around the Third Party API. You can then implement your own authentication method inside your own small web service or do not implement it in case it is not needed. However, you could ...


6

You can't. Let me rephrase: Impossible You could/should make it harder to use a token. Implementing a max-usage per token, a max life-time, ... It is however impossible to know if it is the scriptkiddie or your 'application' contacting your api. A lot of people tend to forget that it is never the aplpication calling the api, it's the application, ...


1

You are declaring a local scope function in this case. This means it will only be available withing your scope which is very limited. If you are not planing to reuse it, I wouldn't declare a function all together. if you are planing to reuse it, I would move it outside the callback scope into a separate module/class depending on what the responsibility of ...


1

One of the problems of using global variables is that it can lead to conflicts when you use them with other modules that also uses the same variable names and are also declared global in those modules. Say you have a Javascript file call it main.js and in that file are codes where there are global variables A, B and C. Then, your colleague who is also ...


0

On problem with globally scoped variables is that it can make the understanding of who needs to use that variable or modify it more difficult. It also means that as code grows, there can be collisions in usage of the variable - not simply having the same name for what should be two variables, but separate usages of the same variable in different program ...


2

There’s no such thing as information overload, only bad design. — Edward Tufte It's a general rule in graphic design to leave out unnecessary elements and ornamentation to reduce noise. Fewer visual elements on the screen means less work for our brains to parse the actual useful information. let foo = 1 vs. let /* variable */ foo = 1; // EOL ...


2

Direct answers / TL;DR ... The future is compilation forever, compilation in more places (e.g. node), and compilation by more and more developers/projects. Are we going to end up with different builds of our applications for different versions of browsers? I'm just going to go with whatever large companies determine is best. They have more ...


1

I think the paintCar function makes more sense if you provide a reference to the car object and the colors of the garage and favorite. function PaintCar (favoriteColor, garage, car) { //The test succeeds if the favoriteColor boolean value is true. if (favoriteColor) { return car.color = favoriteColor } // The test succeeds if either condition ...


0

You might like Require.js. I don't believe there is a "standard Angular way" of importing code because they figure you'll use any of the other techniques: Concatenate and minify using Bower Import using regular script tags Use a loading library like Require.js Just define your own stuff as services in Angular You also might want to read ...


3

This is related to constraint-programming. Prolog is an example of such a system. There exists javascript implementations of prolog http://yieldprolog.sourceforge.net/ . You could then make your prolog program and use it on both the server and client. Another approach is having all the logic on the server side but expose it as an api which the client could ...


2

As several others have pointed out, when the maintenance developers have to go behind you, a section of code in a different style is going to cause them to stop and try to figure out what is special about that section. There's also the very real risk of the inconsistent style getting propagated to other sections, resulting in a huge mess later. I get the ...


2

I have had good luck treating code styles just like I treat writing styles in natural English. There's a huge range of styles from conversational English, which mimics the way we speak in every day conversation, to formal English, which is often heavy and stilted by always very precise in its meaning. Consider what you would like the final product to look ...


0

It's very much about the legibility of the diffs. If code style thrashes around, the diffs hide changes with no semantic meaning to the program, and can make merges hard or impossible.


2

The topvoted answers here repeat the easily agreeable theoretical best practices detailing how we would all like our codebases to be. But real code somehow never looks like that. If you try to make that perfect codebase, you will almost inevitably fail. That is not to say that we shouldn't try to do better, but there has to be a limit for how far from the ...


0

If the event handler is declared in the script, it'd be (kind-of) hard to look at the code and figure out what button does. You answered your own question. Registering the handler in the JS code separates the markup from the logic which is always a desirable property.


2

There's no right or wrong to this, both things are fine. There are a few things to consider which makes one or the other better in one or the other situation. And actually, there are at least three ways of assigning event handlers: Using an event handler attribute in HTML, like this: <button id="buttonSave" onClick="save()">Save</button> ...


2

Custom elements are a specification part of the Web Components standard, along with Shadow DOM, Templates and HTML imports. From http://webcomponents.org/articles/introduction-to-custom-elements/: Custom Elements enable developers to create their own custom HTML tags, let them use those tags in their sites and apps, and enable easier component reuse. ...


50

Inconsistencies make you stop and think why, which and where: When you read part of the code and see that it uses a different style from the rest of the code, it makes you wonder - why is this particular part different? Does it have a special reason that I need to be aware of? This is dangerous, because if there really is a reason for that part to be ...


4

The code may be well written yet not perfectly consistent, so some clients won't care. When things start to go bad, do you want to give them another knock against you? If I hired a company to work on a multi-developer project and they didn't indicate to me that they have a coding standard and follow it, I would be skeptical. We need to keep a fast pace ...


47

Code Transfer Advantage Following patterns provided by a library, React in your case, means that the product you deliver will be easily picked up and maintained by other developers who are also familiar with React. Potential Backward Compatibility Issues Some libraries would have a new major version out, and backward compatibility might be compromised if ...


1

Your application probably have different actions with different access levels, for example an admin will probably be allowed more things than a simple user. So you better build some data-matrix summarizing user(-roles) access-rights and check brefore treating any request if the current logged-in user (or even unlogged Guest if you happen to have such a ...


2

Just use an URL with some query parameters, like <a href="user/5?checksum=12345">Edit</a> Of course the checksum is computed, perhaps using some session cookie, and your server code has something to validate it. So if your user is abusing the system by editing the URL (e.g. replacing user/5 by user/567) the checksum should no more be valid. ...


4

I have encountered this issue several times and have found what I think is the simplest solution. Since your user can edit (personal/account?) information, I assume you have some kind of authentication system up and running. If you use sessions to keep track of recognized clients you can store the user's ID inside it. Then you can fetch the ID from the ...


4

In JavaScript, a function's signature is not checked when called, so you can call a function of any arity with any number of arguments. arguments is a reserved variable provided to you by the language that holds all the arguments sent to the closest function, so you can get them even if they do not appear in the function's signature: js> function foo() { ...


0

timesSignerIsRequired is not global state, it's a field on your object. It's okay for the methods of an object to access the fields (including private fields) of that same object.


0

Regular html image tags hard coded on the page, but do not give them an src attribute. after everything on the page is loaded, use jquery and add an src attribute to each image tag you want, and it will automatically go out and grab that image. write some code to figure out what image you want based on what has loaded, then $(document).ready(function () { ...


2

Your confusion around tissue = new Tissue(); tissue1 = tissue.load_tissue(2); // tissue1 = 3; tissue2 = tissue.load_tissue(3); // tissue2 = 6 BUT tissue1 = 6 as well. derives from confusion value and object-oriented semantics in your tissue abstraction. This is called 'aliasing'. To find out which one you should use, ask the following question "If two ...


13

The problem is that a password should appear in plain text as rarely as possible. In your case, the password appears in plain text in an e-mail. This has several drawbacks: If the account of the person is compromised, the hacker gets access to your website as well. If there is a malicious man in the middle, he can access the password with ease. ...


4

Honestly, there is not much value to it. 1) Most people use their own password that they remember. If they do, then making them change their password will take longer than filling up an extra field during registration. The benefit of your system may be that by then the user is registered so you'll not lose it. 2) If they use a password manager it is ...



Top 50 recent answers are included