commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sébastien Brisard <sebastien.bris...@m4x.org>
Subject Re: svn commit: r1343163 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/linear/ test/java/org/apache/commons/math3/linear/
Date Mon, 28 May 2012 15:36:05 GMT
Hello again,

2012/5/28 sebb <sebbaz@gmail.com>:
> On 28 May 2012 13:28, Sébastien Brisard <sebastien.brisard@m4x.org> wrote:
>> Hi Gilles,
>>
>> 2012/5/28 Gilles Sadowski <gilles@harfang.homelinux.org>:
>>> Hello.
>>>
>>>>
>>>> >
>>>> > Why do you call "valueOf"?
>>>> >
>>>> I have to say I do not like implicit conversions, that's why I tend to
>>>> always use Integer.valueOf and the likes.
>>>
>>> Why?
>>>
>> This is going to get "philosophical": I would not dare to claim that
>> I'm holding *the* truth, this is only my way of seeing things. I do
>> not like things to happen implicitely, because I think that it opens a
>> door to errors (this would not be true of professional programmers,
>> but remember that I work in an environment where people are not real
>> computer scientists... so my philosophy is "close as many doors as you
>> can"...). I even think that J. Bloch has a nice example of potential
>> issues with auto-boxing. However, I agree with you: calling valueOf in
>> this context (that is: building a new exception) is certainly
>> far-fetched.
>>
>> That was the initial reason why I moved from C++ to Java ten years
>> ago: too many things happened "behind my back". Again, I'm not saying
>> that C++ is evil. I'm just saying that I did not have the background
>> with C++ to be fully aware of these implicit assumptions, and their
>> potential consequences.
>>
>> I'm pretty sure I will not convince you on this. I hope I have at
>> least convinced you that I have a good reason to do it this way :-)
>>
>
> I agree with you - making boxing explicit is better.
>
> The reasoning is that implicit boxing/unboxing can hide ineffiicient
> conversions as well as subtle bugs.
> I've seen code which treats the same item variously as a Integer and
> an int for no good reason.
> The compiler warnings allow the careful programmer to investigate and
> choose one or the other.
>
> Yes, the code is a bit longer, but it clearly shows that the
> boxing/unboxing was intended, and not an accident of compiler
> "helpfulness".
>
>>>> However, if you think that
>>>> it leads to less readable code, I'm OK with your way of seeing things.
>>>
>>> Good! ;-)
>>>
>>> Gilles
>>>
>> As I said, I will remove these explicit boxings (but be warned: I've
>> used valueOf() in the past, and do apologize for any unwanted
>> occurence...).
>>
>> Best regards,
>> Sébastien
>>
Wowww!
Who would have thought that this would raise so many answers!
While I also think explicit conversion is better, I think we can all
agree that Gilles has a point for this specific case

            throw new OutOfRangeException(LocalizedFormats.INDEX,
                                          Integer.valueOf(start),
                                          Integer.valueOf(0),
                                          Integer.valueOf(dim - 1));

is a bit far-fetched, since the code ends right there. I think we can
safely follow Gilles' advice, here.
Best regards,
Sébastien


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message