巨人の足元でたじlog

そうして言葉を軽んじるから――― 君は私の言葉を聞き逃す

pythonではじめるソフトウェアアーキテクチャ読書メモ①

ずっとちゃんとしたアプリケーションというものを作ったことがなかった。

アプリケーションを作ったことはあるが、ちゃんとした方法論に基づいて作ったり、他人にレビューされたりすることがあまりなかった人生だった。
いい加減にこの状態から脱したい。
そう思ってちょうど良さそうな本を積読していたのを思い出した。
勉強させていただこう。

第2章 修正用意性と可読性

まずpythonにはZenなるものがあるらしい。

Python 3.6.0 (default, Jun 25 2018, 03:17:06)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>> import this
>>> this
<module 'this' from '/Users/yoshii/.anyenv/envs/pyenv/versions/3.6.0/lib/python3.6/this.py'>

なるほど、unixという考え方。的なことか。

ちょっとよくわからない文もあるので、後で調べてみよう。

アンチパターンについて。

インデント

  • これは基本的にはVSCodeなどのエディタのlinterを使おう。

文字列リテラル

シングルクオートとダブルクオートを混合させて使いがちなので、気をつけよう。

関数型の多用

これずっと思ってたんだけど、やっぱり関数型って読みづらいよね?
自分が初心者すぎるだけ? シンプルなmapとかだったらわかるけど、複雑化してくると一気にわからなくなる。
コードの行数は確かに少なくなるけど、コードを読む時間は増えてしまうのでカッコつけずにfor文で回そうよ。
そんなに処理時間気にしないだろ、自分のサービスは!って言いたくなる。

2.4.1 ドキュメンテーション

クラスにもドックストリングは使えるのか。
関数ではドックストリングさん、雰囲気で使ってたけど、@paramsと@returnを書くのが一般的なのかな?
今度OSSとか見てみてチェックしてみよう。

できれば毎日ちょっとずつ進めていきたい。
備忘録としてここに残していく。
最後にどこかにちゃんとまとめよう。