1. 程式人生 > >寫出漂亮程式碼的7種方法

寫出漂亮程式碼的7種方法

很多開發者不願意使用空白,就好像這要收費一樣。我在此並非刻意地新增空白,粗魯地打斷程式碼的連貫性。在實際編寫程式碼的過程中,會很容易地發現在什麼地方加入空白,這不但美觀而且讓讀者易懂,如下:

1 function getSomeAngle() {

2    // Some code here then

3    radAngle1 = Math.atan(slope(center, point1));

4    radAngle2 = Math.atan(slope(center, point2));

5

6    firstAngle = getStartAngle(radAngle1, point1, center);

7    secondAngle = getStartAngle(radAngle2, point2, center);

8

9    radAngle1 = degreesToRadians(firstAngle);

10    radAngle2 = degreesToRadians(secondAngle);

11

12    baseRadius = distance(point, center);

13    radius = baseRadius + (lines * y);

14

15    p1["x"] = roundValue(radius * Math.cos(radAngle1) + center["x"]);

16    p1["y"] = roundValue(radius * Math.sin(radAngle1) + center["y"]);

17

18    pt2["x"] = roundValue(radius * Math.cos(radAngle2) + center["y"]);

19    pt2["y"] = roundValue(radius * Math.sin(radAngle2) + center["y");

20    // Now some more code

21 }