On 11/22/2011 7:42 PM, Benjamin Peterson wrote:
2011/11/22 Antoine Pitrou<solip...@pitrou.net>:
On Tue, 22 Nov 2011 16:42:35 -0500
Benjamin Peterson<benja...@python.org>  wrote:
2011/11/22 Antoine Pitrou<solip...@pitrou.net>:
On Tue, 22 Nov 2011 21:29:43 +0100
benjamin.peterson<python-check...@python.org>  wrote:
http://hg.python.org/cpython/rev/77ab830930ae
changeset:   73697:77ab830930ae
user:        Benjamin Peterson<benja...@python.org>
date:        Tue Nov 22 15:29:32 2011 -0500
summary:
   fix compiler warning by implementing this more cleverly

You mean "more obscurely"?
Obfuscating the original intent in order to disable a compiler warning
doesn't seem very wise to me.

Well, I think it makes sense that the kind tells you how many bytes are in it.

Yes, but "kind * 2 + 2" looks like a magical formula, while the
explicit switch let you check mentally that each estimate was indeed
correct.

I don't see how it's more magic than hardcoding 4, 6, and 10. Don't
you have to mentally check that those are correct?

I personally strongly prefer the one-line formula to the hardcoded magic numbers calculated from the formula. I find it much more readable. To me, the only justification for the switch would be if there is a serious worry about the kind being changed to something other than 1, 2, or 4. But the fact that this is checked with an assert that can be optimized away negates that. The one-liner could be followed by
  assert(kind==1 || kind==2 || kind==4)
which would also serve to remind the reader of the possibilities. You could even follow the formula with /* 4, 6, or 10 */ I think you reverted too soon.

--
Terry Jan Reedy

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to