Subject: Re: [boost] [lexical_cast] A suggestion
From: Vladimir Batov (batov_at_[hidden])
Date: 2009-02-06 23:02:28
>> int i = lexical_cast<optional<int> >(mystring).get_value_or(-1);
>> Why is this so bad?
> Well, if you want lexical_cast (and Boost) *not* used in the wide, then keep
> mounting these wonderful complexities and interfaces. Surely the users will
> be very supportive of your effort.
Well, that was somewhat terse and unfriendly. Apologies. I'll elaborate and give you metrics.
1. int i = lexical_cast<optional<int> >(mystring).get_value_or(-1);
2. int i = lexical_cast(mystring, -1);
#1 and #2 do exactly the same (although #2 does it better as it does not demand default-constructability). However, #1 has 3 new special-vocabulary elements (lexical_cast, optional, get_value_or) vs. just one entry for #2. I.e the entry level for a user to deploy #1 is at least 3 times higher than #2. You might say -- "no, big deal, I already know all that". You most likely do. Others might not. Application programmers often can qualify only as casual Boost users. And often it's not entirely their fault as they have a lot to know/care about beyond Boost (like their domain-specific stuff). Unfortunately, learning something new for those app. programmers is often secondary (unfortunate but fact) as they are too busy coding their domain-specific stuff. Therefore, learning something new can only be learnt if it passes some mental complexity level and if it fits some mentally allocated time. If learning/diversion spills over complexity/time limits, that new thing is dropped and something is hand-coded the ugly way. I personally want (for selfish reasons) to see those guys engaged and using Boost rather than repelled by interface/deployment complexity.
Another thing is that #1 is twice as long (and IMHO ugly :-) ). In isolation it might be OK (the length it is). On a bigger scale you are suggesting I write twice as much code as I have to. With #1 I'll have to spend one hour writing code when with #2 I could spend only half an hour writing code and the remaining half an hour enjoying myself ;-). Then, I'll have twice as much code to proof-read, to debug, to maintain, to test. As it is pretty much what I do all day long, you just robbed me of half my working day (or made me work twice as hard). All that for what? Some abstract idea/ideal of keeping lexical_cast looking similar to static_cast?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk