title: Objective C naming convention for method performs an action and returns a value
body: <p>I have a method that performs an action and returns a value. For example  from the input number it will update class's input history, then generate and return an input record. So how do I name this method?</p>
  
  <p>I think even C has this problem, e.g. <strong>fopen</strong> function does open a file and return a handler. But with Objective C convention it seems difficult to name the method.</p>
  
  <p>From apple document for cocoa <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/Conventions/Conventions.html" rel="nofollow noreferrer">name convention</a> and also from this article <a href="http://www.cocoawithlove.com/2009/06/method-names-in-objective-c.html" rel="nofollow noreferrer">cocoa with love</a> They both said "<em>If a method performs an action the first word should indicate that action</em>" and "<em>If a method returns a value the first word normally indicates what will be returned</em>" </p>
  
  <p>So if I name something like <code>callRecordFromNumber:(NSString*) number</code>, it only indicates the returned value, not the action it performs. If I name something like <code>updateCallRecordFromNumber:(NSString *) number</code>, it only indicate the action, not the returned value.</p>
  
  <p>BTW, I do consider separate it into 2 methods, but the thing is the new record is generated alongside with the action is performed. The code like this: creating a new one if not exists, then update history record. And the actual code has several types of histories (say, missed call history, rejected call history, total history), and record is generated and updated for its own history. So separating it into 2 methods will introduce too many duplicated codes. Seems not a good option here. </p>
  
  <pre><code>Record *record = totalHistory[number];
  if (record !=nil ) return record;
  record = [[Record alloc] initWithNumber:number];
  record.type = [self callType:number];
  totalHistory[number] = record;
  switch (record.type) {
      case -1: /*missed call*/ {
      missedHistory[number] = record;
      break; }
      case 0: /*normall call*/ {
      acceptedHistory[number] = record;
      break; }
      case 1: /*rejected call*/ {
      rejectedHistory[number] = record;
      break; }
      ...
  }
  return record.
  </code></pre>
  
  <p>---- Update ----</p>
  
  <p>Following 2 discussions are helpful too.</p>
  
  <p><a href="https://softwareengineering.stackexchange.com/questions/244630/how-to-name-a-method-that-both-performs-a-task-and-returns-a-boolean-as-a-status">How to name a method that both performs a task and returns a boolean as a status?</a></p>
  
  <p><a href="https://softwareengineering.stackexchange.com/questions/198165/naming-functions-that-retrieve-a-value">Naming functions that retrieve a value</a></p>
  
  <p>Now I am using the method name like this, <strong>valueByPerformed</strong>..., e.g. recordByUpdatedCallHistoryFrom:</p>
  
  <p>Wordy :( I wish there was a better name！</p>
  
  <p>---- update ----</p>
  
  <p><a href="https://swift.org/documentation/api-design-guidelines/#naming" rel="nofollow noreferrer">swift 3.0 naming guideline</a>, e.g. <a href="http://www.appcoda.com/swift3-changes/" rel="nofollow noreferrer">Verbs vs Nouns Naming Convention</a>, like sort vs sorted gave me some new thought about this question. Now I do think <strong>valueByPerformed</strong> is probably a good name :D</p>