東方算程譚

Oriental Code Talk ── επιστημηが与太をこく、弾幕とは無縁のシロモノ。

目次

Blog 利用状況

ニュース

著作とお薦めの品々は

著作とお薦めの品々は
東方熱帯林へ。

あわせて読みたい

わんくま

  1. 東京勉強会#2
    C++/CLI カクテル・レシピ
  2. 東京勉強会#3
    template vs. generics
  3. 大阪勉強会#6
    C++むかしばなし
  4. 東京勉強会#7
    C++むかしばなし
  5. 東京勉強会#8
    STL/CLRによるGeneric Programming
  6. TechEd 2007 @YOKOHAMA
    C++・C++/CLI・C# 適材適所
  7. 東京勉強会#14
    Making of BOF
  8. 東京勉強会#15
    状態遷移
  9. 名古屋勉強会#2
    WinUnit - お気楽お手軽UnitTest

CodeZine

  1. Cで実現する「ぷちオブジェクト指向」
  2. CUnitによるテスト駆動開発
  3. SQLiteで組み込みDB体験(2007年版)
  4. C++/CLIによるCライブラリの.NET化
  5. C# 1.1からC# 3.0まで~言語仕様の進化
  6. BoostでC++0xのライブラリ「TR1」を先取りしよう (1)
  7. BoostでC++0xのライブラリ「TR1」を先取りしよう (2)
  8. BoostでC++0xのライブラリ「TR1」を先取りしよう (3)
  9. BoostでC++0xのライブラリ「TR1」を先取りしよう (4)
  10. BoostでC++0xのライブラリ「TR1」を先取りしよう (5)
  11. C/C++に対応した、もうひとつのUnitTestFramework ─ WinUnit
  12. SQLiteで"おこづかいちょう"
  13. STL/CLRツアーガイド
  14. マージ・ソート : 巨大データのソート法
  15. ヒープソートのアルゴリズム
  16. C++0xの新機能「ラムダ式」を次期Visual Studioでいち早く試す
  17. .NETでマンデルブロ集合を描く
  18. .NETでマンデルブロ集合を描く(後日談)
  19. C++/CLI : とある文字列の相互変換(コンバージョン)
  20. インテルTBBによる選択ソートの高速化
  21. インテルTBB3.0 によるパイプライン処理
  22. Visual C++ 2010に追加されたSTLアルゴリズム
  23. Visual C++ 2010に追加されたSTLコンテナ「forward_list」
  24. shared_ptrによるObserverパターンの実装
  25. .NETでマンデルブロ集合を描く(番外編) ── OpenCLで超並列コンピューティング
  26. StateパターンでCSVを読む
  27. 状態遷移表からStateパターンを自動生成する
  28. 「ソートも、サーチも、あるんだよ」~標準C++ライブラリにみるアルゴリズムの面白さ
  29. インテルTBBの同期メカニズム
  30. なぜsetを使っちゃいけないの?
  31. WPFアプリケーションで腕試し ~C++でもWPFアプリを
  32. C++11 : スレッド・ライブラリひとめぐり
  33. Google製のC++ Unit Test Framework「Google Test」を使ってみる
  34. メールでデータベースを更新するココロミ
  35. Visitorパターンで遊んでみたよ
  36. Collection 2題:「WPFにバインドできる辞書」と「重複を許す検索set」
  37. Visual C++ 2012:stateless-lambdaとSQLiteのぷち拡張
  38. 「Visual C++ Compiler November 2012 CTP」で追加された6つの新機能

@IT

  1. Vista時代のVisual C++の流儀(前編)Vista到来。既存C/C++資産の.NET化を始めよう!
  2. Vista時代のVisual C++の流儀(中編)MFCから.NETへの実践的移行計画
  3. Vista時代のVisual C++の流儀(後編) STL/CLRによるDocument/Viewアーキテクチャ
  4. C++開発者のための単体テスト入門 第1回 C++開発者の皆さん。テスト、ちゃんとしていますか?
  5. C++開発者のための単体テスト入門 第2回 C++アプリケーションの効率的なテスト手法(CppUnit編)
  6. C++開発者のための単体テスト入門 第3回 C++アプリケーションの効率的なテスト手法(NUnit編)

AWARDS


Microsoft MVP
for Visual Developer - Visual C++


Wankuma MVP
for いぢわる C++


Nyantora MVP
for こくまろ中国茶

Xbox

Links

記事カテゴリ

書庫

日記カテゴリ

ちがうだろぉ!?

ネタ元 → ぼけ損ねたエントリにつっこみ損ねた件

イベントハンドラ名は
 イベント センダ名、アンダースコア、およびイベント名を組み合わせた
 標準名前付け規則を使用します。(あくまで推奨です。)
 例: Private Sub member_DisplayNameChanged(....)

ゴーマンかますのを許していただけるなら、
こんなケッタイな名前付け規則を推奨すんなよ」と。

たとえば、だ。腕をマムシに噛まれたとするわ。

class 兵士 : 国民 {
  public 兵士() {
    腕.Onマムシに噛まれた += new 噛まれたハンドラ(腕_マムシに噛まれた);
  }
  private void 腕_マムシに噛まれた() {
    傷口をナイフで切り裂き
    急いで口で吸え
  }
}

...違うだろ。そのメソッド名は違うだろ
メソッド名は"なにをする"かを表す名前であるべきで、
"デキゴト"の名前であってあっちゃならんだろ。

class 兵士 : 国民 {
  public 兵士() {
    腕.On毒蛇に噛まれた += new 噛まれたハンドラ(対毒蛇応急処置); // ※
  }
  private void 対毒蛇応急処置() {
    傷口をナイフで切り裂き
    急いで口で吸え
  }
}

でなくちゃならんだろ。
こうしておけば腕噛まれようが太腿噛まれようが、
マムシが噛もうががハブが噛もうがメソッド名は安定するわな。

"デキゴト"とそれが起きたら"なにをする"かの対応は
イベントとハンドラを対応付けたんとこで表現されてるやんか。

void ボタン_押された() { 歌う }

なんてコード書いといて、お客さんのわがままで歌わす条件が
コロコロ変わるたんびにメソッド名を書き換えろってか!?

# と、キレーゴトを抜かしてみる ^^;

投稿日時 : 2007年10月24日 13:15

コメントを追加

# re: ちがうだろぉ!? 2007/10/24 13:23 とりこびと

正直なところ・・・自分でも違和感バリバリです。>名前付け規則

おっしゃられるとおり「何をするか」がメソッド名であってほしいと思っています。

といいつつも Visual Studio が自動生成するコードのメソッド名を変更しないことがおおい現実。orz

# re: ちがうだろぉ!? 2007/10/24 13:38 επιστημη

うんうん。

さりとてIDEが"なにをする"かを察してくれるほど
賢くも薄気味悪くもないので:

class 兵士 : 国民 {
 public 兵士() {
  腕.Onマムシに噛まれた +=
   new 噛まれたハンドラ(腕_マムシに噛まれた);
 }
 private void 腕_マムシに噛まれた() {
  対マムシ応急処置();
 }
 private void 対マムシ応急処置() {
  傷口をナイフで切り裂き
  急いで口で吸え
 }
}

ってなワンクッションかますことがしばしば。

# re: ちがうだろぉ!? 2007/10/24 14:26 シャノン

ちなみに、この命名規則は(C#も)VB6をひきずっていて、VB6にはHandles句が無かったので、イベントハンドラ名だけがオブジェクトとメソッドを結びつけるものでした。…たぶん。

# re: ちがうだろぉ!? 2007/10/24 15:39 とりこびと

おや?消えてる?w

# re: ちがうだろぉ!? 2007/10/24 15:58 επιστημη

ふぇ?

# re: ちがうだろぉ!? 2007/10/24 17:05 とりこびと

あ、じゃんぬさんのコメントありませんでしたっけ?(^^;

# re: ちがうだろぉ!? 2007/10/24 17:30 επιστημη

あー、バケバケのがくっついてたんで消したんですけど、
じゃんぬさんには失礼なことしちまったかすら。
再投下よろしくっす > じゃんぬさん

# re: ちがうだろぉ!? 2007/10/24 19:08 Imabeppu

イベントハンドラとか、コールバック関数とかは、
漠然とそういう名前の方がしっくりきてしまいます。
( おかしいんだろうか…… ^^; )

「背中をぽんとたたかれたら走ってね」というとき、
その人には「背中をたたかれた」ということが知らされて、
それを受けて「走れ」と指令を自分自身に出すような。
そうしとくと、「背中をぽんとたたかれたら走ったあとに歌ってね」もできるし。

最初の例ならこんな感じかしら。

class 兵士 : 国民 {
public 兵士() {
腕.Onマムシに噛まれた += new 噛まれたハンドラ(腕_マムシに噛まれた);
}
private void 腕_マムシに噛まれた() {
対毒蛇応急処置();
}
private void 対毒蛇応急処置() {
傷口をナイフで切り裂き
急いで口で吸え
}
}

# re: ちがうだろぉ!? 2007/10/24 19:32 RUN

そもそも、リアクション(イベント)とメソッド(アクション)を同列に扱おうと言う事が全ての間違いと言う気もします。

イベントってのはそもそも、発生した事象(トリガー)を受け取る事が目的でそれに対するリアクションを決める場所で、アクションそのものをする場所ではないよね?(間違ってたらゴメン)

VB表記になるけどこんな感じ?(シグネチャ省略)

private sub 咬まれた() Handles 咬んだのはマムシ,噛んだのは小島よ○お
dim 気分 as string = 痛みを我慢(痛さ)
call 治療する(気分)
end sub

private function 痛みを我慢(どの位の痛さ) as string
Select どの位の痛さ
case とても痛い
return "我慢できない"
case すこし痛い
return "我慢できる"
case へたこいた~
return "でもそんなの関係ねぇ~"
case else
return "実は痛くない"
End Select
end function

private sub 治療する(気分)
Select 気分
case "我慢できない"
call 病院へ行く()
……
case "我慢できる"
call 薬を塗る()
……
case "でもそんなの関係ねぇ~"
call オッパッピ~()
……
case else
……
End Select
end sub

# re: ちがうだろぉ!? 2007/10/24 19:59 επιστημη

んむ、そぉね。
少なくともイベントハンドラそれ自体にイベントセンダ名をくっつけちゃうのはヤですねぇ。
複数のイベントを捕まえるハンドラに名前が付けられんくなるし。

どこを噛まれたか・どう噛まれたかはハンドラの引数で判断できるだろから、ハンドラ名は(名前の重複が起こらぬならば) "噛まれた" でいいよねぇ。

# re: ちがうだろぉ!? 2007/10/24 21:08 Imabeppu

んだんだ。 > RUNさん

# re: ちがうだろぉ!? 2007/10/24 21:13 Imabeppu

どうするのがよいのか、なんだかもやもやします。

ハンドラ名は「噛まれた」でいいのかどうか。

電卓はボタンが押されたハンドラは「押された」なのか。
数字ボタンと電源ボタンのハンドラはやっぱり分けた方がよいのではないのか。
そうすると、「数字押された」「電源押された」になってしまうのか。
おもちゃのような電卓があって、押された数字によっていろいろなことが起こるのなら、「[1] 押された」「[2] 押された」になってしまうのか。

ここらへんが「名前の重複が起こらぬならば」になりますか?
もやもや

# re: ちがうだろぉ!? 2007/10/24 22:03 επιστημη

んー、そこらへんは各人のもやもや次第なんかも知れません。

ぶっちゃけWin32-message-loopみたく:

private void なにかが起こった(Msg m) {
 switch ( m.WPARAM ) {
 case WM_COMMAND:
  ...
}

でもいいわけだし。

# write an opinion essay a16cbh 2022/09/09 0:38 Charlosmox


Regards! I enjoy it. https://definitionessays.com/ write my essay service

# how to write dissertation j98pnd 2023/03/06 12:40 EugeneSib


Thanks a lot! Fantastic information!
persuasive essay help https://essayservicehelp.com high school versus college essay https://cheapessaywriteronlineservices.com

# college entry essay q183aw 2023/03/06 12:59 Gregorysaipt

You actually suggested this really well!
custom writing services https://quality-essays.com essay rewriter https://essaywriting4you.com

# dissertation project y854xf 2023/03/07 3:43 EugeneSib


Fantastic advice. Appreciate it.
law essay writing https://topswritingservices.com effective essay writing https://researchpaperwriterservices.com

# custom dissertation writing services r59wzo 2023/03/09 7:58 Gregorysaipt

You said that adequately!
writing help for students https://topswritingservices.com what is a good essay writing service https://researchproposalforphd.com

# thesis length z71gtx 2023/03/10 8:50 EugeneSib


Reliable stuff. Thanks!
dissertation def https://domyhomeworkformecheap.com writing a literary analysis essay https://helpwithdissertationwriting.com

# college personal essay f498yz 2023/03/12 5:23 EugeneSib


Cheers! Good information.
education dissertation topics https://essaywritingservicelinked.com community service essay sample https://helpwritingdissertation.com

# how to write a good compare contrast essay x91atj 2023/03/14 1:17 EugeneSib


Terrific stuff, Many thanks.
hiring writer https://payforanessaysonline.com pay for essay cheap https://phdthesisdissertation.com

# Exceptional blog! 4 2023/05/09 19:08 Lemuelcreby

Recently, stumbled upon your weblog and I have to mention that I'm very impressed with the quality of your articles. An article that piqued my interest was not only enlightening but also captivating and absorbing, and I just had to share my thoughts.

Your devotion to providing a helpful resource for your readers is truly commendable. It is not often that one finds a website that not only provides helpful information but also presents it in a way that is simple to understand and grasp.

The post in question was particularly well-prepared and informative. It was evident that much effort went into gathering and presenting the data. I appreciated how it was presented in a way that was both compelling and easy to follow. The investigation that went into creating the post was apparent, and it made the content all the more informative.

As someone who is always striving to enhance and learn, I found the post to be extremely helpful. It contained useful suggestions and recommendations that I can apply to my own pursuits. I can't wait to put them into practice and see the results for myself. The practical applications of the suggestions presented in the post are sure to be of great advantage to many readers.

Additionally, your writing is praiseworthy. It was not only informative, but also entertaining to read. The way you presented the information made it easy to understand and absorb. The tone of the post was captivating and kept me interested from beginning to end.

Taking everything into account, I would like to express my gratitude for the outstanding asset you have built on this blog. The dedication you show to providing valuable material to your readers is really commendable.

I am struck by the excellence of your articles and the energy that goes into creating it. Rarely I encounter a blog that not only provides useful information but additionally delivers it in a way that is simple to grasp and absorb.

The post that grabbed my interest was not only educational but additionally engaging. I just had to share my thoughts about it. The practical applications of the notions presented in the article are sure to be of great advantage to a lot of readers.

As someone who strives for constant betterment and learning, I came across the article exceptionally valuable. It had useful tips and advice that I can utilize to my own activities. I cannot wait to apply them and see the outcomes for myself.

If you're in search of a beneficial aid that supplies fascinating and instructive writing, I highly suggest examining
my blog site https://www.twitch.tv/vikaletova. Resolute to offering advantageous information and relevant hints, you are likely to uncover something which will amplify your survival and aid you in achieving your ambitions. Don't wait, drop in and find out what you could gain.

Additionally, I liked your writing style. It was not just educational but also enjoyable to go through. The manner you presented the facts made it easy to comprehend and absorb.

# The plugins developed for WordPress 2023/05/09 21:16 Justas

The plugins developed for WordPress serve to enhance the features and functions of a WordPress website, allowing you to build your awesome and functional site https://t.me/wpigaming/648 Customise WordPress with powerful, professional and intuitive fields.

# natural remedies for ed https://edpillsotc.store/# - best pills for ed 2023/10/08 4:48 EdPills

natural remedies for ed https://edpillsotc.store/# - best pills for ed

# paxlovid buy https://paxlovid.bid/ paxlovid india 2023/10/26 2:32 Paxlovid

paxlovid buy https://paxlovid.bid/ paxlovid india

# buy doxycycline without prescription https://doxycycline.forum/ doxy 2023/11/25 16:22 Doxycycline

buy doxycycline without prescription https://doxycycline.forum/ doxy

# farmacia online miglior prezzo https://farmaciait.pro/ acquisto farmaci con ricetta 2023/12/04 12:46 Farmacia

farmacia online miglior prezzo https://farmaciait.pro/ acquisto farmaci con ricetta

タイトル  
名前  
URL
コメント