... | ... | @@ -29,19 +29,17 @@ interest is Rust (at the time of writing). |
|
|
|
|
|
# Referenced Courses & Materials
|
|
|
|
|
|
I am going to pull from CS 330, CS 350, CS 411W, and CS 417 lecture notes
|
|
|
I am going to pull from CS 330, CS 350, CS 411W, and CS 417 lecture notes.
|
|
|
|
|
|
- **CS 330 - Object Oriented Programming & Design**
|
|
|
- [S.O.L.I.D](https://www.cs.odu.edu/~tkennedy/cs330/f20/Public/reviewSOLID/)
|
|
|
- [Iterators](https://www.cs.odu.edu/~tkennedy/cs330/f20/Public/designDiscussionIterators/)
|
|
|
- **CS 350 - Introduction to Software Engineering**
|
|
|
- **CS 411W - Professional Workforce Development II**
|
|
|
- [Git Review](https://www.cs.odu.edu/~cs411/f20/Public/gitIntro/)
|
|
|
- **CS 417 - Computational Methods & Software**
|
|
|
- [Python non-linear solver discussion](https://www.cs.odu.edu/~tkennedy/cs417/f20/Public/solverDiscussion/)
|
|
|
|
|
|
I will also pull a couple examples from my previous Git workshop, <https://www.cs.odu.edu/~tkennedy/git-workshop>.
|
|
|
i
|
|
|
|
|
|
|
|
|
# The Broad Strokes
|
|
|
|
... | ... | @@ -53,7 +51,7 @@ This workshop is intended as discussion on how to write more concise, idiomatic |
|
|
|
|
|
There are generally three styles of code found in Python.
|
|
|
|
|
|
**Procedural**
|
|
|
## Procedural
|
|
|
|
|
|
```python
|
|
|
|
... | ... | @@ -68,7 +66,10 @@ for point in points: |
|
|
|
|
|
```
|
|
|
|
|
|
**Object Oriented**
|
|
|
Procedural style code tends to be how most *quick* Python programs are written.
|
|
|
|
|
|
|
|
|
## Object Oriented
|
|
|
|
|
|
```python
|
|
|
class Point:
|
... | ... | @@ -90,7 +91,27 @@ class Point: |
|
|
return sqrt(self.x ** 2 + self.y ** 2)
|
|
|
```
|
|
|
|
|
|
**Functional**
|
|
|
A proper discussion of Object oriented Python would require explantation of the [rules of a class
|
|
|
checklist](https://www.cs.odu.edu/~tkennedy/cs330/f20/Public/classChecklistCrossLanguage/index.html).
|
|
|
|
|
|
| C++ | Java | Python 3 | Rust |
|
|
|
| :------------------------ | :------------------------------ | :--------------- | :---- |
|
|
|
| Default Constructor | Default Constructor | `__init__` | `new()` or Default trait |
|
|
|
| Copy Constructor | Clone and/or Copy Constructor | `__deepcopy__` | Clone trait |
|
|
|
| Destructor | | | |
|
|
|
| | finalize (deprecated/discouraged) | `__del__` | Drop trait |
|
|
|
| Assignment Operator (=) | | | |
|
|
|
| Accessors (Getters) | Accessors (Getters) | Accessors (`@property`) | Accessors (Getters) |
|
|
|
| Mutators (Setters) | Mutators (Setters) | Setter (`@attribute.setter`) | Mutators (setters) |
|
|
|
| Swap | | | |
|
|
|
| Logical Equivalence Operator (==) | equals | `__eq__` | std::cmp::PartialEq trait |
|
|
|
| Less-Than / Comes-Before Operator (<) | hashCode | `__hash__` | std::cmp::PartialOrd trait |
|
|
|
| Stream Insertion Operator (<<) | toString | `__str__` | std::fmt::Display trait |
|
|
|
| | | `__repr__` | std::fmt::Debug trait |
|
|
|
| `begin()` and `end()` | `iterator` | `__iter__` | `iter()` and `iter_mut()` |
|
|
|
|
|
|
|
|
|
## Functional
|
|
|
|
|
|
```python
|
|
|
point1 = (0, 5)
|
... | ... | |