abergel wrote
Hi!
I perfectly understand the purpose of this method "??â Although I do not think this will seriously impact the quality of the code being produced, ...
Actually, I would argue it that it would degrade the quality of code. There is less clarity conveyed by infix operators than by keyword messages, unless the infix operator is already well known (such as common arithmetic operators) or somewhat easily guessed (such as #~=). #?? only has meaning if you already know it from other languages.
... I still believe it will not help making code of a better quality. Check for the nil value should be banned in my opinion. There are well-known techniques to not have to use it (e.g., Null-object pattern).
Cheers, Alexandre
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
On May 20, 2015, at 3:19 PM, Aliaksei Syrel <
alex.syrel@
> wrote:
Hi,
Null coalesce operator - returns the first not nil operand. http://en.wikipedia.org/wiki/Null_coalescing_operator <http://en.wikipedia.org/wiki/Null_coalescing_operator>
Adding one simple method to an Object:
?? anObject ^ self
and to UndefinedObject:
?? anObject ^ anObject
could allow us to write:
default1 := nil. default2 := nil. default3 := 'foo'. default4 := 'don''t care'. config := default1 ?? default2 ?? default3 ?? default4.
=> 'foo'
I know you don't like to add new methods to an object, but still :)
-- View this message in context: http://forum.world.st/Null-Coalesce-Operator-tp4827707p4827911.html Sent from the Pharo Smalltalk Developers mailing list archive at Nabble.com.