4 ms·
Why NULL is Bad?
- kazinator 12y agoIt's a blub language issue: (defun get-by-name (name) (let ((id (database-find db name))) ;; return NIL or employee instance (if id (make-instance 'employee id)))) If necessary, we can make the generic functions that normally operate on employee to also work on nil, by specializing methods for the null class: (defmethod salary ((e null)) 0) ;; null employee makes nothing No problem to see here, move on: (salary (get-by-name "Nonex Istent")) -> 0 Note, by the way, how the test is "(if id ...)" and not "(if (zerop id) ...)". get-by-name itself returns nil when the name is not found, rather than an integer, which means zero could be a valid ID. The conventions shortens code since the result can be treated as a boolean value indicating found or not found, and the true value is an ID also.