Tag Info

New answers tagged

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


11

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


2

First thing is to know the partitions of the number 5 (the team size you want to assembly). There are algorithms to generate the partitions of a number but since the number is small and fixed you don't need to worry about it. The partitions of 5 are: {5}, {4,1}, {3,2}, {3,1,1}, {2,2,1), {2,1,1,1}, and {1,1,1,1,1}. Make 5 lobby lists (L1,L2,L3,L4,L5). One ...


1

Calculate the total rank of all players in a single lobby. Match with other lobby based on that. (+- 1.5 range pretty much) Isn't it as simple as this?


1

Node.js is an open source, cross-platform runtime environment for server-side and networking applications. Basically the language it is programmed is still javascript but it adds some functionalities to the javascript in which we write our applications. Node.js is not a framework but rather a runtime environment. It may seem like a framework at first ...


5

Most languages in common use are more powerful and better designed than JavaScript. All the features you mention are supported by other dynamic languages like Python or Ruby which are overall better designed. And some of the features you mention are not necessarily desirable anyway - many would consider static typing with type inference preferable to dynamic ...


0

Game calculations involve a lot of real work; like any real work, it'd be ridiculous to try to mandate to the computer "Enforce that this function runs inside of 300ms". In fact, 2040's computers might run that work 10x as fast. requestAnimationFrame means "run this as often as possible". You'll find that lots of mathematical, smooth-application code in a ...


0

Do not bind events to elements that may appear, disappear, or change. Bind them on the parent DIV: <div id="right_side"> <input type="text" id="firstname">Susan</input> <label for="nickname">Nickname? <input type="checkbox" id="nickname"> </label> </div> <script> // This script must be executed ...


4

The problem is the global scope. In other words, every change you make affects the whole code base, and yours may in turn be affected in any location of the code base. Imagine that you want to loop through all elements of an array; imagine that browsers don't support it yet. For that, you create a method forEach which is called this way: [5, 7, 1, 1, ...


1

Abhi explained on Stack Overflow why you don't want to do it to common objects, but for your own class, that's the way of doing it. So in short, the answer is DEPENDS. When you extend an object, you change its behaviour. Changing the behaviour of an object that will only be used by your own code is fine. But when you change the behaviour of ...


1

Indeed, such fixtures are not a good way to run unit tests. The goal of unit tests is to test a very specific (and often very small) part of the code in isolation from the remaining code and the environment. By making those tests rely on the particular state of the web page, you lose the “unit” aspect of your tests, meaning that you'll rather have system and ...


0

I would go a bit of different route here: Setup a Node.js based service on the mainframe. Setup queuing system. (0MQ, RabbitMQ) Use your Node.js to read from the queue and process. Return the results to your main process through the queue as well. Fully asynchronous and independent system. Advantages: Node.js can handle millions of connections ...


0

I'd say, when you don't know what to do, just use jQuery. jQuery has lots of value, handles edge-cases and avoid headaches for you: https://decadecity.net/talks/what-has-jquery-ever-done-for-us Using jQuery is standing on the shoulders of giants.


1

The short answer is yes, you can pretty much replace callbacks with promises. The caveat is some library APIs use callbacks so you are unlikely to be able to avoid them altogether.


0

If I, as an end user, use a widely used browser without employing any clever tricks, then you can detect which browser I am using, and your server code can easily block my browser (display a website saying "please use a different browser"). If I detect that your website doesn't support my browser, and I want to use your website and not change my browser, ...


1

I write this from the perspective of a long-time .NET developer being pulled inexorably into the client-side JavaScript world, so I assume that I probably share some of the same biases as you. I only bring this up because I think a lot of your bullet points are probably biased by your experience and relative comfort with C# and .NET over JavaScript. For ...


0

I think many of your main points are quite misguided; claiming that "yes browsers can do it but Visual Studio is better" is not going to convince your coworkers (who probably are more used to debugging JS than to working with VS). Also: number 3 is not an actual issue; you can write JS that does not rely in the browser version and that means no more ...


0

Just to record a javascript adaptation from Movable Type Scripts function createCoord(coord, bearing, distance){ /** http://www.movable-type.co.uk/scripts/latlong.html φ is latitude, λ is longitude, θ is the bearing (clockwise from north), δ is the angular distance d/R; d being the distance travelled, R the earth’s radius* ...


2

You might want to search for Javascript static program analysis tools (like this question), e.g. Flow. You'll find many research papers on that subject. I've heard several talks on that subject, and IIRC eval is used, sometimes carelessly or needlessly, in many practical Javascript software. Your question can be understood in two different ways: How ...


2

You have a mentor! Wow, great first step. At least somebody cares. The thing about writing code is that any idiot can do it. And a lot of idiots do. The difference between idiot code, and good, clean, maintainable, documented code that works well and is easy to maintain... a bit like the difference between chalk and cheese. Things like coding standards, ...


1

Is my mentor's concern for code quality excessive? Possibly. Your statement that only one (his) version of solving a problem hints to it. But then he probably is way more competent than you are right now, so it might just a (wrong) impression that you get. Others have pointed out how what he does sounds perfectly reasonably. But it shouldn't really ...


2

Your mentor is taking his role seriously; you should always appreciate that. By holding you to a high standard, he is helping you develop the practices and proficiencies that will serve you well in your career. By pointing out errors made by others, he is helping you better recognize bad code so that yours will more often be better. To become expert at ...


-8

This is an opinion question so I'll give my opinion as a desktop and web programmer. Yes his concern are excessive in the context of web development in JavaScript. Such concerns apply to large codebase written in strong typed languages that have to be maintained for decades. JavaScript was never meant to follow best practice and industry standards. It was ...


20

One big key to understanding what is happening: It is possible, via Javascript, to set the URL in the addressbar without actually redirecting the user. To see this in action, paste the below code into a supported browser's console. Notice that it changes your address bar to http://programmers.stackexchange.com/yay.html. ...


24

The short answer is that the page's client-side Javascript code detects when you get "too close" to the bottom of the page, and asks the server for more data when that happens. Without getting too technical, they are not reloading the entire web page. Instead the Javascript code on that page is requesting more data from the server, then when it receives the ...


6

for the first time feeling like I get close to being competent. I've been programming for over twenty years, and every year I wind up saying that to myself at least once or twice. anything takes a whole lot of time because I have to find the best way to do it or else its a waste of time, it also feels like my creativity doesnt matter because there ...


6

"Done is better than perfect" I hate to break it to you, but code can always be made better, code is never perfect. If you think your code is perfect, you probably haven't looked at it enough yet, or you're no real engineer, as a real engineer can always make things better than they are. (Or, in the programmers lingo, a real hacker can always make things ...


21

To tell you a little about myself, I'm a newbie programmer working internships and learning a lot from experienced programmers [...] This sentence it seems to me is the key to the answer. I manage teams of programmers. When I do code review with programmers in general (of good and not so good levels of skill) I will get them to write code to meet or ...


9

Your mentor may be an excellent coder, but... Does he have the authority to review and change all the code? Is he potentially imposing stylistic changes on functional code rather than fixing bugs/preventing dangerous behavior? Are the changes being made backed up by unit tests and/or functional tests? Was there significant unit test coverage before the ...


1

When I mentor I always need to keep in mind that my pov is not the absolute truth. Design is still a creative process, but the more I learn the more I put constraints on my creativity, which I don't think kills creativity, it actually makes it stronger. Some of my ideas are still experiments and I can't enforce those to newcomers. Leaving aside "the ...


8

There are two issues here: The issue of your mentor disliking your solution is hard to qualify without concise examples. Maybe if you posted your code, you would find that everybody agrees with your mentor and that you are using the wrong approach (do not worry about it, the fact that mentors exist is the prove that most people need to get some actual ...


130

"Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live." (Took it from here) That said: there is no level of »excessive« for code reviews. I'm a newbie programmer working internships and learning a lot from experienced programmers What is more important than writing code is reading code ; read ...


27

I am very much like your mentor. I treat all code reviews for developers of any experience the same way, even if I wrote the unchanged code I'm complaining about myself. It's no reflection on you or your abilities. Often, the problems with a design are not apparent until you try to modify it. Alternately, a design might have been perfect before the ...


70

Let me quote from Page xxii (Foreword) of "Clean Code" by Robert C. Martin from Prentice Hall. Back in my days working in the Bell Labs Software Production Research organization (Production, indeed!) we had some back-of-the-envelope findings that suggested that consistent indentation style was one of the most statistically significant indicators ...


14

First things first - there is very rarely a single "correct" way to do something in code. So your creativity always matters. That said, there are a whole lot of bad ways to do something in code. Ways that will cause you (or others on your team) issues in the future. Sometimes immediately. So code quality is very important, since poor code quality tends to ...


1

There are very good arguments for and against each option. If you were speaking with regards to configuration data I would think a longer and more in-depth discussion would be warranted. Since you're talking about application data, I would be inclined to believe that unless you know for certain that these data would never need to be queryable for reports ...


2

In order to make this more on-topic, this is a way to go about determining which one is better for a particular situation. Note: you may find that the best solution could change over time as your application's requirements change. Do Both: Sorry, if you want to really find out the best solution, I recomend doing both and comparing your results. This ...


0

Json Way Pros: Faster than DB There is no weight for server/job Cons: Update/Edit content is difficult. DB Way Pros: Can be develop for speed Cons: Sometimes its unnecessary if it isn't change. If its grow, it will weight for server My suggest is using DB. Because you can develop for speed. Generally, I'm using JSON for static weight ...


0

Hmm I guess the obvious one is to: sort B desc sort A asc loop through A loop through B if Value(B) <= RemainingValue(A) add B to A break if RemainingValue(A) == 0 OR you run out of B Next B Next A but this is not quick


1

SQL Server has a feature called query notification. The application submits a query and some parameters. This is know as a subscription. If data changes so the result of this query would be different with the new data, the notification fires. From BoL: Query notification subscriptions must be created from a database access interface. Transact-SQL does ...


0

I ended up using the gulp-preprocess plugin. My code looks like this now and it's working well so far. <script src="<!-- @echo IMAGE_SERVER_URL -->/scripts/iep-alert/alert.js"></script>



Top 50 recent answers are included