 Google C++ Style Guidebe an appropriate error handling response. Oth- erwise, consider a factory function or Init() method. Avoid Init() methods on objects with no other states that affect which public methods may be called Exceptions are the only way for a constructor to fail. We can simulate this with a factory function or an Init() method, but these require heap allocation or a new “invalid” state, respectively. • Exceptions are created with a braced initializer list, known as a braced-init-list in the C++ grammar. Here are a few examples of its use. // Vector takes a braced-init-list of elements. vector Google C++ Style Guidebe an appropriate error handling response. Oth- erwise, consider a factory function or Init() method. Avoid Init() methods on objects with no other states that affect which public methods may be called Exceptions are the only way for a constructor to fail. We can simulate this with a factory function or an Init() method, but these require heap allocation or a new “invalid” state, respectively. • Exceptions are created with a braced initializer list, known as a braced-init-list in the C++ grammar. Here are a few examples of its use. // Vector takes a braced-init-list of elements. vector- v{"foo", "bar"}; // 0 码力 | 83 页 | 238.71 KB | 1 年前3
 Google Python Style GuideSquare(3) >>> sq.area 9 >>> sq.perimeter 12 >>> sq.area = 16 >>> sq.side 4 >>> sq.perimeter 16 """ def __init__(self, side): self.side = side def __get_area(self): """Calculates the 'area' property.""" return boolean indicating if we like SPAM or not. eggs: An integer count of the eggs we have laid. """ def __init__(self, likes_spam=False): """Inits SampleClass with blah.""" self.likes_spam = likes_spam self.eggs also defines special methods that implement the default semantics of objects including __new__, __init__, __delattr__, __getattribute__, __setattr__, __hash__, __repr__, and __str__. Strings link Use0 码力 | 30 页 | 94.81 KB | 1 年前3 Google Python Style GuideSquare(3) >>> sq.area 9 >>> sq.perimeter 12 >>> sq.area = 16 >>> sq.side 4 >>> sq.perimeter 16 """ def __init__(self, side): self.side = side def __get_area(self): """Calculates the 'area' property.""" return boolean indicating if we like SPAM or not. eggs: An integer count of the eggs we have laid. """ def __init__(self, likes_spam=False): """Inits SampleClass with blah.""" self.likes_spam = likes_spam self.eggs also defines special methods that implement the default semantics of objects including __new__, __init__, __delattr__, __getattribute__, __setattr__, __hash__, __repr__, and __str__. Strings link Use0 码力 | 30 页 | 94.81 KB | 1 年前3
共 2 条
- 1













