私はシミュレーションコードで使用されている物理的/数学的な量の良い命名体系を確立したいと思います。次の例を考えてみましょう:物理量の名前をPythonで
from math import *
class GaussianBeamIntensity(object):
"""
Optical intensity profile of a Gaussian laser beam.
"""
def __init__(self, intensity_at_waist_center, waist_radius, wavelength):
"""
Arguments:
*intensity_at_waist_center*: The optical intensity of the beam at the
center of its waist in W/m^2 units.
*waist_radius*: The radius of the beam waist in meters.
*wavelength*: The wavelength of the laser beam in meters.
"""
self.intensity_at_waist_center = intensity_at_waist_center
self.waist_radius = waist_radius
self.wavelength = wavelength
self._calculate_auxiliary_quantities()
def _calculate_auxiliary_quantities(self):
# Shorthand notation
w_0, lambda_ = self.waist_radius, self.wavelength
self.rayleigh_range = pi * w_0**2/lambda_
# Generally some more quantities could follow
def __call__(self, rho, z):
"""
Arguments:
*rho*, *z*: Cylindrical coordinates of a spatial point.
"""
# Shorthand notation
I_0, w_0 = self.intensity_at_waist_center, self.waist_radius
z_R = self.rayleigh_range
w_z = w_0 * sqrt(1.0 + (z/z_R)**2)
I = I_0 * (w_0/w_z)**2 * exp(-2.0 * rho**2/w_z**2)
return I
命名スキームを使用すると、数式が比較的短いままであること可読性と簡潔な表記(間バランスをとるために、物理的性質(物性、関数の引数など)のために提案する何一貫した)?上記の例を改善していただけますか?または、より良い体系を提案するか?
PEP8のガイドラインに従い、「愚かな一貫性は少しの心のホッコブリン」であることを覚えておくとよいでしょう。伝統的な80文字の行の長さに従いながら、わかりやすい名前に固執するのは難しいようです。
ありがとうございます!
あなたは*本当に*とにかく80文字の制限から、どのような値を得るのですか?あなたのコードを電子メールで送って、1980年の@ –
@Klausに戻ってしまうようなものではありません。たとえば、画面上にさらに多くのファイルを開くことができ、実際に長い行を1つだけ収容する必要がなく、画面の不動産を一杯にすることができます。 (例えば、私の2つの画面上のxmonadでは、約12個のウィンドウがタイル状に並べられています;ほとんどが90文字以上でコードがトリミングされます) –
@jimbob私はあなたの意見を見ていますが、私はIDEを使用します。 –