Add a FAQ item about dynamic strings
authorJordan DeLong <jdelong@fb.com>
Mon, 24 Sep 2012 20:58:28 +0000 (13:58 -0700)
committerJordan DeLong <jdelong@fb.com>
Fri, 12 Oct 2012 04:33:41 +0000 (21:33 -0700)
Summary:
After a conversation with njormrod I remembered why we didn't
do this.  Let's document it.

Test Plan: It's docs.

Reviewed By: njormrod@fb.com

FB internal diff: D582651

folly/docs/Dynamic.md

index c9a5c3652ba4fb6dd77855c163d2bd16715e7449..924bb7140bd3708b83398854b51b204f26ca885a 100644 (file)
@@ -186,6 +186,17 @@ also be surprising if `dynamic d` left `d.isArray()` as true. The
 solution was just to disallow uninitialized dynamics: every
 dynamic must start out being assigned to some value (or nullptr).
 
+**Q. Why doesn't a dynamic string support begin(), end(), and operator[]?**
+
+The value_type of a dynamic iterator is `dynamic`, and `operator[]`
+(or the `at()` function) has to return a reference to a dynamic.  If
+we wanted this to work for strings, this would mean we'd have to
+support dynamics with a character type, and moreover that the internal
+representation of strings would be such that we can hand out
+references to dynamic as accessors on individual characters.  There
+are a lot of potential efficiency drawbacks with this, and it seems
+like a feature that is not needed too often in practice.
+
 **Q. Isn't this just a poor imitation of the C# language feature?**
 
 Pretty much.