On 11/24/2015 03:15 PM, Josef Reidinger wrote:
On Tue, 24 Nov 2015 14:45:45 +0100 Stefan Hundhammer
wrote: [...]
Well, in OOP is also one more approach called NullObject pattern, which is create kind if partition table, that in represent no partition table. Let me below show how it will behave. ( and yes, I know it is a bit controversial pattern - https://en.wikipedia.org/wiki/Null_Object_pattern
Indeed, while reading HuHa's mail, the NullObject pattern was the first thing that came to my mind as well (it looks like a tailored example to explain the pattern). Fortunately, Josef already explained it much better that I would have done.
[...]
[...]
OTOH if there would be more checks that might fail (such as the 'if disk && disk.partition_table && disk.partition_table.gpt?' check above), that one 'begin..rescue' block would handle them all, and the control flow remains clear and straightforward.
And that's the beauty of it.
Well, I am not sure as you should use more specialized exception catcher, otherwise you can catch also other problem, that should go more top level, so in the end, you might want to rescue from three kinds of exception like
rescue NoPartitionTable, NoDisk, NotGpt => e
which is not so beauty.
Well, to be fair, you could use Inheritance like class LibStorage::NotFound < Exception; end class LibStorage::NoPartitionTable < LibStorage::NotFound; end class LibStorage::NoDisk < LibStorage::NotFound; end and so on, so you only need to catch rescue LibStorage::NotFound => e Still, I prefer the NullObject pattern instead of abusing the exceptions system (which, as a side note, used to be quite slow in the first versions of Ruby 2, not sure now).
[...]
Still I think for common situation that can easily happen like disk without partitions we should consider NullPattern approach, which *for me* is in this situation better approach.
+1 Cheers. -- Ancor González Sosa YaST Team at SUSE Linux GmbH -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org