Repository: Qiskit/qiskit

Issue:
The methods "get_something()" should be "something()"
@jaygambetta expressed discontent with methods of the shape `get_something()`. It seems he is not [the](https://stackoverflow.com/questions/374763/should-i-use-get-set-prefixes-in-python-method-names) [only](https://python-consistency.readthedocs.io/en/latest/conventions.html#properties) [one](https://github.com/sovetov/python-style-guide#names).

A quick grep returned:

- [x] ~`qiskit/tools/visualization/_matplotlib.py`:   `get_index(self)`~ See https://github.com/Qiskit/qiskit-terra/issues/1346#issuecomment-442202176
- [ ] `qiskit/result/_result.py`:
     - `get_status(self)`
     -  `get_circuit_status(self, icircuit)`
     - `get_job_id(self)`
     - `get_ran_qasm(self, name)`
     - `get_data(self, circuit=None)`
     - `get_counts(self, circuit=None)`
     - `get_statevector(self, circuit=None)`
     - `get_unitary(self, circuit=None)`
     - `get_snapshots(self, circuit=None)`
     - `get_snapshot(self, slot=None, circuit=None)`
     - `get_names(self)`
     - `get_qubitpol_vs_xval(self, nqubits, xvals_dict=None)`
- [x] `qiskit/backends/ibmq/api/ibmqconnector.py`: https://github.com/Qiskit/qiskit-terra/issues/1346#issuecomment-461134342
   - `get_job_url(config, hub=None, group=None, project=None)`
   - `get_backend_stats_url(config, backend_type, hub=None)`
   - `get_backend_properties_url(config, backend_type, hub=None)`
   - `get_backend_url(config, hub, group, project)`
   - `def get_token(self)`
   - `get_user_id(self)`
   - `get_config(self)`
   - `get_job(self, id_job, hub=None, group=None, project=None,..)`
   - `get_jobs(self, limit=10, skip=0, backend=None, only_completed=False,...)`
   - `get_status_job(self, id_job, hub=None, group=None, project=None,...)`
   -  `get_status_jobs(self, limit=10, skip=0, backend=None, filter=None,...)`
- [ ] `qiskit/backends/baseprovider.py`:    `get_backend(self, name=None, **kwargs)` 
- [x] `qiskit/backends/aer/aerprovider.py`: ` get_backend(self, name=None, **kwargs)` https://github.com/Qiskit/qiskit-terra/issues/1346#issuecomment-461134342
- [x] `qiskit/unrollers/_unrollerbackend.py`:    `get_output(self)` https://github.com/Qiskit/qiskit-terra/issues/1346#issuecomment-461134342
- [x] `qiskit/unrollers/_dagbackend.py`:   `get_output(self)` https://github.com/Qiskit/qiskit-terra/issues/1346#issuecomment-461134342
- [x] `qiskit/unrollers/_jsonbackend.py`: `get_output(self)` https://github.com/Qiskit/qiskit-terra/issues/1346#issuecomment-461134342
- [ ] `qiskit/mapper/_coupling.py`:
   - `get_qubits(self)`
  - `get_edges(self)`
- [x] `qiskit/mapper/_layout.py`:  
   - `get_bits(self)`
   - `get_wires(self)`
- [x] qiskit/dagcircuit/_dagcircuit.py`:  
   - `get_qubits(self)`
   - `get_op_nodes(self, op=None)`
  - `get_named_nodes(self, name)`
  - `get_cnot_nodes(self)`
- [ ] `qiskit/qasm/_qasm.py`:
  - `get_filename(self)`
  - `get_tokens(self)`
- [ ] `qiskit/qasm/_qasmparser.py`:   `get_tokens(self)`

In many situations the prefiex `get_` simply can be removed. In others, it can be replaced by more specific, like `generate_output`. If there is a `set_something`, in that case I think `get_something` makes sense.

Since this change affects a lot of things, do it in several PRs please.


Discussion:
Yes there are many that we need to fix. The get_backend I think we keep as we have a backends command. 
The matplotlib one I wouldn't worry about it, it's an internal method on a class only used inside that module (to set anchors in the figure). It's never going to be called anywhere else
For the `Result`s, there is an attempt of discussion at #830. For the rest of instances and potential implementers, please note as well that even if the technical challenge is indeed relatively straightforward (as in, renaming the method and revising the rest of the codebase and test for usages of the method), some discussion might be needed:
* if the change implies a public API change, a deprecation warning should be emitted.
* not all `get_xxx` functions fall into the same category - there are some that are indeed akin to _property_ setters (ie. where the recommendation linked above very likely applies), but there are others with a different semantic meaning (Jay's example of `.get_backend()` is one where that distinction is arguably quite strong - it is not getting a property, it involves actually retrieving a backend).

It would probably be a good idea indeed to go case-by-case basis (per class or similar) - other than those nits, it sounds good! Thanks @1ucian0 for starting the effort :+1: 
Maybe `select_backend`?
lol I really like select_backend but the spec is out and we have so many people using get_backend. But select is so much more descriptive. @diego-plan9 @ajavadia thoughts? 
Not part of terra any more:
* `qiskit/backends/ibmq/api/ibmqconnector.py`
* `qiskit/unrollers/` 
* `qiskit/backends/aer/aerprovider.py`

Resolving patch:
diff --git a/qiskit/qasm/qasm.py b/qiskit/qasm/qasm.py
--- a/qiskit/qasm/qasm.py
+++ b/qiskit/qasm/qasm.py
@@ -15,6 +15,8 @@
 """
 OPENQASM circuit object.
 """
+import warnings
+
 from .exceptions import QasmError
 from .qasmparser import QasmParser
 
@@ -32,18 +34,29 @@ def __init__(self, filename=None, data=None):
         self._filename = filename
         self._data = data
 
-    def get_filename(self):
+    def return_filename(self):
         """Return the filename."""
         return self._filename
 
     def get_tokens(self):
+        """Deprecated. Use generate_tokens()."""
+        warnings.warn('The method get_tokens() is being replaced by generate_tokens()',
+                      DeprecationWarning, 2)
+        if self._filename:
+            with open(self._filename) as ifile:
+                self._data = ifile.read()
+
+        with QasmParser(self._filename) as qasm_p:
+            return qasm_p.read_tokens()
+
+    def generate_tokens(self):
         """Returns a generator of the tokens."""
         if self._filename:
             with open(self._filename) as ifile:
                 self._data = ifile.read()
 
         with QasmParser(self._filename) as qasm_p:
-            return qasm_p.get_tokens()
+            return qasm_p.read_tokens()
 
     def parse(self):
         """Parse the data."""
diff --git a/qiskit/qasm/qasmparser.py b/qiskit/qasm/qasmparser.py
--- a/qiskit/qasm/qasmparser.py
+++ b/qiskit/qasm/qasmparser.py
@@ -17,6 +17,7 @@
 import os
 import shutil
 import tempfile
+import warnings
 
 import ply.yacc as yacc
 import sympy
@@ -1046,7 +1047,22 @@ def find_column(self, input_, token):
         return column
 
     def get_tokens(self):
-        """Returns a generator of the tokens."""
+        """Deprecated. Use read_tokens()."""
+        warnings.warn('The method get_tokens() is being replaced by read_tokens()',
+                      DeprecationWarning, 2)
+        try:
+            while True:
+                token = self.lexer.token()
+
+                if not token:
+                    break
+
+                yield token
+        except QasmError as e:
+            print('Exception tokenizing qasm file:', e.msg)
+
+    def read_tokens(self):
+        """finds and reads the tokens."""
         try:
             while True:
                 token = self.lexer.token()


Test patch: