プリンキピア

第9章ソフトウェア工学

Refactoringリファクタリング
As has been stated earlier, refactoring is the process of restructuring source code without changing its functionality. It is not specific to reuse, though refactoring can involve reuse. Typically, refactoring consists of making a series of elementary changes called micro-refactorings, such as:
英語のヒント
先に述べたように、リファクタリングとは、機能を変えずにソースコードの構造を組み直すプロセスである。再利用だけに特有のものではないが、再利用を伴うことはある。通常は、マイクロリファクタリングと呼ばれる、次のような基本的な変更を積み重ねる。
• Rename an attribute, which changes the name of an attribute to a new one that better corresponds to its purpose.
• 属性の名前変更:属性の名前を、その目的によりよく合う新しい名前に変更する。
• Rename a method, which changes the name of a method to a new one that better corresponds to its purpose.
• メソッドの名前変更:メソッドの名前を、その目的によりよく合う新しい名前に変更する。
• Extract a class, which moves a part of an existing class into a new class.
英語のヒント
• クラスの抽出:既存のクラスの一部を、新しいクラスへ移す。
• Extract a method, which moves a fragment of code into a new method.
• メソッドの抽出:コードの一部を、新しいメソッドへ移す。
• Inline a method, which replaces a method call by its body. This is typically used only for very short methods.
英語のヒント
• メソッドのインライン化:メソッドの呼び出しを、その本体で置き換える。通常は、ごく短いメソッドにだけ使う。
• Move a method, which moves a method to a more appropriate class.
• メソッドの移動:メソッドを、より適切なクラスへ移す。
• Move a field, which moves a field to a more appropriate class.
• フィールドの移動:フィールドを、より適切なクラスへ移す。
• Remove dead code, which removes code that never executes.
• デッドコードの削除:決して実行されないコードを取り除く。
• Replace a literal with a symbolic constant, which replaces a magic value with a named constant.
英語のヒント
• リテラルの記号定数への置換:マジック値を、名前の付いた定数で置き換える。
• Change method parameters, which adds or removes method parameters.
• メソッドのパラメーター変更:メソッドのパラメーターを追加または削除する。
• Substitute an algorithm, which replaces one algorithm with another. This is typically done to improve performance of the software system.
英語のヒント
• アルゴリズムの置換:一つのアルゴリズムを別のものに置き換える。通常は、ソフトウェアシステムの性能を高めるために行う。
You can apply these micro-refactorings manually, but it is more common to perform them in an IDE. Modern IDEs provide support for some refactoring, and you can often apply a selected refactoring by activating an appropriate menu item, as shown in Figure 9.26.
これらのマイクロリファクタリングは手作業で適用できるが、IDEで実行するほうが一般的である。現在のIDEは、一部のリファクタリングを支援している。図9.26に示すように、適切なメニュー項目を選ぶだけで、選択したリファクタリングを適用できる場合が多い。
Figure 9.26

rendered in NetBeans by Sun Microsystems; attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典

Figure 9.26 In the NetBeans IDE, the action of renaming a method falls under the Refactor menu item. (rendered in NetBeans by Sun Microsystems; attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図9.26 NetBeans IDEでは、メソッドの名前変更は「Refactor」メニュー項目の中にある。(Sun MicrosystemsのNetBeansで描画。帰属:Rice University、OpenStax著作権、CC BY 4.0ライセンス。)
Returning to the concept of reuse, one of the benefits of refactoring is that functions, classes, and other chunks of code can be extracted from other parts of the code. These can then be reused by placing them in libraries, by incorporating them into a framework to be used by other developers, or by constructing an interface to access them.
英語のヒント
再利用の概念に話を戻すと、リファクタリングの利点の一つは、関数、クラス、その他のコードのまとまりを、コードの別の部分から抽出できることである。その後、ライブラリに入れたり、ほかの開発者が使うフレームワークに組み込んだり、それらにアクセスするインターフェースを構築したりして、再利用できる。
Software Licensingソフトウェアのライセンス
When software engineers design and develop software for an organization, that software and all its code generally belong to the organization. This means the source code and functionality cannot be used by others without permission. This permission is typically controlled by a software license. The type of license can be determined by those who created the software or commissioned its creation. Two of the most common categories for defining software reuse are closed source and open source. Proprietary, or closed-source software, is a form of licensing that prohibits access to underlying source code. This type of software is typically developed for organizations or as software to be sold. It can be used to protect software that might contain proprietary information or intellectual property within the code. Free and open-source (FOSS), or open-source software, is a form of software licensing that provides access to the underlying code and generally allows the code to be reused and modified It is important to read the license terms of any software code used. It is also important to make sure that, if software is to be shared, it is clear as to what license will be applied to both the use of the software and its code. If a license is not provided with code, then the code is generally protected under copyright rules.
英語のヒント
ソフトウェアエンジニアが組織のためにソフトウェアを設計・開発すると、そのソフトウェアとコード全体は、一般に組織に帰属する。つまり、ほかの人は許可なく、そのソースコードや機能を利用できない。この許可は通常、ソフトウェアライセンスによって管理する。ライセンスの種類を決めるのは、ソフトウェアを作った人や、制作を依頼した人である。ソフトウェアの再利用を定める、最も一般的な二つの種類は、クローズドソースとオープンソースである。プロプライエタリーソフトウェア、すなわちクローズドソースソフトウェアは、基になっているソースコードへのアクセスを禁止するライセンスの形態である。通常は、組織向け、または販売用のソフトウェアとして開発する。コードに専有情報や知的財産を含む可能性のあるソフトウェアを保護するために使うことができる。自由かつオープンソースのソフトウェア(FOSS)、すなわちオープンソースソフトウェアは、基となるコードへのアクセスを認め、一般に再利用や変更も認めるライセンスの形態である。使うソフトウェアコードのライセンス条件は、必ず読むことが重要である。ソフトウェアを共有する場合は、ソフトウェアの利用とそのコードの双方に、どのライセンスが適用されるのかを明確にすることも重要である。コードにライセンスが付いていなければ、一般に著作権の規則によって保護される。
Free and Open-Source Software (FOSS)自由かつオープンソースのソフトウェア(FOSS)
Free software (sometimes called libre software) is software distributed under the terms that provide users with the following four freedoms:
英語のヒント
自由ソフトウェア(libre softwareと呼ばれることもある)は、ユーザーに次の四つの自由を認める条件の下で配布されるソフトウェアである。
1. the freedom to run the software for any purpose
1. どのような目的でもソフトウェアを実行する自由
2. the freedom to study how the software works and modify it
2. ソフトウェアの仕組みを調べ、変更する自由
3. the freedom to redistribute the software
3. ソフトウェアを再配布する自由
4. the freedom to improve the software and release the improvements to the public
4. ソフトウェアを改善し、改善内容を一般に公開する自由
The freedom to study how the software works and modify it and the freedom to improve the software can hardly be fulfilled without source code, and so these freedoms more or less imply that source code of the software must be available.
英語のヒント
ソフトウェアの仕組みを調べて変更する自由と、改善する自由は、ソースコードなしではほとんど実現できない。そのため、これらの自由は、おおむね、そのソフトウェアのソースコードを利用できなければならないことを意味する。
Free here refers to liberty, not price (you may be required to pay for free software). Software that is distributed gratis is referred to as freeware, and it rarely comes with source code. Open-source software is software distributed under a license that grants users the right to use, study, modify, and distribute the software and its source code. It does not mean that software must be gratis, although in many cases it is the case. Today, it is common that open-source projects provide their source code via a public repository on the Internet that allows anybody to contribute.
英語のヒント
ここでいうfreeは価格ではなく自由を指す。自由ソフトウェアでも、支払いを求められる場合がある。無料で配布されるソフトウェアはフリーウェアと呼ばれ、ソースコードが付くことはまれである。オープンソースソフトウェアは、ソフトウェアとそのソースコードを利用し、調べ、変更し、配布する権利をユーザーに認めるライセンスの下で配布される。無料でなければならないという意味ではないが、多くの場合は無料である。現在、オープンソースプロジェクトは、誰でも貢献できるインターネット上の公開リポジトリを通じてソースコードを提供するのが一般的である。
The benefits of FOSS are as follows:
FOSSの利点は次のとおりである。
• Improved quality and reliability: Community involvement in open-source projects can lead to better quality and more reliable software due to a wider range of users and developers identifying and fixing bugs.
• 品質と信頼性の向上:オープンソースプロジェクトにコミュニティが参加すると、より幅広いユーザーや開発者がバグを発見して修正するため、品質や信頼性の高いソフトウェアにつながりうる。
• Lower development costs: Open-source software can benefit from community contributions, reducing development costs for companies and organizations.
• 開発費用の低減:オープンソースソフトウェアはコミュニティの貢献から恩恵を受け、企業や組織の開発費用を減らせる。
• Innovation: Openness and collaboration can accelerate innovation as developers can build upon existing open-source code.
英語のヒント
• 革新:開発者が既存のオープンソースコードを土台に開発できるため、開放性と協力によって革新を加速できる。
Some projects that were developed as free and/or open-source software can be categorized as follows:
自由ソフトウェア、オープンソースソフトウェア、またはその両方として開発されたプロジェクトの一部は、次のように分類できる。
• Operating systems
• オペレーティングシステム
◦ Linux: An open-source operating system, which is distributed in so-called distributions. The distributions are referred to by name such as Debian, Fedora, Ubuntu, RedHat, and SUSE, and they can be commercial (paid) or community-driven (gratis). The Linux kernel is licensed under GNU General Public License, version 2, which makes it a free and open-source software.
英語のヒント
◦ Linux:ディストリビューションと呼ばれる形で配布される、オープンソースのオペレーティングシステムである。ディストリビューションにはDebian、Fedora、Ubuntu、RedHat、SUSEなどの名前があり、商用(有料)のものと、コミュニティ主導(無料)のものがある。LinuxカーネルはGNU一般公衆ライセンスのバージョン2で許諾されているため、自由かつオープンソースのソフトウェアとなる。
◦ Android: A free and open-source operating system developed by a consortium sponsored by Google. It is based on the Linux kernel and other open-source software, and it aims primarily to touchscreen mobile devices, such as smartphones and tablets. Android is the most common operating system (not only on mobile phones).
英語のヒント
◦ Android:Googleが支援する企業連合によって開発された、自由かつオープンソースのオペレーティングシステムである。Linuxカーネルと、その他のオープンソースソフトウェアに基づき、主にスマートフォンやタブレットなど、タッチスクリーンを備えたモバイル機器を対象とする。Androidは、携帯電話だけに限らず、最も広く使われているオペレーティングシステムである。
• Development tools
• 開発ツール
◦ NetBeans IDE: An open-source IDE that started as a student project with the goal of creating an IDE for the Java programming language. Now it belongs to Apache Software Foundation and also supports other programming languages, such as PHP, C, C++, and JavaScript.
◦ NetBeans IDE:Javaプログラミング言語用のIDEを作ることを目指した、学生のプロジェクトから始まったオープンソースのIDEである。現在はApache Software Foundationに属し、PHP、C、C++、JavaScriptなどのほかの言語も支援する。
◦ Eclipse IDE: An open-source integrated development environment that started at IBM and is now managed by the Eclipse Foundation.
◦ Eclipse IDE:IBMで始まり、現在はEclipse Foundationが管理する、オープンソースの統合開発環境である。
◦ GNU Compiler Collection (GCC): A free and open-source compiler (or more precisely a suite of compilers) that supports various programming languages, hardware platforms, and operating systems. It is the standard compiler included in many Linux distributions.
英語のヒント
◦ GNU Compiler Collection(GCC):さまざまなプログラミング言語、ハードウェアプラットフォーム、オペレーティングシステムを支援する、自由かつオープンソースのコンパイラーである。より正確にはコンパイラーの一式であり、多くのLinuxディストリビューションに標準コンパイラーとして含まれている。
• Web browsers
• Webブラウザー
◦ Google Chrome: A no-cost web browser developed by Google. Although most source code of Google Chrome comes from free and open-source software, it is licensed as proprietary freeware. It is available on Windows, Linux, Android, macOS, and iOS.
◦ Google Chrome:Googleが開発した無料のWebブラウザーである。ソースコードの大半は自由かつオープンソースのソフトウェアに由来するが、プロプライエタリーなフリーウェアとして許諾されている。Windows、Linux、Android、macOS、iOSで利用できる。
◦ Mozilla Firefox: A free and open-source web browser developed by Mozilla Foundation. It is available on Windows, Linux, macOS, and Android.
◦ Mozilla Firefox:Mozilla Foundationが開発した、自由かつオープンソースのWebブラウザーである。Windows、Linux、macOS、Androidで利用できる。
• Programming languages
• プログラミング言語
◦ OpenJDK: A free and open-source implementation of the Java Platform, Standard Edition. Many other distributions of the Java Platform, such as Amazon Corretto, are based on OpenJDK.
◦ OpenJDK:Java Platform, Standard Editionの、自由かつオープンソースの実装である。Amazon Correttoなど、ほかの多くのJava Platformの配布版も、OpenJDKに基づく。
◦ C#: A modern cross-platform programming language initially developed by Microsoft. Both the C# language and the current (as of 2014) Microsoft C# compiler are open source.
英語のヒント
◦ C#:Microsoftが最初に開発した、現代的なクロスプラットフォームのプログラミング言語である。C#言語と、現在の(2014年時点の)Microsoft C#コンパイラーは、どちらもオープンソースである。
◦ Python: A modern programming language is that is completely open source, freely usable and distributable, even for commercial use, making it extremely popular with businesses around the world.
英語のヒント
◦ Python:完全にオープンソースで、商用利用を含め自由に利用・配布できる現代的なプログラミング言語であり、世界中の企業で非常に人気が高い。
• Application servers
• アプリケーションサーバー
◦ Payara Server: An open-source application server, with paid support options.
◦ Payara Server:有料のサポートも選べる、オープンソースのアプリケーションサーバーである。
While some open-source software is entirely free, FOSS projects can have successful business models. It may seem that open-source software development does not bring any benefits to software publishing companies, but community involvement leads to better quality and higher reliability of the software and lower cost of development. Many software companies that moved to open-source development adequately modified their business model and instead of selling software, they charge the customer for providing additional services. For example, Payara Server is an open-source application server for Jakarta Enterprise Edition applications. The server is gratis, but companies that use Payara Server for mission-critical applications can pay for support, which allows them to consult a team of software engineers at any time. In addition, they receive monthly releases with bug fixes and security alerts. Many companies that embrace open-source development focus on providing value-added services, such as technical support, training, or custom development, around the core open-source product.
英語のヒント
完全に無料のオープンソースソフトウェアもあるが、FOSSプロジェクトは成功する事業モデルを持つこともできる。オープンソースの開発はソフトウェアを提供する企業に何の利益ももたらさないように見えるかもしれないが、コミュニティの参加によって、品質と信頼性が向上し、開発費用が下がる。オープンソース開発へ移行した多くのソフトウェア企業は、事業モデルを適切に変更し、ソフトウェアの販売に代えて、追加サービスの提供に対して顧客に料金を請求している。たとえばPayara Serverは、Jakarta Enterprise Editionアプリケーション用のオープンソースのアプリケーションサーバーである。サーバーは無料だが、業務の遂行に欠かせないアプリケーションにPayara Serverを使う企業は、有料のサポートを受けられる。それによって、いつでもソフトウェアエンジニアのチームに相談できる。また、バグ修正を含む毎月のリリースと、セキュリティに関する警告も受け取る。オープンソース開発を採用する多くの企業は、中核となるオープンソース製品の周辺で、技術サポート、研修、個別の要望に応じた開発などの付加価値サービスを提供することに力を入れている。
It is important for companies and developers to pay attention to the following:
企業と開発者は、次の点に注意を払うことが重要である。
• Software licensing considerations: Understanding software licenses is crucial for both software users and developers. While many people accept End User Licensing Agreements (EULAs) when installing software on their personal computers and devices, it is important that software engineers understand that these are legal agreements. As such, when using software to build solutions, it is important to understand what the licensing allows.
英語のヒント
• ソフトウェアライセンスに関する考慮事項:ソフトウェアライセンスを理解することは、利用者と開発者の双方にとって極めて重要である。多くの人は、自分のコンピューターや機器にソフトウェアをインストールするとき、エンドユーザー使用許諾契約(EULA)に同意する。ソフトウェアエンジニアは、これが法的な契約だと理解することが重要である。そのため、ソフトウェアを使って仕組みを構築するときには、ライセンスが何を認めているかを理解する必要がある。
• Using open-source software: Software developers should be aware of the license terms associated with any FOSS they use to ensure compliance.
英語のヒント
• オープンソースソフトウェアの利用:ソフトウェア開発者は、条件を守るために、使うFOSSに付随するライセンス条件を把握しておくべきである。
• Distributing software: Additionally, when distributing software, it is important to make sure that an included license defines how you or the organization that owns the software wants it used and protected. Choose a license that aligns with your project’s goals and how you want your software to be used and distributed.
英語のヒント
• ソフトウェアの配布:ソフトウェアを配布するときには、所有する本人または組織が望む使用方法と保護のあり方を、添付するライセンスが定めていることも重要である。プロジェクトの目標と、望む使用・配布の方法に合うライセンスを選ぼう。
FOSS is a powerful development model that fosters collaboration, innovation, and cost-effective software creation. While security considerations should also be factored in, open-source software plays a vital role in the tech industry.
英語のヒント
FOSSは、協力、革新、費用対効果の高いソフトウェア制作を促す、力強い開発モデルである。セキュリティ上の考慮事項も織り込む必要はあるが、オープンソースソフトウェアは技術産業で重要な役割を果たしている。