Tag Info

Hot answers tagged

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 ...


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 ...


10

I think JavaScript is not the best language to start learning programing concepts, mainly because of its "unusual" prototype approach. C is meanwhile completely there were assembler was in earlier days. So I think not very interesting for most of the students. Where I think C++ now took the role of C. But I think C++ is not that interesting or fancy for ...


8

It all depend of the purpose of the course. If the goal is to teach programming fundamentals, consideration about actual usefullness of the language should be largely ignored. Javascript is nice because it is used in browsers. On the other hand it has a lot of problems that will distract your students from the core message of your course. Learning ...


7

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, ...


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 ...


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() { ...


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 ...


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 ...


3

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 ...


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 ...


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 ...


3

The short answer is that JIT has longer initialization times, but is a lot faster in the long run, and JavaScript wasn't originally intended for the long run. In the 90s, typical JavaScript on a web site would amount to one or two functions in the header, and a handful of code embedded directly in onclick properties and the like. It would typically get run ...


3

I would advise you to stuck to: "Start simple. Build complexity on top of it." JS with its prototype based inheritance is just to complex to begin with it. IMHO a good programming class should start low-complexity, low-level (C-console - as you already do - for example) and slowly move up to high complexity, high-level (C++ OOP, JS, PHP, etc.) - if ...


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 ...


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. ...


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

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. ...


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 ...


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 ...


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 ...


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

match is just a wrapper for exec, per ES5 15.5.4.10, step 8(f)(i): Let result be the result of calling the [[Call]] internal method of exec with rx as the this value and argument list containing S. For a global regex, match continuously calls exec until exec retruns a null value. When we look at exec, we see that each call to exec with a global regex ...


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 ...


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 ...



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