シミュレーション コードで使用される物理/数学量の適切な命名スキームを確立したいと考えています。次の例を検討してください。
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 文字の制限に従いながら、わかりやすい名前に固執するのは難しいようです。
前もって感謝します!