私はいくつかのコードを調べて、問題や改善および変更できるものを見つけました (これは宿題ですが、この質問はタスク自体とは関係ありません)。コードの一部は次のとおりです。
Function CheckIfSameCell(ByVal FirstCellPosition As CellReference, ByVal SecondCellPosition As CellReference) As Boolean
Dim InSameCell As Boolean
InSameCell = False
If FirstCellPosition.NoOfCellsSouth = SecondCellPosition.NoOfCellsSouth And FirstCellPosition.NoOfCellsEast = SecondCellPosition.NoOfCellsEast Then
InSameCell = True
End If
CheckIfSameCell = InSameCell
End Function
関数名に割り当てることができるのに、なぜInSameCell
is 変数が作成されるのか理解できませんCheckIfSameCell
か?
または、次のように return ステートメントを使用しますか?
Function CheckIfSameCell(ByVal FirstCellPosition As CellReference, ByVal SecondCellPosition As CellReference) As Boolean
If FirstCellPosition.NoOfCellsSouth = SecondCellPosition.NoOfCellsSouth And FirstCellPosition.NoOfCellsEast = SecondCellPosition.NoOfCellsEast Then
Return True
End If
Return False
End Function
If
読みやすさを向上させるために、ステートメント内の式を直接返さないことは理解できます。
関数名に戻り値を割り当てても関数が終了しないことはわかっていますが、Return は終了しますが、それは単なる人のスタイルですか、それとも最初のバージョンに利点がありますか (IMO、2 番目の方が読みやすい)?