Qcon北京2018-《以Null的处理、回调地狱的应对为例,看C#背后的问题解决思路》-Mads+TorgersenNulls and other C# stories from the future Chapter One Herding nulls Every reference type allows null! Code must be defensive about it C# shares this with most object oriented languages Not all languages public string? MiddleName { get; set; } public string LastName { get; set; } } J 1. Protect non-null types from nulls 2. Protect nulls from dereference Must be optional Turn it on when you’re ready job with existing code Can’t force you to rewrite good code Recognize existing ways of ensuring null safety (checks and assignments) Can’t be exhaustive Tradeoff between completeness and convenience0 码力 | 32 页 | 2.66 MB | 1 年前3
CakePHP Cookbook 2.x
AUTO_INCREMENT PRIMARY KEY, title VARCHAR(50), body TEXT, created DATETIME DEFAULT NULL, modified DATETIME DEFAULT NULL ); /* Then insert some posts for testing: */ INSERT INTO posts (title, body, created) index() { $this->set('posts', $this->Post->find('all')); } public function view($id = null) { if (!$id) { throw new NotFoundException(__('Invalid post')); } Here’s what the edit() action of the PostsController would look like: public function edit($id = null) { if (!$id) { throw new NotFoundException(__('Invalid post')); } $post = $this0 码力 | 1096 页 | 958.62 KB | 1 年前3
CakePHP Cookbook 2.x
AUTO_INCREMENT PRIMARY KEY, title VARCHAR(50), body TEXT, created DATETIME DEFAULT NULL, modified DATETIME DEFAULT NULL ); /* Then insert some posts for testing: */ INSERT INTO posts (title, body, created) public function index() { $this->set('posts', $this->Post->find('all')); } public function view($id = null) { if (!$id) { throw new NotFoundException(__('Invalid post')); (continues on next page) 12 Chapter Here’s what the edit() action of the PostsController would look like: public function edit($id = null) { if (!$id) { throw new NotFoundException(__('Invalid post')); } $post = $this->Post->findById($id);0 码力 | 820 页 | 2.52 MB | 1 年前3
Kotlin 1.2 Language DocumentationMap Ranges Type Checks and Casts: 'is' and 'as' This Expression Equality Operator overloading Null Safety Exceptions Annotations Reflection Type-Safe Builders Reference Keywords and Operators value. It checks whether the receiver meets the predicate, and returns the receiver, if it does or null if it doesn't. Combined with an elvis-operator and early returns it allows to write constructs like: but it takes the inverted predicate. It returns the receiver when it doesn't meet the predicate and null otherwise. So one of the examples above could be rewritten with takeUnless as following: val index0 码力 | 333 页 | 2.22 MB | 1 年前3
CakePHP Cookbook 4.x
VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, created DATETIME, modified DATETIME ); CREATE TABLE articles ( id INT AUTO_INCREMENT PRIMARY KEY, user_id INT NOT NULL, title VARCHAR(255) VARCHAR(255) NOT NULL, slug VARCHAR(191) NOT NULL, body TEXT, published BOOLEAN DEFAULT FALSE, created DATETIME, modified DATETIME, UNIQUE KEY (slug), FOREIGN KEY user_key (user_id) UNIQUE KEY (title) ) CHARSET=utf8mb4; CREATE TABLE articles_tags ( article_id INT NOT NULL, tag_id INT NOT NULL, PRIMARY KEY (article_id, tag_id), FOREIGN KEY tag_key(tag_id) REFERENCES tags(id)0 码力 | 1249 页 | 1.04 MB | 1 年前3
CakePHP Cookbook 4.x
VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, created DATETIME, modified DATETIME ); CREATE TABLE articles ( id INT AUTO_INCREMENT PRIMARY KEY, user_id INT NOT NULL, title VARCHAR(255) NOT NULL, slug VARCHAR(191) VARCHAR(191) NOT NULL, body TEXT, published BOOLEAN DEFAULT FALSE, created DATETIME, modified DATETIME, UNIQUE KEY (slug), FOREIGN KEY user_key (user_id) REFERENCES users(id) ) CHARSET=utf8mb4; CREATE UNIQUE KEY (title) ) CHARSET=utf8mb4; CREATE TABLE articles_tags ( article_id INT NOT NULL, tag_id INT NOT NULL, PRIMARY KEY (article_id, tag_id), FOREIGN KEY tag_key(tag_id) REFERENCES tags(id), FOREIGN0 码力 | 967 页 | 2.88 MB | 1 年前3
Kotlin Language Documentation 1.3Declarations Type Checks and Casts: 'is' and 'as' This Expression Equality Operator overloading Null Safety Exceptions Annotations Reflection Scope Functions Type-Safe Builders Experimental API value. It checks whether the receiver meets the predicate, and returns the receiver, if it does or null if it doesn't. Combined with an elvis-operator and early returns it allows to write constructs like: but it takes the inverted predicate. It returns the receiver when it doesn't meet the predicate and null otherwise. So one of the examples above could be rewritten with takeUnless as following: val index0 码力 | 597 页 | 3.61 MB | 1 年前3
The Zig Programming Language 0.12.0 Documentationfalse, !true, }); // optional var optional_value: ?[]const u8 = null; assert(optional_value == null); print("\noptional 1\ntype: {}\nvalue: {?s}\n", .{ @TypeOf(optional_value) @TypeOf(optional_value), optional_value, }); optional_value = "hi"; assert(optional_value != null); print("\noptional 2\ntype: {}\nvalue: {?s}\n", .{ @TypeOf(optional_value), optional_value $ ./values 1 + 1 = 2 7.0 / 3.0 = 2.3333333e0 false true false optional 1 type: ?[]const u8 value: null optional 2 type: ?[]const u8 value: hi error union 1 type: anyerror!i32 value: error.ArgNotFound0 码力 | 241 页 | 7.37 MB | 1 年前3
The Zig Programming Language 0.7.1 Documentationfalse, !true, }); // optional var optional_value: ?[]const u8 = null; assert(optional_value == null); print("\noptional 1\ntype: {}\nvalue: {}\n", .{ @typeName(@TypeOf(optional_value)) value)), optional_value, }); optional_value = "hi"; assert(optional_value != null); print("\noptional 2\ntype: {}\nvalue: {}\n", .{ @typeName(@TypeOf(optional_value)) /values 1 + 1 = 2 7.0 / 3.0 = 2.33333325e+00 false true false optional 1 type: ?[]const u8 value: null optional 2 type: ?[]const u8 value: hi error union 1 type: anyerror!i32 value: error.ArgNotFound0 码力 | 225 页 | 5.74 MB | 1 年前3
Kotlin Language Documentation 1.9.20instance Access properties Member functions Data classes Practice Next step Null safety Nullable types Check for null values Use safe calls Use Elvis operator Practice What's next? Kotlin Multiplatform Conditional expressions for loop while loop when expression Ranges Collections Nullable values and null checks Type checks and automatic casts Idioms Create DTOs (POJOs/POCOs) Default values for function functions Create a singleton Instantiate an abstract class If-not-null shorthand If-not-null-else shorthand Execute a statement if null 336 336 337 337 337 338 338 339 339 340 341 341 3420 码力 | 1299 页 | 32.44 MB | 1 年前3
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 100













