Ognacの雑感

木漏れ日々

目次

Blog 利用状況

書庫

ギャラリ

出口は一箇所という規約

今時なんでと思うのですが。 「関数の出口であるReturnは、該当関数の最後に1箇所のみ配置すべし」という規約が生きているプロジェクトがありました。
(例1)Private Sub proc1()
        Dim a As Integer = 0
        Dim b As Integer = 3
        'いろいろ
        If a = 10 Then Return
        'いろいろ
        If b = 2 Then Return
        'いろいろ
        Return
    End Sub
このように記したら違反らしい。
(例2)Private Sub proc2()
        Do
            Dim a As Integer = 0
            Dim b As Integer = 3
            'いろいろ
            If a = 10 Then Exit Do
            'いろいろ
            If b = 2 Then Exit Do
            'いろいろ
            Exit Do
        Loop
        Return
    End Sub
れはOkだという。この判断基準が理解できません。例2)は Do/Loopが如何にも冗長だし、うっかりミスると無限Loopになる
for Loopや do while false にしても冗長さを感じます。ミスりやすい記述より規約を優先させるのは良くないでしょう。
 gotoが悪者扱いされた時、Gotoの変わりに Flag制御に置換したら、制御判定がスパゲッティになったという笑い話が過去にあります。

出口を一箇所にするならば
(例3) Private Sub proc()
        Try
            Dim a As Integer = 0
            Dim b As Integer = 3
            'いろいろ
            If a = 10 Then Return
            'いろいろ
            If b = 2 Then Return
            'いろいろ
            Return
        Finally
            MessageBox.Show("K")
        End Try
    End Sub
のように 、Finally句で対処できそうに思うのです。と指摘したところ......
「規約は随分以前に作られたもので。規約を変えるには相当な運動が必要で、開発に追われて、そのような暇はない。規約に従ってれば波風立たないのでそのほうか良い。」
「規約責任者に Try/Catch/Finally を理解してもらうのは困難だ。このスタイルでも困らないから放っていて。」
との返事を頂きました。
 今時のオープン系の開発現場で規約策定者が例外処理やFinallyを知らないのはモット問題でしょう。(この類の人が権力を持っているケースが多いのも事実なんですか....)
 この絵柄は本末転倒でしょう。効率のよい開発規約を作るのも開発作業の仕事の一部です。波風立てないのは短期的には良いでしょうが、中長期的にマイナスです。
開発者が効率を求めるのはソースコードだけではありません。システムの効率化に匹敵するくらい、規約の見直しも作業の進め方の一つで大事なことです。

投稿日時 : 2007年11月29日 0:19

Feedback

# re: 出口は一箇所という規約 2007/11/29 7:04 774RR

MISRA C の何番だったっけなー、その規約
真っ先に拒絶しますた。

# re: 出口は一箇所という規約 2007/11/29 8:24 774RR

14.7 だそうな。
http://www.softech.co.jp/mm_070801_firm.htm
ここでも「逸脱を許可」にしたそうな。まあ順当な判断といえよう

# re: 出口は一箇所という規約 2007/11/29 11:33 choir

>規約策定者が例外処理やFinallyを知らない
策定者どころか作業者でもさして珍しくないと思ってしまった。

>この類の人が権力を持っているケースが多い
だから、さくっと諦める。
プログラマとしてそれはどうよ?と言われると
心苦しいものはありますけど。
そゆ人が権力持ってると万事がそんな感じなので、
転職サイトを物色してみたりすると。(ぇー

# re: 出口は一箇所という規約 2007/11/29 12:05 凪瀬

転職は見捨てるという最終手段ですね・・・
改善の可能性がないとみたら妥当な決断かもしれません。

常の行動として、技術的な発言力が高まっていれば、ひとこと物申すこともできるのですが、
そういう対外的な地位を得るのはそれこそ時間がかかる話ですし。
こういうときばかりは権力が欲しくなりますね。

# re: 出口は一箇所という規約 2007/11/29 16:54 Ognac

>ここでも「逸脱を許可」にしたそうな。まあ順当な判断といえよう
同意
サイト紹介ありがとうございました。
>規約策定者が例外処理やFinallyを知らない

>策定者どころか作業者でもさして珍しくないと思ってしまった。
それは問題でしょ

>転職は見捨てるという最終手段ですね・・・
転職しても同じ雰囲気だったという話は良く聞きます。
>こういうときばかりは権力が欲しくなりますね。 Remove Comment 110866
 権力を取る前に飛び出してしまった自分....www

# re: 出口は一箇所という規約 2007/11/29 22:42 Jitta

かわらんね。どうして「関数」はダメで、「ループ」なら良いの?
ループも関数も、「処理のブロック」という意味では一緒です。あるブロックは「途中で抜けちゃダメ」。あるブロックは「途中で抜けても良いよ」。おかしいです。
ルールの意味を理解せずに使っているから、こんな変な実装を許可するし、「規約を変えるには相当な運動が必要」などという、ふざけた言葉が出てくるんですよ。
出口を一箇所にするなら、
If a=10 Then
Else
 ' いろいろ
 If b=2 Then
 Else
  ' いろいろ
 End If
End If
ですよ。

# re: 出口は一箇所という規約 2007/11/30 0:06 Ognac

>ループも関数も、「処理のブロック」という意味では一緒です。
たぶん、レビュー者は、別物と認識してそう。(想像ですが)
一緒と認識できるレベルだったら、こんな規約は改定していると思います。
一箇所ルールを適用すれば提示された例になりますね。でも、出口が一杯のほうが好きだなぁ

# re: 出口は一箇所という規約 2007/12/01 9:18 Jitta

他の所を引っ張ってて、かなりぶっきらぼうになっていました。ごめんなさい。

> でも、出口が一杯のほうが好きだなぁ
できれば、2箇所にしたい。
最初と最後の2箇所です。最初に複数の出口があることはあります。

とはいえ、途中で抜けることは、「これ以上、この中の処理はないよ」と明確に伝えることができますから、必要に応じてあるのも好きです。

# PFAQbPeopUZAmJW 2014/08/07 11:47 http://crorkz.com/

L33FJe Thanks so much for the article.Really looking forward to read more.

# WOW just what I was searching for. Came here by searching for C# 2018/10/05 14:07 WOW just what I was searching for. Came here by se

WOW just what I was searching for. Came here by searching for C#

# Wow, this paragraph is good, my younger sister is analyzing such things, so I am going to convey her. 2018/10/06 6:37 Wow, this paragraph is good, my younger sister is

Wow, this paragraph is good, my younger sister is analyzing such
things, so I am going to convey her.

# Good write-up. I certainly appreciate this website. Keep writing! 2018/10/18 2:50 Good write-up. I certainly appreciate this website

Good write-up. I certainly appreciate this website.
Keep writing!

# I am in fact grateful to the owner of this website who has shared this great post at at this time. 2018/11/14 23:27 I am in fact grateful to the owner of this website

I am in fact grateful to the owner of this website who has shared this great post at at this time.

# WzbxpxIzDuGbb 2018/12/17 11:51 https://www.suba.me/

MX0RtQ Roda JC Fans Helden Supporters van Roda JC Limburgse Passie

# I enjoy what you guys tend to be up too. This sort of clever work and reporting! Keep up the fantastic works guys I've added you guys to my own blogroll. 2019/03/22 1:09 I enjoy what you guys tend to be up too. This sort

I enjoy what you guys tend to be up too. This sort of clever work and reporting!

Keep up the fantastic works guys I've added you guys to my own blogroll.

# Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something. I think that you could do with some pics to drive the message home a little bit, but other than that, this is excellent blog. A great read. I'll c 2019/05/05 7:53 Its like you read my mind! You seem to know so muc

Its like you read my mind! You seem to know so much about this, like you wrote the book in it or something.
I think that you could do with some pics to drive the message home a little bit, but other than that,
this is excellent blog. A great read. I'll certainly be back.

# My partner and I stumbled over here from a different website and thought I may as well check things out. I like what I see so now i'm following you. Look forward to looking into your web page repeatedly. 2019/05/12 12:03 My partner and I stumbled over here from a differe

My partner and I stumbled over here from a different website and thought
I may as well check things out. I like what I see so now i'm following you.
Look forward to looking into your web page repeatedly.

# It's a pity you don't have a donate button! I'd certainly donate to this excellent blog! I suppose for now i'll settle for bookmarking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this site with my 2019/07/30 22:00 It's a pity you don't have a donate button! I'd ce

It's a pity you don't have a donate button! I'd certainly
donate to this excellent blog! I suppose for now i'll settle for bookmarking and adding your
RSS feed to my Google account. I look forward to fresh updates and will talk about this site with
my Facebook group. Talk soon!

# It's a pity you don't have a donate button! I'd certainly donate to this excellent blog! I suppose for now i'll settle for bookmarking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this site with my 2019/07/30 22:01 It's a pity you don't have a donate button! I'd ce

It's a pity you don't have a donate button! I'd certainly
donate to this excellent blog! I suppose for now i'll settle for bookmarking and adding your
RSS feed to my Google account. I look forward to fresh updates and will talk about this site with
my Facebook group. Talk soon!

# It's a pity you don't have a donate button! I'd certainly donate to this excellent blog! I suppose for now i'll settle for bookmarking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this site with my 2019/07/30 22:02 It's a pity you don't have a donate button! I'd ce

It's a pity you don't have a donate button! I'd certainly
donate to this excellent blog! I suppose for now i'll settle for bookmarking and adding your
RSS feed to my Google account. I look forward to fresh updates and will talk about this site with
my Facebook group. Talk soon!

# It's a pity you don't have a donate button! I'd certainly donate to this excellent blog! I suppose for now i'll settle for bookmarking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this site with my 2019/07/30 22:03 It's a pity you don't have a donate button! I'd ce

It's a pity you don't have a donate button! I'd certainly
donate to this excellent blog! I suppose for now i'll settle for bookmarking and adding your
RSS feed to my Google account. I look forward to fresh updates and will talk about this site with
my Facebook group. Talk soon!

# We're a group of volunteers and starting a new scheme in our community. Your web site provided us with valuable info to work on. You've done an impressive job and our entire community will be thankful to you. 2019/09/03 19:53 We're a group of volunteers and starting a new sch

We're a group of volunteers and starting a new
scheme in our community. Your web site provided us with valuable info to work
on. You've done an impressive job and our entire community will be thankful
to you.

# We're a group of volunteers and starting a new scheme in our community. Your web site provided us with valuable info to work on. You've done an impressive job and our entire community will be thankful to you. 2019/09/03 19:54 We're a group of volunteers and starting a new sch

We're a group of volunteers and starting a new
scheme in our community. Your web site provided us with valuable info to work
on. You've done an impressive job and our entire community will be thankful
to you.

# We're a group of volunteers and starting a new scheme in our community. Your web site provided us with valuable info to work on. You've done an impressive job and our entire community will be thankful to you. 2019/09/03 19:55 We're a group of volunteers and starting a new sch

We're a group of volunteers and starting a new
scheme in our community. Your web site provided us with valuable info to work
on. You've done an impressive job and our entire community will be thankful
to you.

# We're a group of volunteers and starting a new scheme in our community. Your web site provided us with valuable info to work on. You've done an impressive job and our entire community will be thankful to you. 2019/09/03 19:56 We're a group of volunteers and starting a new sch

We're a group of volunteers and starting a new
scheme in our community. Your web site provided us with valuable info to work
on. You've done an impressive job and our entire community will be thankful
to you.

# kuFWzWIHRwmlrlpTP 2021/07/03 1:27 https://waylonforbes.dreamwidth.org/profile

you can look here How do you password protect a Blogger blog on a custom domain?

# MOGUywNekYcmOXet 2021/07/03 2:57 https://amzn.to/365xyVY

Very informative blog article.Really looking forward to read more. Fantastic.

タイトル
名前
Url
コメント