スキップしてメイン コンテンツに移動

投稿

BDD (Behavior-driven Development) について

最近BDD (Behavior-driven Development) についてエンジニア仲間で話題になったので、記事を書こうと思い立ちました。 結論から言うと、筆者は、BDDには懐疑的な立場です。 BDDとは(あくまで筆者の理解) BDD (Behavior-driven Development)は、 ビジネス側が書いたシナリオ(誰が、どんなとき、どの条件で、どうしする)や仕様をもとに、コンピュータで実行可能なテストを自動生成し、システム側がそのテストを通るようにシステム開発をしていく方法です。ビジネス側がBehaviorを書く際の言語は、ビジネス側でもできるだけ理解できる自然言語風の、BDD専用言語です。 BDDのメリットは、 ビジネス側の仕様記述から、システムテストを作成できるので、ビジネス側の望んでいるシステムを素早く正確につくれる ビジネス側の仕様変更がダイレクトにシステムテストに反映されるので、仕様変更にも強い ことかと思います(筆者の理解)。 筆者がBDDを支持しない理由 1番目の理由は、そもそもビジネス側の期待している振る舞い (Behavior) 自体が曖昧で、それを論理的に整合性のある仕様に落とし込むことが、システム開発で最も困難な場合が多いと感じるからです。 ビジネス側の期待している振る舞いが簡潔で、論理的であればあるほとプログラムとして記述しやすくなるはずなので、その場合は、システム側だけのTDD (Test Driven Development) 方式で開発を進められると思います。 BDDの記述方法も所詮は論理記述の一種なので、それが綺麗に書ける人はそもそも、エンジニアとしての才能があるので、普通に綺麗な仕様を書ける場合が多いのではないでしょうか。 2番目の理由はBDDの記述言語です。 自然言語風にするのはいいのですが、自然言語に近づければ近づけるほど、論理の矛盾や文法チェックが必要になり意味解釈が面倒になると思います(自然言語処理が簡単であれば、自然言語処理という研究分野は存在しないはず)。 もちろんBDDの記述言語はプログラム言語を自然言語風にしたシナリオ記述言語なので、意味解釈の面で問題が出ることはないと思います。 しかしそうすると、BDDの記述言語には表現に制約があり、最終

Reduce Code & Focus on Return On Code

Value of reducing code Reducing amount of code is one of the MOST REQUIRED & IMPORTANT skill in real software development workplace, especially in team based software development. Most of the case, reducing code is much more valuable than writing code! Why doesn't any computer science teach this MOST important skill! Let me point out benefits of reducing code: The less code makes programmer be the easy to understand project! The amount of code they should read is lesser! Fledgling developer easy to understand! You don't have to write much test code! Complexity should tend to be lower! Code duplication tends to be less! Prevent regression! You can only care about code which really lively works! Put it all together, These benefits finally leads "Improve code maintainability" and "Reduce maintenance cost" . I mention just in case - reducing code doesn't mean you should merge a few "for loop" lines into single line. My pri

Java: Identify Country From IP Address

Identify Country From IP Address Many people sometimes would like to identify country from IP address when you check access log or something. Most of the people google with keywords like "ip address country" or "whois ip" or something, and then use the internet service which they find. In this post, I will show you program for identifying country from IP address. I wrote the program in Java, but if you an average developer you can easily translate into the program language you prefer. Using File Provided by RIR IP address is allocated, registered and managed by regional internet registry ( RIR ). There are five organization based on covering region: African Network Information Centre (AfriNIC): Africa American Registry for Internet Numbers (ARIN): the United States, Canada, several parts of the Caribbean region, and Antarctica. Asia-Pacific Network Information Centre (APNIC): Asia, Australia, New Zealand, and neighboring countries Latin America and

Java: Coloned IPv6 Address To BigInteger

IPv6 Address to Long I have written code for converting coloned IPv6 IP address to BigInteger value in Java. I have already written similar code for IPv4 IP address (see this post ). The function is useful when you compare IP addresses based on numeric magnitude relationship. Java Code public static BigInteger colonIpV6_to_BigInteger(String colonedIP) { String[] addrArray = colonedIP.split(":", -1); BigInteger num = BigInteger.ZERO; BigInteger block = BigInteger.valueOf(65536); for (int i = 0; i < addrArray.length; i++) { if(!addrArray[i].equals("")) { int power = 8-i; BigInteger value = BigInteger.valueOf(Long.parseLong(addrArray[i], 16) % 65536L); value = value.multiply(block.pow(power)); num = num.add(value); } } return num; } Here is an example. // following code output "22170076769632982771575277020213308075606016"

Java: Dotted IPv4 Address To BigInteger

IPv4 Address to Long I have written code for converting dotted IPv4 IP address to BigInteger value in Java. This code is inspired by PHP's ip2long function. The function is useful when you compare IP addresses based on numeric magnitude relationship. Java Code public static BigInteger dotIPv4_to_BigInteger(String dottedIP) { String[] addrArray = dottedIP.split("\\."); BigInteger num = BigInteger.ZERO; BigInteger block = BigInteger.valueOf(256); for (int i = 0; i < addrArray.length; i++) { int power = 3-i; BigInteger value = BigInteger.valueOf(Integer.parseInt(addrArray[i]) % 256); value = value.multiply(block.pow(power)); num = num.add(value); } return num; } Here is an example. // following code output "2071690107" System.out.println(dotIPv4_to_BigInteger("123.123.123.123"));

Measure Code & Improve Team Based Software Development

Introduction In this post, I'm going to write about "Why & How to measure your code of software project. And improve it." I am going to mainly write about this topic from the static code analysis point. Why Measure? There are number of reasons to measure your code. For me especially following reasons (or intentions). Daily Health Check Keep code base clean See impact on entire code base by your code change Detect problems as soon as possible Feel improvement! Let every team members show what happens Monitor test result status Follow coding standard Especially in team based software development, a lot of people change code for different task. And each developer is hard to know what each developer change the code for what purpose. If the source code measurement is public for everyone, it helps everyone to know affect of entire project which the other developers make. What to Measure? There are a lot of measurement is proposed but from static

PHP Symfony 1.4 Action plus View Rendering PHPUnit Test

Symfony 1.4 Action plus View Rendering PHPUnit Test I wrote test case for executing action and rendering view test. However testing action plus final rendering result is quite not easy because you need to understand how Symfony 1.4 framework handles web request and rendering model to view internally. I have investigated in the framework a bit and found a solution. Please see the test case example in the next section. Code <?php $basePath = dirname(__FILE__).'/../../../../apps/your_app_name/modules/'; $modulePaths = glob($basePath.'*', GLOB_ONLYDIR); foreach($modulePaths as $modulePath) { require_once $modulePath.'/actions/actions.class.php'; } class ActionsTest extends PHPUnit_Framework_TestCase { public function testActions() { // create stub web request $request = $this->createStubfWebRequest(); // action you would like to test. // you should pass module and action name refelctively $actions = new TargetActions($this