3

here's a short question that my googling failed to deliver any clues on.

It seems to be pretty commonplace to use the word "res" for one of the indexes in function arguments. Its existence appears to be agnostic to whatever programming language you look at.

What does it stand for? A simple guess would be, "resource", perhaps? If this is spot on, it would be nice if someone who feels pedagogically inclined, would care to help me shed some light on this. What I don't grok, in particular, is when and why there's a use for the meaning, "resource" (granted that this is the actual meaning of "res").

Edit 1: I'm providing a random example, this is from the NodeJS.org homepage:

var http = require('http');
http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

Edit 2: I first came across the "res" thing while working with a PHP backend developer on a fairly modded WP instance. At the time things were too hectic to really sort out what he meant in his quick explanation, but he seemed to scatter the word all around, in arguments and $res variable calls alike. It's obviously impossible to comment on individual programmers' style and preference of coding, but I'm mostly curious to know if there's some sort of untold consensus among programmers – and if there's a single purpose – using a so called "res" pointer. (Compare eg. with using i for "iterator" as often used in loops.)

Henrik
  • 2,421
  • 4
  • 25
  • 33
  • 3
    I suspect you are a time traveler from the 1800's. Typefaces have evolved a bit since then. Those are actually "f"s and not "s"s and the keyword is "ref" which means reference. – Jamie Treworgy Oct 25 '10 at 22:37
  • It is usually an abbreviation for result or resource. In graphics-related programming it could also be resolution. If it's not clear from the context, then it shouldn't have been abbreviated. – Seth Oct 25 '10 at 22:39
  • 7
    In that context it is Request, Response – Jamie Treworgy Oct 25 '10 at 22:42
  • 1
    @jamietre why not make that an answer? No rep for upvoted comments that answer the question :p – Davy8 Oct 25 '10 at 23:01
  • Ah, the question got edited, I was replying to a comment that OP deleted. Anyway it seems all is right in the world now. – Jamie Treworgy Oct 26 '10 at 12:08

4 Answers4

7

In case it's not quite clear from the various answers and comments, in this context req is short for request and res is short for response.

Gabe
  • 84,912
  • 12
  • 139
  • 238
4

A HTTP transaction consists of a request from the client to the server and a response from the server to the client.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
2

In your code, req means request and res response, but res can also mean "result". A JS example:

function count(haystack, needle) {
    var res = 0

    arr.forEach(function (value) {
        if (value === needle) {
            res++
        }
    })

    return res
}
tleb
  • 4,395
  • 3
  • 25
  • 33
2

Not an answer, but

It seems to be pretty commonplace to use the word "res" for one of the indexes in function arguments. Its existence appears to be agnostic to whatever programming language you look at.

Nope. My guess is this is only common for Javascript doing http request/response (or a few very similar things).

Brian
  • 117,631
  • 17
  • 236
  • 300