Changeset 1386
- Timestamp:
- 12/15/09 16:23:11 (2 years ago)
- Files:
-
- trunk/docsrc/const-faq.dd (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docsrc/const-faq.dd
r833 r1386 18 18 $(ITEMR java-const, Why did Java reject const?) 19 19 $(ITEMR cpp-const, How does const differ in C++?) 20 $(ITEMR invariant-strings, Why are strings i nvariant?)20 $(ITEMR invariant-strings, Why are strings immutable?) 21 21 $(ITEMR const-parameters, Why aren't function parameters const by default?) 22 22 $(ITEMR static-members, Are static class members covered by transitive const?) 23 $(ITEMR invariant, What is $(I i nvariant) good for?)23 $(ITEMR invariant, What is $(I immutable) good for?) 24 24 ) 25 25 26 26 $(ITEM const, Why does D have const?) 27 27 28 $(P People often express frustration with const and i nvariant28 $(P People often express frustration with const and immutable 29 29 in D 2.0 and wonder if it is worth it. 30 30 ) … … 202 202 $(OL 203 203 $(LI const is not transitive) 204 $(LI no i nvariants)204 $(LI no immutables) 205 205 $(LI const objects can have mutable members) 206 206 $(LI const can be legally cast away and the data modified) … … 208 208 ) 209 209 210 $(ITEM invariant-strings, Why are strings i nvariant?)211 212 $(P $(LINK2 http://dobbscodetalk.com/index.php?option=com_myblog&show=Invariant-Strings.html&Itemid=29, I nvariantStrings)210 $(ITEM invariant-strings, Why are strings immutable?) 211 212 $(P $(LINK2 http://dobbscodetalk.com/index.php?option=com_myblog&show=Invariant-Strings.html&Itemid=29, Immutable Strings) 213 213 ) 214 214 … … 254 254 ) 255 255 256 $(ITEM invariant, What is $(I i nvariant) good for?)257 258 $(P I nvariantdata, once initialized, is never changed.256 $(ITEM invariant, What is $(I immutable) good for?) 257 258 $(P Immutable data, once initialized, is never changed. 259 259 This has many uses: 260 260 ) 261 261 262 262 $(UL 263 $(LI Access to i nvariantdata need not be synchronized263 $(LI Access to immutable data need not be synchronized 264 264 when multiple threads read it.) 265 265 $(LI Data races, tearing, sequential consistency, and 266 266 cache consistency are all non-issues when working with 267 i nvariantdata.)268 $(LI Pure functions can only accept i nvariantparameters.)267 immutable data.) 268 $(LI Pure functions can only accept immutable parameters.) 269 269 $(LI When doing a $(I deep copy) of a data structure, 270 the i nvariantportions need not be copied.)270 the immutable portions need not be copied.) 271 271 $(LI Invariance allows a large chunk of data to be treated 272 272 as a value type even if it is passed around by reference 273 273 (strings are the most common case of this).) 274 $(LI I nvarianttype provides more self-documenting information274 $(LI Immutable type provides more self-documenting information 275 275 to the programmer.) 276 $(LI I nvariantdata can be placed in hardware protected read-only276 $(LI Immutable data can be placed in hardware protected read-only 277 277 memory, or even in ROMs.) 278 $(LI If i nvariantdata does change, it is a sure sign of a memory278 $(LI If immutable data does change, it is a sure sign of a memory 279 279 corruption bug, and it is possible to automatically check for 280 280 such data integrity.) 281 $(LI I nvarianttypes provide for many program optimization281 $(LI Immutable types provide for many program optimization 282 282 opportunities.) 283 283 ) 284 284 285 $(P $(I const) acts as a bridge between the mutable and i nvariant285 $(P $(I const) acts as a bridge between the mutable and immutable 286 286 worlds, so a single function can be used to accept both types 287 287 of arguments.)
