Domain Modeling Made Functional (DevTernity 2022)Scott Wlaschin
(video at https://fsharpforfunandprofit.com/ddd/)
Statically typed functional programming languages encourage a very different way of thinking about types. The type system is your friend, not an annoyance, and can be used in many ways that might not be familiar to OO programmers. Types can be used to represent the domain in a fine-grained, self documenting way. And in many cases, types can even be used to encode business rules so that you literally cannot create incorrect code. You can then use the static type checking almost as an instant unit test — making sure that your code is correct at compile time. In this talk, we'll look at some of the ways you can use types as part of a domain driven design process, with some simple real world examples in F#. No jargon, no maths, and no prior F# experience necessary.
Domain Modeling Made Functional (DevTernity 2022)Scott Wlaschin
(video at https://fsharpforfunandprofit.com/ddd/)
Statically typed functional programming languages encourage a very different way of thinking about types. The type system is your friend, not an annoyance, and can be used in many ways that might not be familiar to OO programmers. Types can be used to represent the domain in a fine-grained, self documenting way. And in many cases, types can even be used to encode business rules so that you literally cannot create incorrect code. You can then use the static type checking almost as an instant unit test — making sure that your code is correct at compile time. In this talk, we'll look at some of the ways you can use types as part of a domain driven design process, with some simple real world examples in F#. No jargon, no maths, and no prior F# experience necessary.
The document discusses PHP performance and dives into the internals of how PHP works, including details on the Zend engine, compilation process involving lexing, parsing and compiling to opcodes, and execution through opcode interpretation by the virtual machine. It provides examples and tips on optimizing performance by reducing compilation overhead through opcode caching, profiling execution to find bottlenecks, and analyzing PHP functions at the C level to optimize system calls and memory usage.
Router is one of the most important feature or component in Web application framework,
ant it is also one of the performance bottlenecks of framework.
In this session, I'll show you how to make router much faster than ever.
The document discusses code changes and tests related to adding pagination parameters to an API for retrieving books from a database. It includes:
1) A test failure when trying to access books with a 'size' parameter to limit results.
2) Comments and code changes to the book service and API to support limiting results by adding a 'limit' parameter.
3) Logs and queries showing the updated SQL statement with a limit clause.
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策kwatch
The document discusses issues with the Test::More module for testing in Perl and proposes solutions. It notes that Test::More does not encourage writing tests based on specifications, does not structure tests well, and makes it hard to distinguish assertions. It recommends writing tests according to specifications rather than code, using structures like contexts and descriptions to organize tests, and printing output lines on a per-specification rather than per-assertion basis to improve readability. It also proposes functions like spec() and subtest() to help write more specification-based tests with Test::More.
Oktest - a new style testing library for Python -kwatch
Oktest is a new-style testing library for Python. It helps you to read & write tests very much. Oktest is available with (or without) standard 'unittest' module.
The document contains results from various benchmark tests measuring the performance of different programming languages and implementations like Node.js, Java, Python, and others. It includes graphs showing the time taken to complete tasks like string concatenation and list operations. The benchmarks also compare just-in-time compilers and tracing JIT performance for some languages.
I have something to say about the buzz word "From Java to Ruby"kwatch
The document summarizes a lightning talk given at RubyKaigi2008 about transitioning from Java to Ruby. It cautions that simply writing Ruby code does not mean thinking in Ruby. It argues that overemphasizing beginners and bragging about project size are misguided. The talk urges programmers to change their mindset and think for themselves rather than blindly following trends when adopting new languages and technologies.
The document discusses various techniques for optimizing the performance of embedded Ruby (ERuby) templates. It describes 7 iterations of improvements to "MyEruby" that reduced the processing time from over 69 seconds to under 1 second. The optimizations included avoiding line splitting, replacing parsing with patterns, tuning regular expressions, inline expansion and array buffers.
The document is a technical report from kuwata-lab.com copyrighted in 2007. It contains multiple graphs and tables comparing the performance of different template engines like Tenjin, ERB and Smarty. It also includes copyright notices on each page.
The document discusses modern object-relational mappers (ORMs) and their underlying technologies. It covers several key concepts:
1. Query objects allow building queries through method chaining rather than keyword arguments, abstracting SQL queries.
2. View-layer caching can be implemented through lazy loading to avoid tight coupling between controllers and views.
3. The N+1 problem, where querying dependent objects results in multiple queries, can be addressed through eager loading or strategic eager loading.
4. Ruby-to-SQL translation is enabled by overriding operators in Ruby to generate an abstract syntax tree, which can then be converted to SQL.
How to Make Ruby CGI Script Faster - CGIを高速化する小手先テクニック -kwatch
The document discusses ways to make Ruby CGI scripts faster. It explains that process invocation and library loading are the main reasons CGI scripts are slow. Various case studies are presented on optimizing code by lazy-loading libraries, avoiding unnecessary objects, and parsing query strings efficiently. Benchmark results show performance improvements from these techniques.
現地時間3月3日から10日にかけて、世界中のテレコムが注目するテクノロジーカンファレンスである「Mobile World Conference 2025」がバルセロナで開催されました。特に競争の激しいヨーロッパのマーケットでは、各社が生き残りをかけたイノベーションをたくさん生み出しています。5G/6G、エッジクラウド、新しい音声技術など、多くのキーワードが注目されています。
42. copyright(c) 2013 kuwata-lab.com all rights reserved.
委譲
機能の一部 or 全部を、他のオブジェクトに任せ
ること(丸投げ!)
class Foo {
private $m1;
function __constructor() {
$this->other = new OtherObj();
}
function hello(arg) {
$this->other->hello(arg);
}
.... 丸投げ!
44. copyright(c) 2013 kuwata-lab.com all rights reserved.
プロトタイプチェーン
## 委譲と同様に、探索先を自分で設定可能
this.__proto__ = new Foo();
## 継承と同様に、自動的に探索してくれる
$this.hello();
$this.__proto__.hello();
$this.__proto__.__proto__.hello();
◆ プロトタイプチェーンは、委譲と継承の間の子
委譲の柔軟性と、継承の利便性を合わせ持つ
(注)独自の見解です
45. copyright(c) 2013 kuwata-lab.com all rights reserved.
継承では $this が変わらない
1: class Foo {
2: function hello() { ... }
3: function main() {
4: ...; $this->hello(); ...;
5: }
6: }
7: class Bar extends Foo {
8: function hello() {...} // override
9: // main() はそのまま
10: }
11: $obj = new Bar();
12: $obj->main();
$this は Bar オブ
ジェクトのまま!
オーバーライドした
Bar#hello() が最終的に
呼び出される
難しい話なので、分から
なければ読み飛ばして!
46. copyright(c) 2013 kuwata-lab.com all rights reserved.
委譲では $this が変わる
1: class Foo {
2: function hello() { ... }
3: function main() {
4: ...; $this->hello(); ...; }
5: }
6: class Bar extends Foo {
7: function hello() { ... }
8: function main() {
9: $this->foo->main(); }
10: }
11: $obj = new Bar();
12: $obj->foo = new Foo();
13: $obj->main();
この $this は
Bar ではない!
せっかく Bar#hello() を
新しく定義したのに
呼び出されない!
(Decorator patternでありがち)
Foo オブジェクト
が $this になる!
難しい話なので、分から
なければ読み飛ばして!
47. copyright(c) 2013 kuwata-lab.com all rights reserved.
対策: $this を引数として渡す
class Foo {
function hello() { ... }
function main($_this=null) {
if ($_this === null) $_this = $this;
...; $_this->hello(); ...;
}
}
class Bar {
var $foo = new Foo();
function hello() { ... }
function main() {
$this->foo->main($this); } }
こんな面倒なことを
全メソッドで行うの?
この用意をしてないクラス
は委譲先にできないの?
難しい話なので、分から
なければ読み飛ばして!
48. copyright(c) 2013 kuwata-lab.com all rights reserved.
プロトタイプチェーンでは this が変わらない
1: function Foo() {}
2: Foo.prototype.hello = function() {...};
3: Foo.prototype.main = function() {
4: ...; this.hello(); ...;
5: };
6:
7: function Bar() {}
8: Bar.prototype.hello = function() {...};
9:
10: var obj = new Bar();
11: obj.__proto__ = new Foo();
12: obj.main();
この this は Bar オ
ブジェクトのまま!
委譲と同じことしてるのに、
Bar#hello() が呼ばれる!
(Decorator pattern大勝利の気配!)
51. copyright(c) 2013 kuwata-lab.com all rights reserved.
間違ったクラス設計例
class 受注先 {
var $name;
var $addr;
function 納期回答();
}
class 発注先 {
var $name;
var $addr;
function 納期問合わせ();
}
「受注先かつ発注先」なら両方に登録が必要◆
実体は同じなのに一元管理されないため、名寄せが必要
自称DB設計上級者に
ありがちな間違い
52. copyright(c) 2013 kuwata-lab.com all rights reserved.
間違ったクラス設計例
class 取引先 {
var $name;
var $addr;
}
class 受注先 extends 取引先 {
function 納期回答();
}
class 発注先 extends 取引先 {
function 納期問合わせ();
}
class 受発注先 extends 受注先,発注先 { }
「受注先が発注先にJob Change!」を表せない◆
一度作ったオブジェクトのクラスは変更できないせい
自称Java上級者に
ありがちな間違い
ダイヤモンド継承!
53. copyright(c) 2013 kuwata-lab.com all rights reserved.
好ましいクラス設計例
class 取引先 { // Player
var $name;
var $addr;
var $受注先 = new 受注先();
var $発注先 = new 発注先();
}
class 受注先 { // Role
function 納期回答(); }
class 発注先 { // Role
function 納期問合わせ(); }
「Player」と「Role」とを分け、委譲を使う◆
「受注先かつ発注先」も「Job Change!」も自然に表現可能
でも、受注先や発注
先って、対応する取
引先オブジェクトが
必要だよね?
54. copyright(c) 2013 kuwata-lab.com all rights reserved.
より好ましいクラス設計例
class 取引先 { ... }
class Role {
var $player;
function __constructor($player) {
$this->player = $player;
}
}
class 受注先 extends Role { ... }
class 発注先 extends Role { ... }
「Role」が「Player」を保持する(さっきと逆)◆
Role には Player が必要だが、Player には Role は必須ではない
Role が Player を保持
(なぜなら Role には Player が必要だから)
55. copyright(c) 2013 kuwata-lab.com all rights reserved.
若干の問題点
// 受注先である取引先
$player = new 取引先('○ 商会');
$role = new 受注先($player);
// 受注先として扱う
echo $role->納期回答();
// 取引先として扱う
echo $role->player->name;
echo $player->name;
Role と Player で使い方に差がある◆
Player の属性やメソッドに Role からアクセスするとき
Role からは、Player の属性へ
直接にはアクセスできない
56. copyright(c) 2013 kuwata-lab.com all rights reserved.
そこでプロトタイプベース!
class 取引先 { ... }
class Role {
function __constructor($player) {
$this->player = $player;
$this->__proto__ = $player;
}
}
class 受注先 extends Role { ... }
class 発注先 extends Role { ... }
Role をあたかも Player のように扱える◆
Decorator Pattern も DCI もいらんかったんや!
仮に PHP でこれが
可能だとすると…
57. copyright(c) 2013 kuwata-lab.com all rights reserved.
そこでプロトタイプベース!
// 受注先 (Role) の役割をもった取引先 (Player) は、
$player = new 取引先('○ 商会');
$role = new 受注先($player);
// Role としても Player としても扱える
echo $role->納期回答();
echo $role->name;
// 複数の Role を重ねることさえ可能
$role = new 発注先($role); // 受注先兼発注先
Role をあたかも Player のように扱える◆
Decorator Pattern も DCI もいらんかったんや!
Role なのに、まるで
Player のように扱える!