Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1386

Show
Ignore:
Timestamp:
12/15/09 21:23:11 (15 years ago)
Author:
walter
Message:

bugzilla 3580 Update docs s/invariant/immutable/

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docsrc/const-faq.dd

    r833 r1386  
    1010 
    1111    $(ITEMR const, Why does D have const?) 
    1212    $(ITEMR principles, What principles drove the D const design?) 
    1313    $(ITEMR transitive-const, What is $(I transitive const)?) 
    1414    $(ITEMR head-const, What is $(I head const)?) 
    1515    $(ITEMR tail-const, What is $(I tail const)?) 
    1616    $(ITEMR logical-const, What is $(I logical const)?) 
    1717    $(ITEMR readonly, Why not use $(I readonly) to mean read only view?) 
    1818    $(ITEMR java-const, Why did Java reject const?) 
    1919    $(ITEMR cpp-const, How does const differ in C++?) 
    20     $(ITEMR invariant-strings, Why are strings invariant?) 
     20    $(ITEMR invariant-strings, Why are strings immutable?) 
    2121    $(ITEMR const-parameters, Why aren't function parameters const by default?) 
    2222    $(ITEMR static-members, Are static class members covered by transitive const?) 
    23     $(ITEMR invariant, What is $(I invariant) good for?) 
     23    $(ITEMR invariant, What is $(I immutable) good for?) 
    2424    ) 
    2525 
    2626$(ITEM const, Why does D have const?) 
    2727 
    28     $(P People often express frustration with const and invariant 
     28    $(P People often express frustration with const and immutable 
    2929    in D 2.0 and wonder if it is worth it. 
    3030    ) 
    3131 
    3232    $(OL 
    3333 
    3434    $(LI It makes function interfaces more self-documenting. Without 
    3535    transitive const, for all pointer/reference parameters one must rely on 
    3636    the documentation (which is always missing, out of date, or wrong). Note 
    3737    that without transitivity, C++ const is nearly useless for such 
    3838    self-documentation, which is why C++ programmers tend to rely on 
     
    194194    $(P $(LINK http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4211070) 
    195195    ) 
    196196 
    197197$(ITEM cpp-const, How does const differ in C++?) 
    198198 
    199199    $(P C++ has a const system that is closer to D's than any other 
    200200    language, but it still has huge differences:) 
    201201 
    202202    $(OL 
    203203    $(LI const is not transitive) 
    204     $(LI no invariants) 
     204    $(LI no immutables) 
    205205    $(LI const objects can have mutable members) 
    206206    $(LI const can be legally cast away and the data modified) 
    207207    $(LI $(CODE const T) and $(CODE T) are not always distinct types) 
    208208    ) 
    209209 
    210 $(ITEM invariant-strings, Why are strings invariant?) 
    211  
    212     $(P $(LINK2 http://dobbscodetalk.com/index.php?option=com_myblog&show=Invariant-Strings.html&Itemid=29, Invariant Strings) 
     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) 
    213213    ) 
    214214 
    215215$(ITEM const-parameters, Why aren't function parameters const by default?) 
    216216 
    217217    $(P Since most (nearly all?) function parameters will not be modified, 
    218218    it would seem to make sense to make them all const by default, 
    219219    and one would have to specifically mark as mutable those that would 
    220220    be changed. The problems with this are: 
    221221    ) 
    222222 
     
    246246--- 
    247247 
    248248$(ITEM static-members, Are static class members covered by transitive const?) 
    249249 
    250250    $(P A static class member is part of the global state of a program, 
    251251    not part of the state of an object. Thus, a class having a mutable 
    252252    static member does not violate the transitive constness of an object 
    253253    of that class. 
    254254    ) 
    255255 
    256 $(ITEM invariant, What is $(I invariant) good for?) 
    257  
    258     $(P Invariant data, once initialized, is never changed. 
     256$(ITEM invariant, What is $(I immutable) good for?) 
     257 
     258    $(P Immutable data, once initialized, is never changed. 
    259259    This has many uses: 
    260260    ) 
    261261 
    262262    $(UL 
    263     $(LI Access to invariant data need not be synchronized 
     263    $(LI Access to immutable data need not be synchronized 
    264264    when multiple threads read it.) 
    265265    $(LI Data races, tearing, sequential consistency, and 
    266266    cache consistency are all non-issues when working with 
    267     invariant data.) 
    268     $(LI Pure functions can only accept invariant parameters.) 
     267    immutable data.) 
     268    $(LI Pure functions can only accept immutable parameters.) 
    269269    $(LI When doing a $(I deep copy) of a data structure, 
    270     the invariant portions need not be copied.) 
     270    the immutable portions need not be copied.) 
    271271    $(LI Invariance allows a large chunk of data to be treated 
    272272    as a value type even if it is passed around by reference 
    273273    (strings are the most common case of this).) 
    274     $(LI Invariant type provides more self-documenting information 
     274    $(LI Immutable type provides more self-documenting information 
    275275    to the programmer.) 
    276     $(LI Invariant data can be placed in hardware protected read-only 
     276    $(LI Immutable data can be placed in hardware protected read-only 
    277277    memory, or even in ROMs.) 
    278     $(LI If invariant data does change, it is a sure sign of a memory 
     278    $(LI If immutable data does change, it is a sure sign of a memory 
    279279    corruption bug, and it is possible to automatically check for 
    280280    such data integrity.) 
    281     $(LI Invariant types provide for many program optimization 
     281    $(LI Immutable types provide for many program optimization 
    282282    opportunities.) 
    283283    ) 
    284284 
    285     $(P $(I const) acts as a bridge between the mutable and invariant 
     285    $(P $(I const) acts as a bridge between the mutable and immutable 
    286286    worlds, so a single function can be used to accept both types 
    287287    of arguments.) 
    288288) 
    289289 
    290290Macros: 
    291291    TITLE=const(FAQ) 
    292292    WIKI=constFAQ 
    293293    ITEMR=$(LI $(LINK2 #$1, $+)) 
    294294    ITEM=<hr><h3><a name="$1">$+</a></h3>