凪瀬 Blog
Programming SHOT BAR

目次

Blog 利用状況
  • 投稿数 - 260
  • 記事 - 0
  • コメント - 48909
  • トラックバック - 192
ニュース
広告
  • Java開発者募集中
  • 経歴不問
  • 腕に自信のある方
  • 富山市内
  • (株)凪瀬アーキテクツ
アクセサリ
  • あわせて読みたい
凪瀬悠輝(なぎせ ゆうき)
  • Java技術者
  • お茶好き。カクテル好き。
  • 所属は(株)凪瀬アーキテクツ
  • Twitter:@nagise

書庫

日記カテゴリ

 

ホビープログラミングと業務でのプログラミングの一番の違いは、 記述したコードと他者との関わり方ではないでしょうか。
他人が書いたコードを自分が修正する、自分の書いたコードを他人が修正する、なんてことは日常茶飯事です。 設計さえも自分の思惑と違う方向にいくことがしばしば。 人材不足のIT業界ですから、せっかく綺麗に設計したのにぐちゃぐちゃにされることもあります。

究極の利己主義は利他的

人間は未来予測のできる動物です。子供から大人になるにつれ、 自分の選択の影響をより後半に、より長期的に予測できるように訓練されていきます。
そしてこの能力を使って自分にふりかかるであろう災厄を事前に回避し、 より幸福を得られるようにしようとするわけです。つまるところ利己的に利用しているのですね。

利己的であるというのは生物の本質のようなものだと思います。 他者を押しのけてでも生きようとしない種族は早々に地球という舞台から姿を消してしまったことでしょう。 これだけの歴史の中で今現在を生きている種が生存に対して飽くなき欲求を持っていないはずがありません。

人間のような社会性をもった種では、ある程度の利他的行動をとります。 これは自己犠牲とか欺瞞などではなく、協調して群れを作ることが自分にとって利益だからこそです。
「情けは人のためならず」とはよく言ったものです。 人のために情けをかけるのではない、自分に戻ってくるから人にはよくしておきなさい。 これは利己のために利他的であれという格言に他なりません。

防衛的プログラミング

バグを生み出すのは人に他なりません。コーディングしなければバグは生まれないのです。 業務用のプログラミングではスキルレベルのさまざまな人がコードを触ることになります。 ここで、プロジェクトの平和を願うなら、拙いプログラミングによってバグが仕込まれることが ないように他者の動向に気を配りましょう。そう、利己のための利他なのです。

防衛的なプログラミングとは、何から防衛的なのでしょうか?
プログラマの最大の敵、バグからの防衛に他なりません。
バグは仕込まれるものです。そして、潜むものです。防衛的プログラミングでは

  • バグの潜む隙間をあらかじめ潰しておく
  • バグが潜んでいたときに早期にあぶりだせるようにする
  • バグが仕込まれないように警告する

といったところに注視して、バグの少ないプログラムを書こうとするものです。

バグはヒューマンエラーによって容易にもぐりこんできます。 うっかり間違えたときに、間違いをコンパイラに指摘してもらえるように工夫するとどうでしょう? 正しい使い方をしない限り先に進めない、そうバグの潜む隙間を目張りしてしまうのです。
そのためにメソッドのアクセスレベルや、強い型付けであることを利用します。

コンパイラの時点で発見できると楽なのですが、実行してみるまで分からないバグもたくさんあります。 コンパイラで100%除去できるなら実行時例外なんて存在はなくてもいいわけです。 実行時にはバグを検知したらすばやく実行時例外をthrowしてバグを知らせます。 潜ませたままでは存在に気づきません。早期にあぶりだしましょう。

潜んでいるバグをどれだけ潰したとしても、後から後から供給されるようでは埒が開きません。 バグが仕込まれないように注意点は警告しましょう。 ソースコードレベルでコメントで注意を促すといったものから、 プロジェクトメンバーへの啓蒙まで含めて考える必要があります。 バグの供給を減らした上で除去を効率化すれば、プロジェクトがクリーンになるはずです。

こういったところに気を配った丁寧なプログラミングを重ねることで、 バグの住みにくいプロジェクトにしましょう。 そうすれば、あなた自身がデスマーチを歩む確率を少しでも減らすことが出来ます。 自分が蒔いたバグの種を自分で萌芽させて憤ることも少なくなることでしょう。 未来の自分の幸せのために、ほんの少し工夫するだけです。

次回以降は具体的な防衛手法をお届けします。 サンプルコードはJavaでの記述ですが、他の言語でも応用できるはずです。

投稿日時 : 2007年8月17日 11:49
コメント
  • # re: 防衛的プログラミング
    裏口
    Posted @ 2007/08/17 17:28
    >次回以降は具体的な防衛手法をお届けします。

    wktk
  • # qhTWbiaqsCpcDzlc
    http://crorkz.com/
    Posted @ 2014/08/28 9:20
    tj2Ty7 There is noticeably a bundle to identify about this. I think you made some good points in features also.
  • # love bracelet replica replica
    lyywiyjoh@aol.com
    Posted @ 2015/07/30 11:40
    Is it the light or are you turning grey? Can you recommend a root touch-up? I’ve seen a few greys in my hair but too scared to pull them in case 3 more come to its funeral
    love bracelet replica replica http://www.guard-bracelet.com/
  • # cartier love bracelet 16 replica
    ehcismno@aol.com
    Posted @ 2015/07/30 19:53
    Hi, Neat post. There is a problem with your web site in internet explorer, would test this… IE still is the market leader and a good portion of people will miss your fantastic writing due to this problem.
    cartier love bracelet 16 replica http://www.girlslovebangle.com/this-kind-of-as-cartier-love-bracelet/
  • # price cartier love bracelet replica
    bsxuzkbc@aol.com
    Posted @ 2015/08/20 10:25
    iTrader1 Livestream 31.12.2012
    price cartier love bracelet replica http://www.luxcartierroadster.com/
  • # chanel tasche schwarz replica
    hpejqea@aol.com
    Posted @ 2015/09/05 12:03
    Curieux que personne n’ait suggéré de (re)lire « On liberty » de John Stuart Mill, le texte fondateur, à mon sens, de tout ce qu’on peut dire d’intelligent sur la liberté en général et celle d’expression en particulier.
    chanel tasche schwarz replica http://www.replicasbag.net/de/-c87_90/
  • # replique rolex france
    qjjizkmm@aol.com
    Posted @ 2015/09/17 20:04
    Very descriptive article, I liked that a lot. Will there be a part 2?
    replique rolex france http://www.finewristwatchshop.com/fr/
  • # love ring yellow for sale
    delkcitcheceefsiculufivzm@hotmal.com
    Posted @ 2017/07/03 3:14
    A wrestler since you were twelve? I’m even more impressed. Any medals?
    love ring yellow for sale http://www.amoregioielli.ru/en/imitation-cartier-yellow-gold-plated-love-ring-for-sale-p734/
  • # Hi there! Do you know if they make any plugins to help with Search Engine Optimization? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good success. If you know of any please share. Kudos!
    Hi there! Do you know if they make any plugins to
    Posted @ 2019/04/10 9:40
    Hi there! Do you know if they make any plugins to
    help with Search Engine Optimization? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good
    success. If you know of any please share.
    Kudos!
  • # Hi would you mind sharing which blog platform you're using? I'm going to start my own blog soon but I'm having a difficult time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems differe
    Hi would you mind sharing which blog platform you'
    Posted @ 2019/07/18 23:09
    Hi would you mind sharing which blog platform you're using?

    I'm going to start my own blog soon but I'm having a difficult
    time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design and style seems different then most blogs and
    I'm looking for something unique.
    P.S Apologies for being off-topic but I had to ask!
  • # This site certainly has all the information and facts I needed about this subject and didn't know who to ask.
    This site certainly has all the information and fa
    Posted @ 2019/08/13 23:42
    This site certainly has all the information and facts I needed about
    this subject and didn't know who to ask.
  • # Piece of writing writing is also a excitement, if you know then you can write or else it is difficult to write.
    Piece of writing writing is also a excitement, if
    Posted @ 2022/03/25 7:12
    Piece of writing writing is also a excitement, if you know then you can write or else it is difficult to
    write.
  • # Piece of writing writing is also a excitement, if you know then you can write or else it is difficult to write.
    Piece of writing writing is also a excitement, if
    Posted @ 2022/03/25 7:13
    Piece of writing writing is also a excitement, if you know then you can write or else it is difficult to
    write.
  • # Piece of writing writing is also a excitement, if you know then you can write or else it is difficult to write.
    Piece of writing writing is also a excitement, if
    Posted @ 2022/03/25 7:14
    Piece of writing writing is also a excitement, if you know then you can write or else it is difficult to
    write.
  • # Piece of writing writing is also a excitement, if you know then you can write or else it is difficult to write.
    Piece of writing writing is also a excitement, if
    Posted @ 2022/03/25 7:15
    Piece of writing writing is also a excitement, if you know then you can write or else it is difficult to
    write.
タイトル
名前
Url
コメント