Hot answers tagged

82

Code that works for you and is easy to maintain is by definition "good". You should never change things just for the sake of obeying someone's idea of "good practice" if that person cannot point out what the problem with your code is. In this case, the most obvious problem is that resources are hard-coded into your application - even if they're selected ...


72

In its most basic form, a website serves static files. Mapping the URL path to a file path is the most obvious choice; essentially, it's a read-only FTP site. Then people wanted to change the content of the page with some scripting. The easiest way is to embed a scripting language into the page and run it through an interpreter. Again, given the already ...


40

You can look to a white paper by Roy Fielding on REpresentational State Transfer (REST) as to the when and the why. The first framework I was aware of that made the distinction between a resource and a file was Ruby on Rails--introducing the concept of URL to code routing. The main concepts behind REST that were transformational were: A URL represents a ...


20

I don't think it's an artefact of modern web application frameworks, it's mostly an artefact of dynamic page serving in general. In the old days there were mostly static web pages, where a software served individual files from the file system by their path. They did so mostly because the 1:1 mapping of URL paths to file system paths (with one directory ...


14

You are absolutely right in thinking this is a bad practice. I've seen this in production code, and it always comes back to bite you. What happens when you want to add another environment? Or change your development server? Or you need to fail over to a different location? You can't because your configuration is directly tied to code. Configuration should ...


12

One reason is that loading a file from disk on every request is slow, so web servers started creating ways to cache files in memory, then if you're going to try to keep it in memory anyway, why does it matter where it was on disk? One reason is that many web frameworks are written in compiled languages, so you don't even have a file structure on disk, just ...


11

On of the major reasons is likely that this approach of mapping URIs to file paths has lead to a large number of accidental releases of data via File Path Traversal When you map the path to the file system, it means that you then need to check that every path that you receive as a request maps to files that should be accessible through to clients. A simple ...


8

I can't answer for the industry, but I can tell you why I moved away from the URL = file system back in the early 2000's towards virtual 'routes'. Working with 'old school' PHP, if you have a 1000 PHP pages, you'd have 1000 PHP files representing those pages. Each one duplicating header/footer includes and possibly some other logic. Now let's say you need ...


7

First, see the CAP Theorem. It's similar to the old aphorism of "Fast, Good, Cheap: Pick 2." In theoretical computer science, the CAP theorem, also known as Brewer's theorem, states that it is impossible for a distributed computer system to simultaneously provide all three of the following guarantees: Consistency (all nodes see the same data at ...


7

Is there another good reason? Sure. There are probably many good reasons, though they may not be the reasons motivating YouTube, DailyMotion, etc: The underlying resource isn't identified with a numeric key. A non-numeric identifier makes casual discovery harder. That is, you can't casually browse to another resource by incrementing the key. The ...


7

Tell him that some actions won't have ID's and some will have two or more. It makes more sense to have them at the end, because otherwise the position of your {action} attribute will jump around, making the construction of your routing table much more difficult.


6

If it is truly an ordered linked list, this should be a fairly bad choice because you have to traverse the list one by one until you find the right place to insert the item. In other words O(N). This is ok if the list is small but can get out of hand for big graphs. Usually, what you will need for that kind of stuff is a heap: http://en.wikipedia.org/wiki/...


6

I’d say the first publicly available website of the Web had/has a friendly URL: http://info.cern.ch/hypertext/WWW/TheProject.html The same is true for many of the early websites, e.g. the WWWVL (see the history, which contains some of the original URLs). It’s a subject for debate if the file extension (.html) is "friendly" or not. I’d say especially in ...


6

HaHa :) its NP-Hard https://en.wikipedia.org/wiki/Job_shop_scheduling But your main problem are the humans involved, who will go on holiday, become ill and change shifts at inconvenient times. Your best bet is to forget about optimal and go for ease of use. Automate the calculations that people do in their heads to work out which job to allocate to whom, ...


5

A Frontend-Controller should collaborate with a Router and a Dispatcher to decide based on the (HTTP) request against the application which concrete Action has to be executed and then dispatches it. Depending on how detailed a design is, some Controllers work without Routers and they do the routing their own or the routing is implicit in the design how the ...


5

For one, (as others have mentioned) this is a bad idea because you're tying implementation details into your code. This makes it difficult to change things. As mentioned in this answer, if you want to add a new environment now you have to update your code everywhere, instead of just adding your program to a new environment. There is another serious flaw ...


5

I won't go into too much detail as to why this separation is beneficial. The main argument is that it separates semantics (what are you actually trying to access) from the underlying implementation. Taking that the benefits outweigh the costs as a given - which would be a separate question - it's not difficult to see why it was gradually adopted. I don't ...


4

Actually, there are 3 reasons: Convention Convention Convention Convention is important, because it makes it easier for other programmers to understand your code. In RoR it's even more important, since many facilities of the framework and 3rd party plugins are assuming you are following the convention. Often they'll offer a configuration interface you can ...


4

What are the advantages of HATEOS compliant RESTful service? In short: You stay in control of your server side, minimize client knowledge about server internals. Imagine Amazon giving you a product page with just the product data, no links or forms to buy the item. It would assume, that you will go to a separate service (let's say a shopping cart service) ...


3

This seems like a decision for business people to make, not developers. They do calculations and determine the rules by which your application will decide what parcel gets shipped by you, and what parcel gets shipped by third party. If I was to implement it, here is how I would go about it: Get quotes for each delivery company you can use. Factor in your ...


3

This form www.example.com/invite/123 is preferable when your URL refers to something concrete and specific, like a business entity, transaction or document. The word "invite" typically refers to a controller method. This form www.example.com?invite=123 is preferable when you want to modify the operation or resource at the designated URL using ...


3

REST does not mean to not use URL params at all. Your example demonstrates this very well. You can still see a 'search' as a REST resource. You implement a controller for it, though it only has one or two actions. (But details do not matter much in this case) Everything data needed to perform the search can then be sent by using params. There is nothing ...


3

I would keep your routing as simple as possible - /apple seems perfectly valid. If the user is not allowed to view /apple then show them an error message, if they are allowed to but apple is currently hidden by filters, I'd remove those filters and show them the apple. Basically - routes should refer to distinct resources and not be clouded by other ...


3

how come the default route doesn't have the action in the route configuration by default? Because in REST, the action to be executed by the server is dictated by the HTTP method used in the request.


3

Routers are part of the controller layer. The router processing mechanism is a replacement of the old school Front Controller pattern (the big switch in the entry point). In a modern framework a router defines a direct connection between a "kind" of possible requests and its processor. By contrast, a controller gets just identifying information, ...


3

Elastic Search has this issue, as well: their solution was to allow GET requests with bodies: $ curl -XGET 'http://localhost:9200/twitter/tweet/_search' -d '{ "query" : { "term" : { "user" : "kimchy" } } } ' Though non-standard, it's not technically a violation of HTTP/1.1: The presence of a message body in a request is signaled by a ...


3

This is an NP-Hard problem There has been lots of research on approximations to the TSP. You should look up "traveling salesmen approximations". These will be fast, but not guaranteed optimal/correct. If you manage to solve this correctly/optimally in polynomial time, then you will be an eternal CS hero.


3

There is no advantage to a HATEOS compliant service. The stated goal is to make the api 'discoverable'. However no-one has managed to develop a client with enough AI to be able to interpret the meaning of links provided with a resource. As to what it takes to make a service compliant, well the spec is very very bare on this question. The normal solution is ...


2

When exactly did people start making web technologies handling this though? mod_rewrite handles this functionality on Apache and mod_rewrite has been available since Apache 1.3, which was released on June 6, 1998. See also: http://en.wikipedia.org/wiki/Rewrite_engine


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