28. 27
どっちが良いコード?
public class PerformanceTester
{
public statc final TcpConnectionSimulator wifi = new TcpConnectionSimulator(
500, /*Kbps*/
80, /*msec latency*/
200,/*jitter*/
1/*packet loss %*/);
public static final TcpConnectionSimulator t3_fibar = new TcpConnectionSimulator(
45000,
10,
0,
0);
public static final TcpConnectionSimulator cell = new TcpConnectionSimulator(
100,
400,
250,
5);
}
(A)
public class PerformanceTester
{
// TcpConnectionSimulator(throughput, latency, jitter, packet_loss)
// [kbps] [ms] [ms] [%]
public statc final TcpConnectionSimulator wifi =
new TcpConnectionSimulator(500, 80, 200,1);
public static final TcpConnectionSimulator t3_fibar =
new TcpConnectionSimulator(45000, 10, 0, 0);
public static final TcpConnectionSimulator cell =
new TcpConnectionSimulator(100, 400, 250, 5);
}
(B)
4つの引数を持つTcpConnectionSimulatorクラスを使って、3つのインスタンスを作る。
1.接続速度(kbps) 2.平均遅延時間(msec) 3.遅延時間(msec) 4.パケットロス率(percent,%)
29. 28
どっちが良いコード?
public class PerformanceTester
{
public statc final TcpConnectionSimulator wifi = new TcpConnectionSimulator(
500, /*Kbps*/
80, /*msec latency*/
200,/*jitter*/
1/*packet loss %*/);
public static final TcpConnectionSimulator t3_fibar = new TcpConnectionSimulator(
45000,
10,
0,
0);
public static final TcpConnectionSimulator cell = new TcpConnectionSimulator(
100,
400,
250,
5);
}
(A)
public class PerformanceTester
{
// TcpConnectionSimulator(throughput, latency, jitter, packet_loss)
// [kbps] [ms] [ms] [%]
public statc final TcpConnectionSimulator wifi =
new TcpConnectionSimulator(500, 80, 200,1);
public static final TcpConnectionSimulator t3_fibar =
new TcpConnectionSimulator(45000, 10, 0, 0);
public static final TcpConnectionSimulator cell =
new TcpConnectionSimulator(100, 400, 250, 5);
}
(B)
4つの引数を持つTcpConnectionSimulatorクラスを使って、3つのインスタンスを作る。
1.接続速度(kbps) 2.平均遅延時間(msec) 3.遅延時間(msec) 4.パケットロス率(percent,%)
シルエットを意識する
30. 29
どっちが良いコード?
CheckFullName("doug Adams","Mr.Doglas Adams","");
CheckFullName("Jake Brown","Mr. Jake Brown III","");
CheckFullName("No such Guy","","no match found");
CheckFullName("John","","more than one result");
CheckFullName("doug Adams" ,"Mr.Doglas Adams" ,"");
CheckFullName("Jake Brown" ,"Mr. Jake Brown III" ,"");
CheckFullName("No such Guy" ,"" ,"no match found");
CheckFullName("John" ,"" ,"more than one result");
(A)
(B)
31. 30
どっちが良いコード?
CheckFullName("doug Adams","Mr.Doglas Adams","");
CheckFullName("Jake Brown","Mr. Jake Brown III","");
CheckFullName("No such Guy","","no match found");
CheckFullName("John","","more than one result");
CheckFullName("doug Adams" ,"Mr.Doglas Adams" ,"");
CheckFullName("Jake Brown" ,"Mr. Jake Brown III" ,"");
CheckFullName("No such Guy" ,"" ,"no match found");
CheckFullName("John" ,"" ,"more than one result");
(A)
(B) 私のチームでは、こっちを「良いコード」と定義・・・できるかどうか微妙。
シルエットを意識する
54. 53
どっちが良いコード?
<script>
var f = function(){
for( i = 0; i < 10 ; i += 1 )...
};
f();
</script>
<script>
alert(i);
</script>
(A)
<script>
var f = function(){
for( var i = 0; i < 10 ; i += 1 )...
};
f();
</script>
<script>
alert(i);
</script>
(B)
←10が表示される ←undefined
55. 54
どっちが良いコード?
<script>
var f = function(){
for( i = 0; i < 10 ; i += 1 )...
};
f();
</script>
<script>
alert(i);
</script>
(A)
<script>
var f = function(){
for( var i = 0; i < 10 ; i += 1 )...
};
f();
</script>
<script>
alert(i);
</script>
(B)
私のチームでは、こっちを
「良いコード」と定義します。
変数のスコープを縮める
←10が表示される ←undefined