1
public Customer FindLuckyCustomer(IEnumerable<Customer> customers)
{
   foreach (Customer customer in customers)
       if (IsLucky(customer))
           return customer;

   return null;
}
public Customer FindLuckyCustomer(IEnumerable<Customer> customers)
{
   Customer result = null;

   foreach (Customer customer in customers)
       if (IsLucky(customer))
       {
           result = customer;
           break;
       }

   return result;
}

[The second] version has more lines of code, more state and more complex flow control. To me it’s more complex than the version with multiple returns. We have removed one complexity, and introduced a different one which turns out to be worse.

https://www.anthonysteele.co.uk/TheSingleReturnLaw.html

What is the reason to use "state" in a singular form, not "states"? Is it a typo or the word is used as an adjective? And in case it is used as an adjective, what exactly the author mean?

4

In this context state is an uncountable noun (not an adjective) meaning "management of state and related concerns." A more colloquial way of saying it would be "more saving and keeping track of data."

(In this case it refers to the use of the result variable.)

As is helpfully pointed out in a comment, this is computer jargon. Most English speakers would not be able to define it correctly or understand it correctly.

Depending on context, and arguably in this context, "state" might not refer to the process of keeping track of data but rather to the data itself. You could say that the result variable is state. An example of the word in this sense may be found in the Wikipedia article Session (computer science). The opening paragraph uses the phrase "state information" instead of "state":

A session is typically stateful, meaning that at least one of the communicating parties needs to hold current state information and save information about the session history in order to be able to communicate, as opposed to stateless communication, where the communication consists of independent requests with responses.

Later, the word state is used as a synonym for state information:

For example, an HTTP exchange between a browser and a remote host may include an HTTP cookie which identifies state, such as a unique session ID, information about the user's preferences or authorization level.

I would also note that if you thought that state was an adjective because of its parallel use with complex, you have been misled either by the noun phrase complex flow control or by the fact that the uses of more aren't actually parallel.

In more lines of code, the noun phrase is lines of code. The principal noun is lines, so there are more lines. The prepositional phrase of code gives you additional information about the lines.

In more state, the noun phrase is simply the noun state.

With more complex flow control, you can parse it in one of two ways. Either it is more plus a noun phrase complex flow control, meaning that there is a greater amount of complex flow control, or it is an adjective phrase more complex modifying the noun phrase flow control. I find the second interpretation more likely, but either makes sense here. A careful writer who intends the second meaning would probably write more-complex flow control to remove the ambiguity.

| improve this answer | |
  • 2
    It might be helpful to note that this use of "state" isn't quite plain English. It's computing jargon. – Gary Botnovcan Jul 20 at 16:17
  • 2
    @GaryBotnovcan It would be nice to have a special tag for such a kind of questions, technical or programming. – jsv Jul 20 at 17:16
  • 2
    Or maybe "jargon", to distinguish it from a more general "meaning-in-context". The same kinds of problems crop up with sports references, and I would hesitate to call those "technical" uses. – Gary Botnovcan Jul 20 at 17:32
  • @GaryBotnovcan That is an excellent suggestion. I have expanded the answer somewhat. – phoog Jul 20 at 19:41
  • 1
    @johnc.j. I suppose. If someone said that, I would probably understand what they meant, but I wouldn't say it myself. The word version refers to the source code or program logic as a whole. The state is the result variable. It therefore seems more logical to me to say the the version has more state. If I had to pick a different verb I would probably say that it uses more state. – phoog Sep 2 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.