fest-assert-2.x icon indicating copy to clipboard operation
fest-assert-2.x copied to clipboard

Revert methods that return Iterable to return List (as it was originally intended)

Open alexruiz opened this issue 12 years ago • 3 comments

Returning Iterable is, IMHO, a bad idea. You cannot ask an Iterable about its size, and you cannot access elements by index.

The methods that I plan to revert are in the Properties class.

alexruiz avatar Sep 05 '12 20:09 alexruiz

It was meant to solve #70, if you revert this how do we address that issue ? (BTW, I already use this feature in my project).

Moreover if we extract properties from a Set, returning a List does not make much sense as the input collection does not support element access by index.

Using generics further, what we may do instead is to return the same type of Iterable than the input Iterable, if given a Set, return a Set, if given a List or an array, return a List.

joel-costigliola avatar Sep 05 '12 22:09 joel-costigliola

I meant to change only the return type. If the calling code expects an Iterable, getting a List should work.

I need to review the extended use of generics. I have the gut feeling that type safety in tests does not bring too many benefits. I need to look into this in more detail to have an opinion. Of course, I'll document it with a bug report.

alexruiz avatar Sep 06 '12 00:09 alexruiz

You are right, returning a List should not break #70, I have spoken too quickly.

After some thoughts, it might not be a good idea to return the same type of iterable. Let's imagine we want to extract the names of a Set of Person, some may think that the returned iterable should have the same size as the input iterable, and this cannot be guaranteed by returning a Set. So having a List is nice for element index access and size.

joel-costigliola avatar Sep 06 '12 07:09 joel-costigliola