Skip to content

Commit ffb5fa3

Browse files
committed
Add a section on naming methods
1 parent 71a235b commit ffb5fa3

1 file changed

Lines changed: 14 additions & 26 deletions

File tree

README.md

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -373,38 +373,26 @@ def email_client(clients: Iterator[Client]) -> None:
373373

374374
**Bad:**
375375

376-
```php
377-
class Email
378-
{
379-
//...
380-
381-
public function handle()
382-
{
383-
mail($this->to, $this->subject, $this->body);
384-
}
385-
}
376+
```python
377+
class Email:
378+
def handle(self) -> None:
379+
# Do something...
386380

387-
$message = new Email(...);
388-
// What is this? A handle for the message? Are we writing to a file now?
389-
$message->handle();
381+
message = Email()
382+
# What is this supposed to do again?
383+
message.handle()
390384
```
391385

392386
**Good:**
393387

394-
```php
395-
class Email
396-
{
397-
//...
398-
399-
public function send()
400-
{
401-
mail($this->to, $this->subject, $this->body);
402-
}
403-
}
388+
```python
389+
class Email:
390+
def send(self) -> None:
391+
"""Send this message.
392+
"""
404393

405-
$message = new Email(...);
406-
// Clear and obvious
407-
$message->send();
394+
message = Email()
395+
message.send()
408396
```
409397

410398
**[⬆ back to top](#table-of-contents)**

0 commit comments

Comments
 (0)