中の技術日誌ブログ

C#とC++/CLIと
VBと.NETとWindowsで戯れる
 

目次

Blog 利用状況

ニュース

自己紹介

東京でソフトウェアエンジニアをやっています。
お仕事大募集中です。
記事執筆や、講師依頼とかでも何でもどうぞ(*^_^*)
似顔絵 MSMVPロゴ
MSMVP Visual C# Since 2004/04-2013/03

記事カテゴリ

書庫

日記カテゴリ

00-整理

01-MSMVP

VBのreturnと関数名での戻りどちらの方がいいのか?

VBは7よりReturn構文が追加されて、C系のReturn を利用できるようになりました。

Visual Basic .NET 移行ガイド 第 4 章 スムーズな移行のためのポイント ~プログラミング編~ プロシージャ
http://www.microsoft.com/japan/msdn/net/vbtransitionguide/chapter4/chapter4_11.asp

には以下のように書かれています。

>また、Return キーワードを利用すると、実行コードを生成するときに最適化がより適切に行なわれるため、パフォーマンスの面でも優れているといえます。関数名を Return に変えるだけでよいのですから、ぜひ置き換えを行なってください。

果たしてそうでしょうか?

アセンブラ的に解釈すると戻り値はスタックに帰り値を押し込めてreturnするだけでしかありません。

Public Shared Function ret() As Integer
Return 0
End Function
Public Shared Function fnc() As Integer
fnc = 0
End Function

これらは等価であると思います。

さてIL検証しましょう。

.method public static int32 ret() cil managed
{
      // Code Size: 7 byte(s)
      .maxstack 1
      .locals (
            int32 num1)
      L_0000: nop 
      L_0001: ldc.i4.0 
      L_0002: stloc.0 
      L_0003: br.s L_0005
      L_0005: ldloc.0 
      L_0006: ret 
}
.method public static int32 fnc() cil managed
{
      // Code Size: 5 byte(s)
      .maxstack 1
      .locals (
            int32 num1)
      L_0000: nop 
      L_0001: ldc.i4.0 
      L_0002: stloc.0 
      L_0003: ldloc.0 
      L_0004: ret 
}

驚いたことにretの方がコスト高になっています。

ただし、exit functionしていないので確かに平等ではないかもしれません。

.method public static int32 fnc() cil managed
{
      // Code Size: 8 byte(s)
      .maxstack 1
      .locals (
            int32 num1)
      L_0000: nop 
      L_0001: ldc.i4.0 
      L_0002: stloc.0 
      L_0003: nop 
      L_0004: br.s L_0006
      L_0006: ldloc.0 
      L_0007: ret 
}

nopが増えてしまいました。

もちろんこの解析は平等ではありません。なぜならあまりにも単純すぎるからです。

ということでこの論理のどちら側の情報でもいいので教えてください。

#もちろんパフォーマンス以外のメリット/デメリットではありません。
##VB7は今までやってなかったのでこの移行ガイドはノーチェックでした。(^^

投稿日時 : 2005年2月13日 22:19

コメントを追加

# re: VBのreturnと関数名での戻りどちらの方がいいのか? 2005/02/13 23:47 ishisaka@bailey

VBのReturn文はいままと違って、そこで制御が呼び出し元に戻ってしまうので、戸惑う人も多いだろうと思うとともに、不必要なバグを抱え込むことになるかもと思ったり。

しかし構文がどんどんC系の言語と似てきていますが、本当にそれは望まれたことなのかって気もしてきます。

# re: VBのreturnと関数名での戻りどちらの方がいいのか? 2005/02/14 0:37 稍丼

デバッグでビルドすると,そうなんだけど,
リリースでビルドすると,なぜか逆転しますね...

#早くβ2でないかなぁ~

# re: VBのreturnと関数名での戻りどちらの方がいいのか? 2005/02/14 0:38 中 博俊

ふむ。
デバッグで見てました。(--;;
リリースで見ないとダメですね~

# re: VBのreturnと関数名での戻りどちらの方がいいのか? 2005/02/14 10:34 じゃんぬねっと

# 本当にネタにしちゃったのね。

パフォーマンスもさることながら、可読性を考えても、
Return を使うべきでしょう。(^-^*)

# re: VBのreturnと関数名での戻りどちらの方がいいのか? 2005/02/14 10:43 中 博俊

さーてそれはどうかな?
また次取り上げます。

# re: VBのreturnと関数名での戻りどちらの方がいいのか? 2005/02/14 13:39 じゃんぬねっと

それと、IL検証 の文字小さすぎ (w

# re: VBのreturnと関数名での戻りどちらの方がいいのか? 2005/02/14 13:45 中 博俊

直したよーん

# re: VBのreturnと関数名での戻りどちらの方がいいのか? 2005/02/14 16:38 入海

可読性+コードの管理の観点からReturnに一票。って投票するところじゃないか・・・

# re: VBのreturnと関数名での戻りどちらの方がいいのか? 2005/02/15 3:57 稍丼

そもそも,デフォルトの状態で,
デバッグとリリースのフォルダをちゃんとわけてないんだろ??
それがVBらしさなんだろうか? う~ん。わからん。

# Есть нормальные способы зароботка с помощью интернее? 2008/06/27 4:13 Dolphin_ukr

Всем здравствуйте,
подскажите, кто как зарабатывает на интернет?


# good sait 2008/09/12 10:22 jewellery

http://jewelry.myloger.com/

# Справочник организаций, фирм, предприятий, товаров и цен России 2008/10/22 16:05 Skylinetmk

Уважаемые Дамы и Господа!

У нас Вы найдете много всё по организациям,товарам и ценам по России. Российский государственный сайт. Актуальная информация для жителей и гостей России и мира, представленная в следующих разделах: новости, работа, погода, форум,каталог сайтов, знакомства, объявления, фото, адресный и телефонный справочник, недвижимость



# Софт, эротика, фильмы, игры - БЕСПЛАТНО! | Soft, ero, music - Free!!! 2008/10/23 23:21 kasmattaa

Посетите наш развлекательный сайт http://hornywarez.net На нем есть новые фильмы, музыка, скрипты, игры, картинки, обои, эротика фото, эротика видео, книги!
И все это для Вас БЕСПЛАТНО!

Welcome to our site http://hornywarez.net
U can see many FREE movies, soft, music, games, pictures, wallpapers, erotics, erotic video, books.

# Топик 3 2010/11/14 1:30 gen-p.ru

Каждому Доброе утро! Интересуетесь судьбой планеты или биологией? тогда вам сюда - http://gen-p.ru/19121020

# I'm truly enjoying the design and layout of your website. It's a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work! 2021/09/01 8:56 I'm truly enjoying the design and layout of your w

I'm truly enjoying the design and layout of your website.
It's a very easy on the eyes which makes it much more pleasant for me to come
here and visit more often. Did you hire out a developer to create your theme?
Superb work!

# I'm truly enjoying the design and layout of your website. It's a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work! 2021/09/01 8:57 I'm truly enjoying the design and layout of your w

I'm truly enjoying the design and layout of your website.
It's a very easy on the eyes which makes it much more pleasant for me to come
here and visit more often. Did you hire out a developer to create your theme?
Superb work!

# I'm truly enjoying the design and layout of your website. It's a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work! 2021/09/01 8:58 I'm truly enjoying the design and layout of your w

I'm truly enjoying the design and layout of your website.
It's a very easy on the eyes which makes it much more pleasant for me to come
here and visit more often. Did you hire out a developer to create your theme?
Superb work!

# I'm truly enjoying the design and layout of your website. It's a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work! 2021/09/01 8:59 I'm truly enjoying the design and layout of your w

I'm truly enjoying the design and layout of your website.
It's a very easy on the eyes which makes it much more pleasant for me to come
here and visit more often. Did you hire out a developer to create your theme?
Superb work!

# We're a group of volunteers and starting a new scheme in our community. Your web site provided us with valuable information to work on. You've done an impressive job and our entire community will be grateful to you. 2021/09/02 16:12 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 information to work on. You've done an impressive job and
our entire community will be grateful to you.

# We're a group of volunteers and starting a new scheme in our community. Your web site provided us with valuable information to work on. You've done an impressive job and our entire community will be grateful to you. 2021/09/02 16:13 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 information to work on. You've done an impressive job and
our entire community will be grateful to you.

# We're a group of volunteers and starting a new scheme in our community. Your web site provided us with valuable information to work on. You've done an impressive job and our entire community will be grateful to you. 2021/09/02 16:14 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 information to work on. You've done an impressive job and
our entire community will be grateful to you.

# We're a group of volunteers and starting a new scheme in our community. Your web site provided us with valuable information to work on. You've done an impressive job and our entire community will be grateful to you. 2021/09/02 16:15 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 information to work on. You've done an impressive job and
our entire community will be grateful to you.

# Why users still make use of to read news papers when in this technological globe all is presented on web? 2021/09/06 6:21 Why users still make use of to read news papers wh

Why users still make use of to read news papers when in this technological globe all is presented on web?

# Why users still make use of to read news papers when in this technological globe all is presented on web? 2021/09/06 6:22 Why users still make use of to read news papers wh

Why users still make use of to read news papers when in this technological globe all is presented on web?

# Why users still make use of to read news papers when in this technological globe all is presented on web? 2021/09/06 6:23 Why users still make use of to read news papers wh

Why users still make use of to read news papers when in this technological globe all is presented on web?

# Why users still make use of to read news papers when in this technological globe all is presented on web? 2021/09/06 6:24 Why users still make use of to read news papers wh

Why users still make use of to read news papers when in this technological globe all is presented on web?

# Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a bit, but instead of that, this is excellent blog. An excellent read. I will 2021/09/14 2:08 Its like you read my mind! You seem to know a lot

Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or
something. I think that you could do with a few pics
to drive the message home a bit, but instead of that,
this is excellent blog. An excellent read.

I will certainly be back. ps4 games https://bitly.com/3nkdKIi ps4

# Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a bit, but instead of that, this is excellent blog. An excellent read. I will 2021/09/14 2:09 Its like you read my mind! You seem to know a lot

Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or
something. I think that you could do with a few pics
to drive the message home a bit, but instead of that,
this is excellent blog. An excellent read.

I will certainly be back. ps4 games https://bitly.com/3nkdKIi ps4

# Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a bit, but instead of that, this is excellent blog. An excellent read. I will 2021/09/14 2:10 Its like you read my mind! You seem to know a lot

Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or
something. I think that you could do with a few pics
to drive the message home a bit, but instead of that,
this is excellent blog. An excellent read.

I will certainly be back. ps4 games https://bitly.com/3nkdKIi ps4

# Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a bit, but instead of that, this is excellent blog. An excellent read. I will 2021/09/14 2:11 Its like you read my mind! You seem to know a lot

Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or
something. I think that you could do with a few pics
to drive the message home a bit, but instead of that,
this is excellent blog. An excellent read.

I will certainly be back. ps4 games https://bitly.com/3nkdKIi ps4

# You actually make it appear really easy with your presentation however I find this topic to be actually something that I believe I'd by no means understand. It sort of feels too complicated and extremely broad for me. I am having a look forward in your 2021/09/14 11:24 You actually make it appear really easy with your

You actually make it appear really easy with your presentation however I find this topic to be actually something that I believe I'd
by no means understand. It sort of feels too complicated and extremely broad for me.
I am having a look forward in your next submit, I will attempt
to get the cling of it! quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# You actually make it appear really easy with your presentation however I find this topic to be actually something that I believe I'd by no means understand. It sort of feels too complicated and extremely broad for me. I am having a look forward in your 2021/09/14 11:25 You actually make it appear really easy with your

You actually make it appear really easy with your presentation however I find this topic to be actually something that I believe I'd
by no means understand. It sort of feels too complicated and extremely broad for me.
I am having a look forward in your next submit, I will attempt
to get the cling of it! quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# You actually make it appear really easy with your presentation however I find this topic to be actually something that I believe I'd by no means understand. It sort of feels too complicated and extremely broad for me. I am having a look forward in your 2021/09/14 11:26 You actually make it appear really easy with your

You actually make it appear really easy with your presentation however I find this topic to be actually something that I believe I'd
by no means understand. It sort of feels too complicated and extremely broad for me.
I am having a look forward in your next submit, I will attempt
to get the cling of it! quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# You actually make it appear really easy with your presentation however I find this topic to be actually something that I believe I'd by no means understand. It sort of feels too complicated and extremely broad for me. I am having a look forward in your 2021/09/14 11:27 You actually make it appear really easy with your

You actually make it appear really easy with your presentation however I find this topic to be actually something that I believe I'd
by no means understand. It sort of feels too complicated and extremely broad for me.
I am having a look forward in your next submit, I will attempt
to get the cling of it! quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# What's up to all, how is the whole thing, I think every one is getting more from this website, and your views are fastidious for new users. 2021/10/25 14:46 What's up to all, how is the whole thing, I think

What's up to all, how is the whole thing, I think
every one is getting more from this website, and your views are
fastidious for new users.

タイトル
名前
URL
コメント